From 18ccbebb9a4484e4efb4db2c5c9405e853578e7d Mon Sep 17 00:00:00 2001 From: mtouellette <77415006+mtouellette@users.noreply.github.com> Date: Wed, 16 Feb 2022 09:50:14 -0500 Subject: [PATCH] fix: ensure native mixed types remain valid --- src/Utility/Reflection/Reflection.php | 2 +- tests/Unit/Utility/Reflection/ReflectionTest.php | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Utility/Reflection/Reflection.php b/src/Utility/Reflection/Reflection.php index acaa7a9..cf358e3 100644 --- a/src/Utility/Reflection/Reflection.php +++ b/src/Utility/Reflection/Reflection.php @@ -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'; } diff --git a/tests/Unit/Utility/Reflection/ReflectionTest.php b/tests/Unit/Utility/Reflection/ReflectionTest.php index f41df8f..4b11bad 100644 --- a/tests/Unit/Utility/Reflection/ReflectionTest.php +++ b/tests/Unit/Utility/Reflection/ReflectionTest.php @@ -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 */