Skip to content

Commit 3c4bcf2

Browse files
committed
fixup! Add MemoizationPropertyRule
1 parent 2154e33 commit 3c4bcf2

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

build/PHPStan/Build/MemoizationPropertyRule.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use PhpParser\Node\Expr\BinaryOp\Identical;
99
use PhpParser\Node\Expr\ConstFetch;
1010
use PhpParser\Node\Expr\PropertyFetch;
11+
use PhpParser\Node\Expr\Variable;
1112
use PhpParser\Node\Identifier;
1213
use PhpParser\Node\Stmt\Expression;
1314
use PhpParser\Node\Stmt\If_;
@@ -19,7 +20,6 @@
1920
use PHPStan\Rules\RuleErrorBuilder;
2021
use function count;
2122
use function dirname;
22-
use function get_class;
2323
use function sprintf;
2424
use function str_starts_with;
2525
use function strcasecmp;
@@ -52,9 +52,10 @@ public function processNode(Node $node, Scope $scope): array
5252
}
5353

5454
[$ifNode, $returnNode] = $stmts;
55-
56-
if (!$returnNode instanceof Return_ ||
57-
!$returnNode->expr instanceof PropertyFetch
55+
if (!$returnNode instanceof Return_
56+
|| !$returnNode->expr instanceof PropertyFetch
57+
|| !$returnNode->expr->var instanceof Variable
58+
|| !$returnNode->expr->name instanceof Identifier
5859
) {
5960
return [];
6061
}
@@ -66,22 +67,20 @@ public function processNode(Node $node, Scope $scope): array
6667
|| $ifNode->else !== null
6768
|| !$ifNode->cond instanceof Identical
6869
|| !$ifNode->cond->left instanceof PropertyFetch
70+
|| !$ifNode->cond->left->var instanceof Variable
71+
|| !$ifNode->cond->left->name instanceof Identifier
6972
|| !$ifNode->cond->right instanceof ConstFetch
7073
|| strcasecmp($ifNode->cond->right->name->name, 'null') !== 0
7174
) {
7275
return [];
7376
}
7477

7578
$ifThenNode = $ifNode->stmts[0]->expr;
76-
7779
if (!$ifThenNode instanceof Assign || !$ifThenNode->var instanceof PropertyFetch) {
7880
return [];
7981
}
8082

81-
if (get_class($returnNode->expr) !== get_class($ifNode->cond->left)
82-
|| get_class($returnNode->expr->var) !== get_class($ifNode->cond->left->var)
83-
|| !$returnNode->expr->name instanceof Identifier
84-
|| !$ifNode->cond->left->name instanceof Identifier
83+
if ($returnNode->expr->var->name !== $ifNode->cond->left->var->name
8584
|| $returnNode->expr->name->name !== $ifNode->cond->left->name->name
8685
) {
8786
return [];

0 commit comments

Comments
 (0)