Skip to content

Commit

Permalink
Always use getKeepVoidType
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal committed May 14, 2024
1 parent d3a6576 commit c3b1cbe
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 11 deletions.
5 changes: 0 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ parameters:
message: "#but it's missing from the PHPDoc @throws tag\\.$#" # allow uncatched exceptions in tests
path: tests/*

-
message: '#^Call to function method_exists\(\) with PHPStan\\Analyser\\Scope and ''getKeepVoidType'' will always evaluate to true\.$#'
path: src/Rule/ForbidUnusedMatchResultRule.php
reportUnmatched: false # fails only for PHPStan > 1.10.49

# ignore BC promises
- identifier: phpstanApi.class
- identifier: phpstanApi.method
Expand Down
7 changes: 1 addition & 6 deletions src/Rule/ForbidUnusedMatchResultRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
use PHPStan\Rules\Rule;
use PHPStan\Rules\RuleErrorBuilder;
use PHPStan\Type\NeverType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeCombinator;
use PHPStan\Type\VerbosityLevel;
use ShipMonk\PHPStan\Visitor\UnusedMatchVisitor;
use function method_exists;

/**
* @implements Rule<Match_>
Expand All @@ -36,10 +34,7 @@ public function processNode(Node $node, Scope $scope): array
$returnedTypes = [];

foreach ($node->arms as $arm) {
/** @var Type $armType */
$armType = method_exists($scope, 'getKeepVoidType') // Needed since https://github.com/phpstan/phpstan/releases/tag/1.10.49, can be dropped once we bump PHPStan version gte that
? $scope->getKeepVoidType($arm->body)
: $scope->getType($arm->body);
$armType = $scope->getKeepVoidType($arm->body);

if (!$armType->isVoid()->yes() && !$armType instanceof NeverType && !$arm->body instanceof Assign) {
$returnedTypes[] = $armType;
Expand Down

0 comments on commit c3b1cbe

Please sign in to comment.