Skip to content

Commit 88dda72

Browse files
committedMay 1, 2022
Set return type as nullable when parent is
1 parent 3d3c71f commit 88dda72

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed
 

‎src/ProxyManager/Generator/MagicMethodGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function __construct(ReflectionClass $originalClass, string $name, array
3636
$returnType = $originalMethod->getReturnType();
3737

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

4242
$this->setReturnsReference($originalMethod->returnsReference());

‎src/ProxyManager/ProxyGenerator/NullObject/MethodGenerator/NullObjectMethodInterceptor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public static function generateMethod(MethodReflection $originalMethod): self
2424
$method = static::fromReflectionWithoutBodyAndDocBlock($originalMethod);
2525

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

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

0 commit comments

Comments
 (0)