diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 721f483ece..d1162ce2f3 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -797,6 +797,21 @@ public function getAnonymousFunctionReturnType(): ?Type /** @api */ public function getType(Expr $node): Type { + if ($node instanceof Node\Scalar\Int_) { + return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this)); + } elseif ($node instanceof String_) { + return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this)); + } elseif ($node instanceof Node\Scalar\Float_) { + return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this)); + } elseif ($node instanceof Expr\UnaryMinus && $node->expr instanceof Node\Scalar) { + return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this)); + } elseif ($node instanceof ConstFetch) { + $loweredConstName = strtolower($node->name->toString()); + if (in_array($loweredConstName, ['true', 'false', 'null'], true)) { + return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this)); + } + } + if ($node instanceof GetIterableKeyTypeExpr) { return $this->getIterableKeyType($this->getType($node->getExpr())); } @@ -1295,11 +1310,7 @@ private function resolveType(string $exprString, Expr $node): Type }); } - if ($node instanceof Node\Scalar\Int_) { - return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this)); - } elseif ($node instanceof String_) { - return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this)); - } elseif ($node instanceof Node\Scalar\InterpolatedString) { + if ($node instanceof Node\Scalar\InterpolatedString) { $resultType = null; foreach ($node->parts as $part) { if ($part instanceof InterpolatedStringPart) { @@ -1316,8 +1327,6 @@ private function resolveType(string $exprString, Expr $node): Type } return $resultType ?? new ConstantStringType(''); - } elseif ($node instanceof Node\Scalar\Float_) { - return $this->initializerExprTypeResolver->getType($node, InitializerExprContext::fromScope($this)); } elseif ($node instanceof Expr\CallLike && $node->isFirstClassCallable()) { if ($node instanceof FuncCall && $node->name instanceof Expr) { $callableType = $this->getType($node->name); @@ -2039,16 +2048,6 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu } if ($node instanceof ConstFetch) { - $constName = (string) $node->name; - $loweredConstName = strtolower($constName); - if ($loweredConstName === 'true') { - return new ConstantBooleanType(true); - } elseif ($loweredConstName === 'false') { - return new ConstantBooleanType(false); - } elseif ($loweredConstName === 'null') { - return new NullType(); - } - $namespacedName = null; if (!$node->name->isFullyQualified() && $this->getNamespace() !== null) { $namespacedName = new FullyQualified([$this->getNamespace(), $node->name->toString()]);