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 f6b604d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 . ';');
}

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 f6b604d

Please sign in to comment.