Skip to content

Commit

Permalink
get_class() returns false for mixed argument types
Browse files Browse the repository at this point in the history
This reverts commit 921f48e.
  • Loading branch information
ondrejmirtes committed Sep 12, 2021
1 parent f76875a commit e86742d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 12 additions & 2 deletions src/Type/Php/GetClassDynamicReturnTypeExtension.php
Expand Up @@ -49,9 +49,19 @@ static function (Type $type, callable $traverse): Type {
}

if ($type instanceof TemplateType && !$type instanceof TypeWithClassName) {
return new GenericClassStringType($type);
if ($type instanceof ObjectWithoutClassType) {
return new GenericClassStringType($type);
}

return new UnionType([
new GenericClassStringType($type),
new ConstantBooleanType(false),
]);
} elseif ($type instanceof MixedType) {
return new ClassStringType();
return new UnionType([
new ClassStringType(),
new ConstantBooleanType(false),
]);
} elseif ($type instanceof StaticType) {
return new GenericClassStringType($type->getStaticObjectType());
} elseif ($type instanceof TypeWithClassName) {
Expand Down
4 changes: 2 additions & 2 deletions tests/PHPStan/Analyser/data/generics.php
Expand Up @@ -1299,7 +1299,7 @@ function arrayOfGenericClassStrings(array $a): void
function getClassOnTemplateType($a, $b, $c, $d, $object, $mixed, $tObject)
{
assertType(
'class-string<T (function PHPStan\Generics\FunctionsAssertType\getClassOnTemplateType(), argument)>',
'class-string<T (function PHPStan\Generics\FunctionsAssertType\getClassOnTemplateType(), argument)>|false',
get_class($a)
);
assertType(
Expand All @@ -1324,7 +1324,7 @@ function getClassOnTemplateType($a, $b, $c, $d, $object, $mixed, $tObject)
);

assertType('class-string', get_class($object));
assertType('class-string', get_class($mixed));
assertType('class-string|false', get_class($mixed));
assertType('class-string<W of object (function PHPStan\Generics\FunctionsAssertType\getClassOnTemplateType(), argument)>', get_class($tObject));
}

Expand Down

0 comments on commit e86742d

Please sign in to comment.