Skip to content

Commit 8b653cd

Browse files
committed
Fix PHPStan issue
1 parent 4f24659 commit 8b653cd

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

rules/Transform/Rector/FuncCall/WrapFuncCallWithPhpVersionIdCheckerRector.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ private function isWrappedFuncCall(StmtsAwareInterface $node): bool
127127
return false;
128128
}
129129

130-
$phpVersionIdComparison = $this->getPhpVersionIdComparison($node->cond);
130+
$phpVersionId = $this->getPhpVersionId($node->cond);
131+
if ($phpVersionId === null) {
132+
return false;
133+
}
131134

132135
if (count($node->stmts) !== 1) {
133136
return false;
@@ -142,7 +145,7 @@ private function isWrappedFuncCall(StmtsAwareInterface $node): bool
142145
foreach ($this->wrapFuncCallWithPhpVersionIdCheckers as $wrapFuncCallWithPhpVersionIdChecker) {
143146
if (
144147
$this->getName($childStmt->expr) !== $wrapFuncCallWithPhpVersionIdChecker->getFunctionName()
145-
|| $phpVersionIdComparison->right->value !== $wrapFuncCallWithPhpVersionIdChecker->getPhpVersionId()
148+
|| $phpVersionId->value !== $wrapFuncCallWithPhpVersionIdChecker->getPhpVersionId()
146149
) {
147150
continue;
148151
}
@@ -153,10 +156,10 @@ private function isWrappedFuncCall(StmtsAwareInterface $node): bool
153156
return false;
154157
}
155158

156-
private function getPhpVersionIdComparison(Expr $expr): ?Smaller
159+
private function getPhpVersionId(Expr $expr): ?Int_
157160
{
158161
if ($expr instanceof BooleanAnd) {
159-
return $this->getPhpVersionIdComparison($expr->left) ?? $this->getPhpVersionIdComparison($expr->right);
162+
return $this->getPhpVersionId($expr->left) ?? $this->getPhpVersionId($expr->right);
160163
}
161164

162165
if (! $expr instanceof Smaller) {
@@ -171,6 +174,6 @@ private function getPhpVersionIdComparison(Expr $expr): ?Smaller
171174
return null;
172175
}
173176

174-
return $expr;
177+
return $expr->right;
175178
}
176179
}

0 commit comments

Comments
 (0)