diff --git a/rules-tests/Renaming/Rector/FuncCall/RenameFunctionRector/Fixture/with_die_and_session2.php.inc b/rules-tests/Renaming/Rector/FuncCall/RenameFunctionRector/Fixture/with_die_and_session2.php.inc new file mode 100644 index 00000000000..1cca955cfa3 --- /dev/null +++ b/rules-tests/Renaming/Rector/FuncCall/RenameFunctionRector/Fixture/with_die_and_session2.php.inc @@ -0,0 +1,55 @@ + +----- + \ No newline at end of file diff --git a/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php b/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php index 8fff3eb8469..5bd43d4f5a8 100644 --- a/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php +++ b/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php @@ -5,11 +5,8 @@ namespace Rector\PHPStan\NodeVisitor; use PhpParser\Node; -use PhpParser\Node\Expr; -use PhpParser\Node\Expr\Exit_; use PhpParser\Node\Stmt\ClassLike; use PhpParser\Node\Stmt\Declare_; -use PhpParser\Node\Stmt\Expression; use PhpParser\NodeVisitorAbstract; use PHPStan\Analyser\MutatingScope; use PHPStan\Analyser\Scope; @@ -41,11 +38,8 @@ public function enterNode(Node $node): ?Node $mutatingScope = $this->resolveScope($node->getAttribute(AttributeKey::SCOPE)); foreach ($node->stmts as $stmt) { - if ($stmt instanceof Expression && $stmt->expr instanceof Exit_) { - $isPassedUnreachableStmt = true; - $this->processExitScope($stmt->expr, $stmt, $mutatingScope); - - continue; + if (! $stmt->getAttribute(AttributeKey::SCOPE) instanceof MutatingScope) { + $this->phpStanNodeScopeResolver->processNodes([$stmt], $this->filePath, $mutatingScope); } if ($stmt->getAttribute(AttributeKey::IS_UNREACHABLE) === true) { @@ -56,21 +50,12 @@ public function enterNode(Node $node): ?Node if ($isPassedUnreachableStmt) { $stmt->setAttribute(AttributeKey::IS_UNREACHABLE, true); $stmt->setAttribute(AttributeKey::SCOPE, $mutatingScope); - $this->phpStanNodeScopeResolver->processNodes([$stmt], $this->filePath, $mutatingScope); } } return null; } - private function processExitScope(Exit_ $exit, Expression $expression, MutatingScope $mutatingScope): void - { - if ($exit->expr instanceof Expr && ! $exit->expr->getAttribute(AttributeKey::SCOPE) instanceof MutatingScope) { - $expression->setAttribute(AttributeKey::SCOPE, $mutatingScope); - $this->phpStanNodeScopeResolver->processNodes([$expression], $this->filePath, $mutatingScope); - } - } - private function resolveScope(?Scope $mutatingScope): MutatingScope { return $mutatingScope instanceof MutatingScope ? $mutatingScope : $this->scopeFactory->createFromFile(