|
16 | 16 | use PhpParser\Node\Expr\Closure; |
17 | 17 | use PhpParser\Node\Expr\Empty_; |
18 | 18 | use PhpParser\Node\Expr\FuncCall; |
| 19 | +use PhpParser\Node\Expr\Instanceof_; |
19 | 20 | use PhpParser\Node\Expr\MethodCall; |
| 21 | +use PhpParser\Node\Expr\PropertyFetch; |
| 22 | +use PhpParser\Node\Expr\StaticPropertyFetch; |
20 | 23 | use PhpParser\Node\Expr\Variable; |
21 | 24 | use PhpParser\Node\FunctionLike; |
22 | 25 | use PhpParser\Node\Identifier; |
@@ -244,6 +247,14 @@ private function shouldStop(Node $node, string $paramName): bool |
244 | 247 | return true; |
245 | 248 | } |
246 | 249 |
|
| 250 | + if ($this->isPropertyFetchedOnArrayDimFetch($node, $paramName)) { |
| 251 | + return true; |
| 252 | + } |
| 253 | + |
| 254 | + if ($this->isInstanceofParam($node, $paramName)) { |
| 255 | + return true; |
| 256 | + } |
| 257 | + |
247 | 258 | return $this->isReassignAndUseAsArg($node, $paramName); |
248 | 259 | } |
249 | 260 |
|
@@ -288,6 +299,28 @@ private function isEmptyOrEchoedOrCasted(Node $node, string $paramName): bool |
288 | 299 | return $node instanceof Array_ && $node->expr instanceof Variable && $this->isName($node->expr, $paramName); |
289 | 300 | } |
290 | 301 |
|
| 302 | + private function isPropertyFetchedOnArrayDimFetch(Node $node, string $paramName): bool |
| 303 | + { |
| 304 | + if (! $node instanceof PropertyFetch && ! $node instanceof StaticPropertyFetch) { |
| 305 | + return false; |
| 306 | + } |
| 307 | + |
| 308 | + $fetchedOn = $node instanceof PropertyFetch ? $node->var : $node->class; |
| 309 | + if (! $fetchedOn instanceof ArrayDimFetch) { |
| 310 | + return false; |
| 311 | + } |
| 312 | + |
| 313 | + return $fetchedOn->var instanceof Variable && $this->isName($fetchedOn->var, $paramName); |
| 314 | + } |
| 315 | + |
| 316 | + private function isInstanceofParam(Node $node, string $paramName): bool |
| 317 | + { |
| 318 | + return $node instanceof Instanceof_ && $node->expr instanceof Variable && $this->isName( |
| 319 | + $node->expr, |
| 320 | + $paramName |
| 321 | + ); |
| 322 | + } |
| 323 | + |
291 | 324 | private function isMethodCall(string $paramName, ?Node $node): bool |
292 | 325 | { |
293 | 326 | if ($node instanceof MethodCall) { |
|
0 commit comments