Skip to content

Commit

Permalink
Set return type as nullable when parent is
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed May 1, 2022
1 parent 3d3c71f commit 88dda72
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ProxyManager/Generator/MagicMethodGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct(ReflectionClass $originalClass, string $name, array
$returnType = $originalMethod->getReturnType();

if ($returnType instanceof ReflectionNamedType) {
$this->setReturnType($returnType->getName());
$this->setReturnType(($returnType->allowsNull() ? '?' : '') . $returnType->getName());
}

$this->setReturnsReference($originalMethod->returnsReference());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static function generateMethod(MethodReflection $originalMethod): self
$method = static::fromReflectionWithoutBodyAndDocBlock($originalMethod);

$returnType = $originalMethod->getReturnType();
$nullCast = $returnType instanceof ReflectionNamedType && in_array($returnType->getName(), ['array', 'float', 'int', 'string'], true) ? '(' . $returnType->getName() . ') ' : '';
$nullCast = $returnType instanceof ReflectionNamedType && ! $returnType->allowsNull() && in_array($returnType->getName(), ['array', 'float', 'int', 'string'], true) ? '(' . $returnType->getName() . ') ' : '';

if ($originalMethod->returnsReference() || $nullCast !== '') {
$reference = IdentifierSuffixer::getIdentifier('ref');
Expand Down

0 comments on commit 88dda72

Please sign in to comment.