|
87 | 87 | use PHPStan\Analyser\MutatingScope; |
88 | 88 | use PHPStan\Analyser\NodeScopeResolver; |
89 | 89 | use PHPStan\Analyser\ScopeContext; |
| 90 | +use PHPStan\Node\Expr\AlwaysRememberedExpr; |
90 | 91 | use PHPStan\Node\FunctionCallableNode; |
91 | 92 | use PHPStan\Node\InstantiationCallableNode; |
92 | 93 | use PHPStan\Node\MethodCallableNode; |
@@ -163,10 +164,13 @@ public function processNodes( |
163 | 164 | $scope = $formerMutatingScope ?? $this->scopeFactory->createFromFile($filePath); |
164 | 165 |
|
165 | 166 | $hasUnreachableStatementNode = false; |
| 167 | + $hasAlwaysRememberedExpr = false; |
| 168 | + |
166 | 169 | $nodeCallback = function (Node $node, MutatingScope $mutatingScope) use ( |
167 | 170 | &$nodeCallback, |
168 | 171 | $filePath, |
169 | | - &$hasUnreachableStatementNode |
| 172 | + &$hasUnreachableStatementNode, |
| 173 | + &$hasAlwaysRememberedExpr |
170 | 174 | ): void { |
171 | 175 | // the class reflection is resolved AFTER entering to class node |
172 | 176 | // so we need to get it from the first after this one |
@@ -364,8 +368,13 @@ public function processNodes( |
364 | 368 | return; |
365 | 369 | } |
366 | 370 |
|
367 | | - if ($node instanceof Match_) { |
368 | | - $this->processMatch($node, $mutatingScope); |
| 371 | + if ($node instanceof AlwaysRememberedExpr || $node instanceof Match_) { |
| 372 | + $hasAlwaysRememberedExpr = true; |
| 373 | + |
| 374 | + if ($node instanceof Match_) { |
| 375 | + $this->processMatch($node, $mutatingScope); |
| 376 | + } |
| 377 | + |
369 | 378 | return; |
370 | 379 | } |
371 | 380 |
|
@@ -411,8 +420,15 @@ public function processNodes( |
411 | 420 | RectorNodeScopeResolver::processNodes($stmts, $scope); |
412 | 421 | } |
413 | 422 |
|
| 423 | + if (! $hasAlwaysRememberedExpr && ! $hasUnreachableStatementNode) { |
| 424 | + return $stmts; |
| 425 | + } |
| 426 | + |
414 | 427 | $nodeTraverser = new NodeTraverser(); |
415 | | - $nodeTraverser->addVisitor(new WrappedNodeRestoringNodeVisitor()); |
| 428 | + |
| 429 | + if ($hasAlwaysRememberedExpr) { |
| 430 | + $nodeTraverser->addVisitor(new WrappedNodeRestoringNodeVisitor()); |
| 431 | + } |
416 | 432 |
|
417 | 433 | if ($hasUnreachableStatementNode) { |
418 | 434 | $nodeTraverser->addVisitor(new UnreachableStatementNodeVisitor($this, $filePath, $scope)); |
|
0 commit comments