Skip to content

Commit 921f48e

Browse files
committed
get_class() returning false for mixed argument types is too annoying
1 parent 9133e42 commit 921f48e

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

src/Type/Php/GetClassDynamicReturnTypeExtension.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,9 @@ static function (Type $type, callable $traverse): Type {
4949
}
5050

5151
if ($type instanceof TemplateType && !$type instanceof TypeWithClassName) {
52-
if ($type instanceof ObjectWithoutClassType) {
53-
return new GenericClassStringType($type);
54-
}
55-
56-
return new UnionType([
57-
new GenericClassStringType($type),
58-
new ConstantBooleanType(false),
59-
]);
52+
return new GenericClassStringType($type);
6053
} elseif ($type instanceof MixedType) {
61-
return new UnionType([
62-
new ClassStringType(),
63-
new ConstantBooleanType(false),
64-
]);
54+
return new ClassStringType();
6555
} elseif ($type instanceof StaticType) {
6656
return new GenericClassStringType($type->getStaticObjectType());
6757
} elseif ($type instanceof TypeWithClassName) {

tests/PHPStan/Analyser/data/generics.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ function arrayOfGenericClassStrings(array $a): void
12971297
function getClassOnTemplateType($a, $b, $c, $d, $object, $mixed, $tObject)
12981298
{
12991299
assertType(
1300-
'class-string<T (function PHPStan\Generics\FunctionsAssertType\getClassOnTemplateType(), argument)>|false',
1300+
'class-string<T (function PHPStan\Generics\FunctionsAssertType\getClassOnTemplateType(), argument)>',
13011301
get_class($a)
13021302
);
13031303
assertType(
@@ -1322,7 +1322,7 @@ function getClassOnTemplateType($a, $b, $c, $d, $object, $mixed, $tObject)
13221322
);
13231323

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

0 commit comments

Comments
 (0)