Skip to content
Open
Show file tree
Hide file tree
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
11 changes: 8 additions & 3 deletions src/Analyser/MutatingScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -3231,12 +3231,17 @@ public function enterPropertyHook(

private function transformStaticType(Type $type): Type
{
if (!$this->isInClass()) {
return $type;
}

return TypeTraverser::map($type, function (Type $type, callable $traverse): Type {
if (!$this->isInClass()) {
return $type;
}
if ($type instanceof StaticType) {
$classReflection = $this->getClassReflection();
if ($classReflection === null) {
throw new ShouldNotHappenException();
}

$changedType = $type->changeBaseClass($classReflection);
if ($classReflection->isFinal() && !$type instanceof ThisType) {
$changedType = $changedType->getStaticObjectType();
Expand Down
8 changes: 5 additions & 3 deletions src/Reflection/InitializerExprTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2400,9 +2400,11 @@ public function getClassConstFetchTypeByReflection(Name|Expr $class, string $con
}

if (strtolower($constantName) === 'class') {
$reflectionProvider = $this->getReflectionProvider();

return TypeTraverser::map(
$constantClassType,
function (Type $type, callable $traverse): Type {
static function (Type $type, callable $traverse) use ($reflectionProvider): Type {
if ($type instanceof UnionType || $type instanceof IntersectionType) {
return $traverse($type);
}
Expand All @@ -2428,8 +2430,8 @@ function (Type $type, callable $traverse): Type {
new GenericClassStringType($type),
new AccessoryLiteralStringType(),
);
} elseif ($objectClassNames !== [] && $this->getReflectionProvider()->hasClass($objectClassNames[0])) {
$reflection = $this->getReflectionProvider()->getClass($objectClassNames[0]);
} elseif ($objectClassNames !== [] && $reflectionProvider->hasClass($objectClassNames[0])) {
$reflection = $reflectionProvider->getClass($objectClassNames[0]);
if ($reflection->isFinalByKeyword()) {
return new ConstantStringType($reflection->getName(), true);
}
Expand Down
Loading