Skip to content

Commit

Permalink
fix: ensure native mixed types remain valid
Browse files Browse the repository at this point in the history
  • Loading branch information
mtouellette authored Feb 16, 2022
1 parent 1b80a1d commit 18ccbeb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Utility/Reflection/Reflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public static function flattenType(ReflectionType $type): string
/** @var ReflectionNamedType $type */
$name = $type->getName();

if ($name !== 'null' && $type->allowsNull()) {
if ($name !== 'null' && $type->allowsNull() && $name !== 'mixed') {
return $name . '|null';
}

Expand Down
14 changes: 14 additions & 0 deletions tests/Unit/Utility/Reflection/ReflectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,20 @@ public function test_union_type_is_handled(): void
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
*/
Expand Down

0 comments on commit 18ccbeb

Please sign in to comment.