From 061c0035837c28bc6dade48fd4d386fdd0dbd48c Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 6 Jan 2026 12:42:10 +0100 Subject: [PATCH 1/2] MutatingScope: Reduce duplicate expression printing --- src/Analyser/MutatingScope.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index ead7b24c5c..363ceb4c43 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -945,7 +945,7 @@ private function resolveType(string $exprString, Expr $node): Type !$node instanceof Variable && !$node instanceof Expr\Closure && !$node instanceof Expr\ArrowFunction - && $this->hasExpressionType($node)->yes() + && $this->hasExpressionTypeByString($exprString, $node)->yes() ) { return $this->expressionTypes[$exprString]->getType(); } @@ -2074,10 +2074,11 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu continue; } $constFetch = new ConstFetch($name); - if ($this->hasExpressionType($constFetch)->yes()) { + $constExprString = $this->getNodeKey($constFetch); + if ($this->hasExpressionTypeByString($constExprString, $constFetch)->yes()) { return $this->constantResolver->resolveConstantType( $name->toString(), - $this->expressionTypes[$this->getNodeKey($constFetch)]->getType(), + $this->expressionTypes[$constExprString]->getType(), ); } } @@ -2089,7 +2090,7 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu return new ErrorType(); } elseif ($node instanceof Node\Expr\ClassConstFetch && $node->name instanceof Node\Identifier) { - if ($this->hasExpressionType($node)->yes()) { + if ($this->hasExpressionTypeByString($exprString, $node)->yes()) { return $this->expressionTypes[$exprString]->getType(); } return $this->initializerExprTypeResolver->getClassConstFetchTypeByReflection( @@ -2919,12 +2920,19 @@ public function getTypeFromValue($value): Type /** @api */ public function hasExpressionType(Expr $node): TrinaryLogic + { + return $this->hasExpressionTypeByString( + $this->getNodeKey($node), + $node + ); + } + + private function hasExpressionTypeByString(string $exprString, Expr $node): TrinaryLogic { if ($node instanceof Variable && is_string($node->name)) { return $this->hasVariableType($node->name); } - $exprString = $this->getNodeKey($node); if (!isset($this->expressionTypes[$exprString])) { return TrinaryLogic::createNo(); } From a00c3b1226067afa8f49ba0a4dc30bb4059ef413 Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Tue, 6 Jan 2026 13:57:07 +0100 Subject: [PATCH 2/2] Simplify --- src/Analyser/MutatingScope.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 363ceb4c43..6574d0a1c8 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -2921,16 +2921,20 @@ public function getTypeFromValue($value): Type /** @api */ public function hasExpressionType(Expr $node): TrinaryLogic { + if ($node instanceof Variable && is_string($node->name)) { + return $this->hasVariableType($node->name); + } + return $this->hasExpressionTypeByString( $this->getNodeKey($node), - $node + $node, ); } private function hasExpressionTypeByString(string $exprString, Expr $node): TrinaryLogic { - if ($node instanceof Variable && is_string($node->name)) { - return $this->hasVariableType($node->name); + if ($node instanceof Variable) { + throw new ShouldNotHappenException(); } if (!isset($this->expressionTypes[$exprString])) {