fix: ensure native mixed types remain valid

This commit is contained in:
mtouellette 2022-02-16 09:50:14 -05:00 committed by GitHub
parent 1b80a1df9d
commit 18ccbebb9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -81,7 +81,7 @@ final class Reflection
/** @var ReflectionNamedType $type */
$name = $type->getName();
if ($name !== 'null' && $type->allowsNull()) {
if ($name !== 'null' && $type->allowsNull() && $name !== 'mixed') {
return $name . '|null';
}

View File

@ -105,6 +105,20 @@ final class ReflectionTest extends TestCase
self::assertSame('int|float', Reflection::flattenType($type));
}
/**
* @requires PHP >= 8
*/
public function test_mixed_type_is_handled(): void
{
$object = new class () {
public mixed $someProperty;
};
/** @var ReflectionType $type */
$type = (new ReflectionProperty($object, 'someProperty'))->getType();
self::assertSame('mixed', Reflection::flattenType($type));
}
/**
* @requires PHP >= 8.1
*/