From f6b604d68e8e1fa73842b7c5ab931433c73bc95a Mon Sep 17 00:00:00 2001 From: Alessandro Chitolina Date: Tue, 3 May 2022 10:46:02 +0200 Subject: [PATCH] remove unneeded generated code for never returning methods --- .../MethodGenerator/NullObjectMethodInterceptor.php | 8 ++------ .../Functional/NullObjectFunctionalTest.php | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) 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)); }