8
8
use PhpParser \Node \Expr \BinaryOp \Identical ;
9
9
use PhpParser \Node \Expr \ConstFetch ;
10
10
use PhpParser \Node \Expr \PropertyFetch ;
11
+ use PhpParser \Node \Expr \Variable ;
11
12
use PhpParser \Node \Identifier ;
12
13
use PhpParser \Node \Stmt \Expression ;
13
14
use PhpParser \Node \Stmt \If_ ;
19
20
use PHPStan \Rules \RuleErrorBuilder ;
20
21
use function count ;
21
22
use function dirname ;
22
- use function get_class ;
23
23
use function sprintf ;
24
24
use function str_starts_with ;
25
25
use function strcasecmp ;
@@ -53,8 +53,9 @@ public function processNode(Node $node, Scope $scope): array
53
53
54
54
[$ ifNode , $ returnNode ] = $ stmts ;
55
55
56
- if (!$ returnNode instanceof Return_ ||
57
- !$ returnNode ->expr instanceof PropertyFetch
56
+ if (!$ returnNode instanceof Return_
57
+ || !$ returnNode ->expr instanceof PropertyFetch
58
+ || !$ returnNode ->expr ->var instanceof Variable
58
59
) {
59
60
return [];
60
61
}
@@ -66,6 +67,7 @@ public function processNode(Node $node, Scope $scope): array
66
67
|| $ ifNode ->else !== null
67
68
|| !$ ifNode ->cond instanceof Identical
68
69
|| !$ ifNode ->cond ->left instanceof PropertyFetch
70
+ || !$ ifNode ->cond ->left ->var instanceof Variable
69
71
|| !$ ifNode ->cond ->right instanceof ConstFetch
70
72
|| strcasecmp ($ ifNode ->cond ->right ->name ->name , 'null ' ) !== 0
71
73
) {
@@ -78,8 +80,7 @@ public function processNode(Node $node, Scope $scope): array
78
80
return [];
79
81
}
80
82
81
- if (get_class ($ returnNode ->expr ) !== get_class ($ ifNode ->cond ->left )
82
- || get_class ($ returnNode ->expr ->var ) !== get_class ($ ifNode ->cond ->left ->var )
83
+ if ($ returnNode ->expr ->var ->name !== $ ifNode ->cond ->left ->var ->name
83
84
|| !$ returnNode ->expr ->name instanceof Identifier
84
85
|| !$ ifNode ->cond ->left ->name instanceof Identifier
85
86
|| $ returnNode ->expr ->name ->name !== $ ifNode ->cond ->left ->name ->name
0 commit comments