Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always use getKeepVoidType #242

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading