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 ;
@@ -52,9 +52,10 @@ public function processNode(Node $node, Scope $scope): array
52
52
}
53
53
54
54
[$ 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
58
59
) {
59
60
return [];
60
61
}
@@ -66,22 +67,20 @@ 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
71
+ || !$ ifNode ->cond ->left ->name instanceof Identifier
69
72
|| !$ ifNode ->cond ->right instanceof ConstFetch
70
73
|| strcasecmp ($ ifNode ->cond ->right ->name ->name , 'null ' ) !== 0
71
74
) {
72
75
return [];
73
76
}
74
77
75
78
$ ifThenNode = $ ifNode ->stmts [0 ]->expr ;
76
-
77
79
if (!$ ifThenNode instanceof Assign || !$ ifThenNode ->var instanceof PropertyFetch) {
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
- || !$ returnNode ->expr ->name instanceof Identifier
84
- || !$ ifNode ->cond ->left ->name instanceof Identifier
83
+ if ($ returnNode ->expr ->var ->name !== $ ifNode ->cond ->left ->var ->name
85
84
|| $ returnNode ->expr ->name ->name !== $ ifNode ->cond ->left ->name ->name
86
85
) {
87
86
return [];
0 commit comments