Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/ReturnTypeExtension/NodeGetAttributeTypeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,16 @@ public function getTypeFromMethodCall(
MethodReflection $methodReflection,
MethodCall $methodCall,
Scope $scope
): Type {
$returnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think to keep 1 - 1 behaviour, selectFromArgs() should be used

$returnType = ParametersAcceptorSelector::selectFromArgs($scope, $methodCall->getArgs(), $methodReflection->getVariants())->getReturnType();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getReturnType() return PHPStan type afaik, it maybe missing test here, but allow return null is changing behavior here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand it correctly, it fallbacks to selectFromArgs() when null is returned.

LGTM 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly


): ?Type {
$firstArg = $methodCall->getArgs()[0];

$argumentValue = $this->resolveArgumentValue($firstArg->value);
if ($argumentValue === null) {
return $returnType;
return null;
}

if (! isset(self::ARGUMENT_KEY_TO_RETURN_TYPE[$argumentValue])) {
return $returnType;
return null;
}

$knownReturnType = self::ARGUMENT_KEY_TO_RETURN_TYPE[$argumentValue];
Expand Down
Loading