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 2de9c43 commit 90601cf
Showing 1 changed file with 2 additions and 6 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

0 comments on commit 90601cf

Please sign in to comment.