Skip to content

Commit 818c8ee

Browse files
committed
remove unneeded generated code for never returning methods
1 parent 5260382 commit 818c8ee

File tree

2 files changed

+3
-8
lines changed

2 files changed

+3
-8
lines changed

src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/NullObjectMethodInterceptor.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Laminas\Code\Reflection\MethodReflection;
88
use ProxyManager\Generator\MethodGenerator;
99
use ProxyManager\Generator\Util\IdentifierSuffixer;
10-
use ReflectionNamedType;
1110

1211
/**
1312
* Method decorator for null objects
@@ -19,14 +18,10 @@ class NullObjectMethodInterceptor extends MethodGenerator
1918
*/
2019
public static function generateMethod(MethodReflection $originalMethod): self
2120
{
22-
$method = static::fromReflectionWithoutBodyAndDocBlock($originalMethod);
23-
$originalReturnType = $originalMethod->getReturnType();
21+
$method = static::fromReflectionWithoutBodyAndDocBlock($originalMethod);
2422

25-
if ($originalReturnType instanceof ReflectionNamedType && $originalReturnType->getName() === 'never') {
26-
$method->setBody('throw new \Exception();');
27-
} elseif ($originalMethod->returnsReference()) {
23+
if ($originalMethod->returnsReference()) {
2824
$reference = IdentifierSuffixer::getIdentifier('ref');
29-
3025
$method->setBody("\$reference = null;\nreturn \$" . $reference . ';');
3126
}
3227

tests/ProxyManagerTest/Functional/NullObjectFunctionalTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function testNeverReturningMethodCalls(): void
145145
self::assertIsCallable($method);
146146

147147
$this->expectException(Throwable::class);
148-
$this->expectExceptionMessage('');
148+
$this->expectExceptionMessage('never-returning function must not implicitly return');
149149
$method(random_int(10, 1000));
150150
}
151151

0 commit comments

Comments
 (0)