44
55namespace Rector \Utils \PHPStan \Rule ;
66
7+ use PhpParser \Node \Name ;
8+ use PhpParser \Node \Identifier ;
9+ use PhpParser \Node \Expr \ConstFetch ;
710use PhpParser \Node ;
811use PhpParser \Node \Expr ;
912use PhpParser \Node \Expr \Assign ;
@@ -102,15 +105,15 @@ private function matchScopeFetchVariableName(Stmt $stmt): ?string
102105 }
103106
104107 $ staticCall = $ assign ->expr ;
105- if (! $ staticCall ->class instanceof Node \ Name) {
108+ if (! $ staticCall ->class instanceof Name) {
106109 return null ;
107110 }
108111
109112 if ($ staticCall ->class ->toString () !== ScopeFetcher::class) {
110113 return null ;
111114 }
112115
113- if (! $ staticCall ->name instanceof Node \ Identifier || $ staticCall ->name ->toString () !== 'fetch ' ) {
116+ if (! $ staticCall ->name instanceof Identifier || $ staticCall ->name ->toString () !== 'fetch ' ) {
114117 return null ;
115118 }
116119
@@ -128,17 +131,17 @@ private function isReturnNullGuard(If_ $if): bool
128131 return false ;
129132 }
130133
131- return $ onlyStmt ->expr === null || $ this ->isNullConstant ($ onlyStmt ->expr );
134+ return ! $ onlyStmt ->expr instanceof Expr || $ this ->isNullConstant ($ onlyStmt ->expr );
132135 }
133136
134137 private function isNullConstant (Expr $ expr ): bool
135138 {
136- return $ expr instanceof Node \ Expr \ ConstFetch && $ expr ->name ->toLowerString () === 'null ' ;
139+ return $ expr instanceof ConstFetch && $ expr ->name ->toLowerString () === 'null ' ;
137140 }
138141
139142 private function usesVariable (Expr $ expr , string $ variableName ): bool
140143 {
141- $ foundVariable = ( new NodeFinder () )->findFirst (
144+ $ foundVariable = new NodeFinder ()->findFirst (
142145 [$ expr ],
143146 static fn (Node $ subNode ): bool => $ subNode instanceof Variable && $ subNode ->name === $ variableName
144147 );
0 commit comments