Skip to content

Commit

Permalink
Remove unnecessary instanceof ConstantBooleanType in loop analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
herndlm authored and ondrejmirtes committed Oct 23, 2024
1 parent c875e83 commit 11e0ab6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ parameters:

-
message: "#^Doing instanceof PHPStan\\\\Type\\\\Constant\\\\ConstantBooleanType is error\\-prone and deprecated\\. Use Type\\:\\:isTrue\\(\\) or Type\\:\\:isFalse\\(\\) instead\\.$#"
count: 3
count: 2
path: src/Analyser/NodeScopeResolver.php

-
Expand Down
7 changes: 1 addition & 6 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1320,12 +1320,7 @@ private function processStmtNode(
$initScope = $condResult->getScope();
$condResultScope = $condResult->getScope();
$condTruthiness = ($this->treatPhpDocTypesAsCertain ? $condResultScope->getType($condExpr) : $condResultScope->getNativeType($condExpr))->toBoolean();
if ($condTruthiness instanceof ConstantBooleanType) {
$condTruthinessTrinary = TrinaryLogic::createFromBoolean($condTruthiness->getValue());
} else {
$condTruthinessTrinary = TrinaryLogic::createMaybe();
}
$isIterableAtLeastOnce = $isIterableAtLeastOnce->and($condTruthinessTrinary);
$isIterableAtLeastOnce = $isIterableAtLeastOnce->and($condTruthiness->isTrue());
$hasYield = $hasYield || $condResult->hasYield();
$throwPoints = array_merge($throwPoints, $condResult->getThrowPoints());
$impurePoints = array_merge($impurePoints, $condResult->getImpurePoints());
Expand Down

0 comments on commit 11e0ab6

Please sign in to comment.