Skip to content

Commit 3425d9d

Browse files
committed
Take advantage of variadic mergeWith, pt. 2
1 parent 08d45ff commit 3425d9d

1 file changed

Lines changed: 8 additions & 17 deletions

File tree

src/Analyser/NodeScopeResolver.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -863,37 +863,28 @@ private function processStmtNode(
863863
), $methodScope, $storage);
864864

865865
if ($isConstructor && $this->narrowMethodScopeFromConstructor) {
866-
$finalScope = null;
867-
866+
$scopesToMerge = [];
868867
foreach ($executionEnds as $executionEnd) {
869868
if ($executionEnd->getStatementResult()->isAlwaysTerminating()) {
870869
continue;
871870
}
872871

873-
$endScope = $executionEnd->getStatementResult()->getScope();
874-
if ($finalScope === null) {
875-
$finalScope = $endScope;
876-
continue;
877-
}
878-
879-
$finalScope = $finalScope->mergeWith($endScope);
872+
$scopesToMerge[] = $executionEnd->getStatementResult()->getScope()->toMutatingScope();
880873
}
881874

882875
foreach ($gatheredReturnStatements as $statement) {
883-
if ($finalScope === null) {
884-
$finalScope = $statement->getScope()->toMutatingScope();
885-
continue;
886-
}
887-
888-
$finalScope = $finalScope->mergeWith($statement->getScope()->toMutatingScope());
876+
$scopesToMerge[] = $statement->getScope()->toMutatingScope();
889877
}
890878

891-
if ($finalScope !== null) {
892-
$scope = $finalScope->rememberConstructorScope();
879+
if (count($scopesToMerge) > 0) {
880+
$scope = $scopesToMerge[0]->mergeWith(...array_slice($scopesToMerge, 1))->rememberConstructorScope();
893881
}
894882

895883
}
896884
}
885+
if (!$scope->isInClass()) {
886+
throw new ShouldNotHappenException();
887+
}
897888
if (!$scope->getClassReflection()->isAnonymous() && !$scope->isInAnonymousFunction()) {
898889
$this->processPendingFibers($storage);
899890
}

0 commit comments

Comments
 (0)