Skip to content

Commit

Permalink
remove unneeded generated code for never returning methods
Browse files Browse the repository at this point in the history
  • Loading branch information
alekitto committed May 3, 2022
1 parent 5260382 commit 818c8ee
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Laminas\Code\Reflection\MethodReflection;
use ProxyManager\Generator\MethodGenerator;
use ProxyManager\Generator\Util\IdentifierSuffixer;
use ReflectionNamedType;

/**
* Method decorator for null objects
Expand All @@ -19,14 +18,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 . ';');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down

0 comments on commit 818c8ee

Please sign in to comment.