Skip to content
Snippets Groups Projects
Commit 88dda72c authored by Nicolas Grekas's avatar Nicolas Grekas
Browse files

Set return type as nullable when parent is

parent 3d3c71f8
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,7 @@ class MagicMethodGenerator extends MethodGenerator ...@@ -36,7 +36,7 @@ class MagicMethodGenerator extends MethodGenerator
$returnType = $originalMethod->getReturnType(); $returnType = $originalMethod->getReturnType();
if ($returnType instanceof ReflectionNamedType) { if ($returnType instanceof ReflectionNamedType) {
$this->setReturnType($returnType->getName()); $this->setReturnType(($returnType->allowsNull() ? '?' : '') . $returnType->getName());
} }
$this->setReturnsReference($originalMethod->returnsReference()); $this->setReturnsReference($originalMethod->returnsReference());
......
...@@ -24,7 +24,7 @@ class NullObjectMethodInterceptor extends MethodGenerator ...@@ -24,7 +24,7 @@ class NullObjectMethodInterceptor extends MethodGenerator
$method = static::fromReflectionWithoutBodyAndDocBlock($originalMethod); $method = static::fromReflectionWithoutBodyAndDocBlock($originalMethod);
$returnType = $originalMethod->getReturnType(); $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 !== '') { if ($originalMethod->returnsReference() || $nullCast !== '') {
$reference = IdentifierSuffixer::getIdentifier('ref'); $reference = IdentifierSuffixer::getIdentifier('ref');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment