From c625d93adb8af3f959fc12c7ee06311df3710e63 Mon Sep 17 00:00:00 2001 From: Anders Jenbo Date: Sun, 30 Aug 2026 00:37:58 +0200 Subject: [PATCH] Correct calling mergeWith() on the wrong scope --- src/Analyser/CalledMethodProcessor.php | 10 +++++----- src/Analyser/StmtHandler/ClassMethodHandler.php | 2 +- src/Node/ClassPropertiesNode.php | 8 ++++---- .../Properties/SetNonVirtualPropertyHookAssignRule.php | 8 ++++---- .../TooWideTypehints/TooWideParameterOutTypeCheck.php | 6 +++--- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/Analyser/CalledMethodProcessor.php b/src/Analyser/CalledMethodProcessor.php index f79e2bee434..7fd12802b6f 100644 --- a/src/Analyser/CalledMethodProcessor.php +++ b/src/Analyser/CalledMethodProcessor.php @@ -84,7 +84,7 @@ public function processCalledMethod(NodeScopeResolver $nodeScopeResolver, Method }); $calledMethodEndScope = null; - if ($returnStatement !== null) { + if ($returnStatement instanceof MethodReturnStatementsNode) { foreach ($returnStatement->getExecutionEnds() as $executionEnd) { $statementResult = $executionEnd->getStatementResult(); $endNode = $executionEnd->getNode(); @@ -95,19 +95,19 @@ public function processCalledMethod(NodeScopeResolver $nodeScopeResolver, Method } } if ($calledMethodEndScope === null) { - $calledMethodEndScope = $statementResult->getScope(); + $calledMethodEndScope = $statementResult->getScope()->toWalkScope(); continue; } - $calledMethodEndScope = $calledMethodEndScope->mergeWith($statementResult->getScope()); + $calledMethodEndScope = $calledMethodEndScope->mergeWith($statementResult->getScope()->toWalkScope()); } foreach ($returnStatement->getReturnStatements() as $statement) { if ($calledMethodEndScope === null) { - $calledMethodEndScope = $statement->getScope(); + $calledMethodEndScope = $statement->getScope()->toWalkScope(); continue; } - $calledMethodEndScope = $calledMethodEndScope->mergeWith($statement->getScope()); + $calledMethodEndScope = $calledMethodEndScope->mergeWith($statement->getScope()->toWalkScope()); } } diff --git a/src/Analyser/StmtHandler/ClassMethodHandler.php b/src/Analyser/StmtHandler/ClassMethodHandler.php index ddfb10728d9..4ccbbdde423 100644 --- a/src/Analyser/StmtHandler/ClassMethodHandler.php +++ b/src/Analyser/StmtHandler/ClassMethodHandler.php @@ -237,7 +237,7 @@ public function processStmt( continue; } - $endScope = $executionEnd->getStatementResult()->getScope(); + $endScope = $executionEnd->getStatementResult()->getScope()->toWalkScope(); if ($finalScope === null) { $finalScope = $endScope; continue; diff --git a/src/Node/ClassPropertiesNode.php b/src/Node/ClassPropertiesNode.php index a16ce6b8841..678cab8f858 100644 --- a/src/Node/ClassPropertiesNode.php +++ b/src/Node/ClassPropertiesNode.php @@ -291,19 +291,19 @@ private function collectUninitializedProperties(array $constructors, array $unin } } if ($methodScope === null) { - $methodScope = $statementResult->getScope(); + $methodScope = $statementResult->getScope()->toWalkScope(); continue; } - $methodScope = $methodScope->mergeWith($statementResult->getScope()); + $methodScope = $methodScope->mergeWith($statementResult->getScope()->toWalkScope()); } foreach ($returnStatementsNode->getReturnStatements() as $returnStatement) { if ($methodScope === null) { - $methodScope = $returnStatement->getScope(); + $methodScope = $returnStatement->getScope()->toWalkScope(); continue; } - $methodScope = $methodScope->mergeWith($returnStatement->getScope()); + $methodScope = $methodScope->mergeWith($returnStatement->getScope()->toWalkScope()); } if ($methodScope === null) { diff --git a/src/Rules/Properties/SetNonVirtualPropertyHookAssignRule.php b/src/Rules/Properties/SetNonVirtualPropertyHookAssignRule.php index e7a4ac5d88d..d9bdfb79bad 100644 --- a/src/Rules/Properties/SetNonVirtualPropertyHookAssignRule.php +++ b/src/Rules/Properties/SetNonVirtualPropertyHookAssignRule.php @@ -57,19 +57,19 @@ public function processNode(Node $node, Scope $scope): array } } if ($finalHookScope === null) { - $finalHookScope = $statementResult->getScope(); + $finalHookScope = $statementResult->getScope()->toWalkScope(); continue; } - $finalHookScope = $finalHookScope->mergeWith($statementResult->getScope()); + $finalHookScope = $finalHookScope->mergeWith($statementResult->getScope()->toWalkScope()); } foreach ($node->getReturnStatements() as $returnStatement) { if ($finalHookScope === null) { - $finalHookScope = $returnStatement->getScope(); + $finalHookScope = $returnStatement->getScope()->toWalkScope(); continue; } - $finalHookScope = $finalHookScope->mergeWith($returnStatement->getScope()); + $finalHookScope = $finalHookScope->mergeWith($returnStatement->getScope()->toWalkScope()); } if ($finalHookScope === null) { diff --git a/src/Rules/TooWideTypehints/TooWideParameterOutTypeCheck.php b/src/Rules/TooWideTypehints/TooWideParameterOutTypeCheck.php index 4fd41dc37b1..c96036d64fc 100644 --- a/src/Rules/TooWideTypehints/TooWideParameterOutTypeCheck.php +++ b/src/Rules/TooWideTypehints/TooWideParameterOutTypeCheck.php @@ -38,7 +38,7 @@ public function check( { $finalScope = null; foreach ($executionEnds as $executionEnd) { - $endScope = $executionEnd->getStatementResult()->getScope(); + $endScope = $executionEnd->getStatementResult()->getScope()->toWalkScope(); if ($finalScope === null) { $finalScope = $endScope; continue; @@ -49,11 +49,11 @@ public function check( foreach ($returnStatements as $statement) { if ($finalScope === null) { - $finalScope = $statement->getScope(); + $finalScope = $statement->getScope()->toWalkScope(); continue; } - $finalScope = $finalScope->mergeWith($statement->getScope()); + $finalScope = $finalScope->mergeWith($statement->getScope()->toWalkScope()); } if ($finalScope === null) {