From a4445df500e51deb893319e180c3fbdf64e8dc25 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Wed, 21 Feb 2024 15:03:30 +0700 Subject: [PATCH] Cleanup scope check on UnreachableStatementNodeVisitor (#5648) --- src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php b/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php index 5bd43d4f5a8..268ae67e7ec 100644 --- a/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php +++ b/src/PHPStan/NodeVisitor/UnreachableStatementNodeVisitor.php @@ -38,7 +38,9 @@ public function enterNode(Node $node): ?Node $mutatingScope = $this->resolveScope($node->getAttribute(AttributeKey::SCOPE)); foreach ($node->stmts as $stmt) { - if (! $stmt->getAttribute(AttributeKey::SCOPE) instanceof MutatingScope) { + $hasMutatingScope = $stmt->getAttribute(AttributeKey::SCOPE) instanceof MutatingScope; + if (! $hasMutatingScope) { + $stmt->setAttribute(AttributeKey::SCOPE, $mutatingScope); $this->phpStanNodeScopeResolver->processNodes([$stmt], $this->filePath, $mutatingScope); } @@ -49,7 +51,6 @@ public function enterNode(Node $node): ?Node if ($isPassedUnreachableStmt) { $stmt->setAttribute(AttributeKey::IS_UNREACHABLE, true); - $stmt->setAttribute(AttributeKey::SCOPE, $mutatingScope); } }