diff --git a/src/ProxyManager/Generator/MethodGenerator.php b/src/ProxyManager/Generator/MethodGenerator.php index 1349c4e7..ae45ec64 100644 --- a/src/ProxyManager/Generator/MethodGenerator.php +++ b/src/ProxyManager/Generator/MethodGenerator.php @@ -69,7 +69,7 @@ public static function copyMethodSignature(MethodReflection $reflectionMethod): $parameter->setDefaultValue(new ValueGenerator($default, $reflectionParameter)); $type = $parameter->getType(); - if ($default->getValue() === null && strpos($type ?? '?', '?') !== 0 && strpos($type, '|') === false) { + if ($default->getValue() === null && strpos($type ?? '?', '?') !== 0 && strpos($type, '|') === false && $type !== 'mixed') { $parameter->setType('?' . $type); } } diff --git a/tests/ProxyManagerTest/Generator/MethodGeneratorTest.php b/tests/ProxyManagerTest/Generator/MethodGeneratorTest.php index d06ae613..9a8d53ee 100644 --- a/tests/ProxyManagerTest/Generator/MethodGeneratorTest.php +++ b/tests/ProxyManagerTest/Generator/MethodGeneratorTest.php @@ -10,6 +10,7 @@ use ProxyManager\Generator\MethodGenerator; use ProxyManagerTestAsset\BaseClass; use ProxyManagerTestAsset\ClassWithAbstractPublicMethod; +use ProxyManagerTestAsset\ClassWithNullDefaultMethodArguments; use ProxyManagerTestAsset\EmptyClass; use ProxyManagerTestAsset\ReturnTypeHintedClass; use ProxyManagerTestAsset\ScalarTypeHintedClass; @@ -134,6 +135,27 @@ public function scalarTypeHintedMethods(): array ]; } + /** + * @requires PHP 8.0 + */ + public function testGenerateMethodWithNullDefaultMixedArgument(): void + { + $method = MethodGenerator::fromReflectionWithoutBodyAndDocBlock(new MethodReflection( + ClassWithNullDefaultMethodArguments::class, + 'acceptMixed' + )); + + self::assertSame('acceptMixed', $method->getName()); + + $parameters = $method->getParameters(); + + self::assertCount(1, $parameters); + + $param = $parameters['param']; + + self::assertSame('mixed', $param->getType()); + } + public function testGenerateMethodWithVoidReturnTypeHinting(): void { $method = MethodGenerator::fromReflectionWithoutBodyAndDocBlock(new MethodReflection( diff --git a/tests/ProxyManagerTestAsset/ClassWithNullDefaultMethodArguments.php b/tests/ProxyManagerTestAsset/ClassWithNullDefaultMethodArguments.php new file mode 100644 index 00000000..be6f298f --- /dev/null +++ b/tests/ProxyManagerTestAsset/ClassWithNullDefaultMethodArguments.php @@ -0,0 +1,13 @@ +