WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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()]);
Expand Down
Loading