diff --git a/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/NullObjectMethodInterceptor.php b/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/NullObjectMethodInterceptor.php index 08baed4c..ead15318 100644 --- a/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/NullObjectMethodInterceptor.php +++ b/src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/NullObjectMethodInterceptor.php @@ -19,14 +19,10 @@ class NullObjectMethodInterceptor extends MethodGenerator */ public static function generateMethod(MethodReflection $originalMethod): self { - $method = static::fromReflectionWithoutBodyAndDocBlock($originalMethod); - $originalReturnType = $originalMethod->getReturnType(); + $method = static::fromReflectionWithoutBodyAndDocBlock($originalMethod); - if ($originalReturnType instanceof ReflectionNamedType && $originalReturnType->getName() === 'never') { - $method->setBody('throw new \Exception();'); - } elseif ($originalMethod->returnsReference()) { + if ($originalMethod->returnsReference()) { $reference = IdentifierSuffixer::getIdentifier('ref'); - $method->setBody("\$reference = null;\nreturn \$" . $reference . ';'); } diff --git a/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php b/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php index e8a28a14..d7b6cfa2 100644 --- a/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php +++ b/tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php @@ -145,7 +145,7 @@ public function testNeverReturningMethodCalls(): void self::assertIsCallable($method); $this->expectException(Throwable::class); - $this->expectExceptionMessage(''); + $this->expectExceptionMessage('never-returning function must not implicitly return'); $method(random_int(10, 1000)); }