Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow method tag return type to be by reference #166

Open
wants to merge 1 commit into
base: 1.9.x
Choose a base branch
from

Conversation

jaapio
Copy link
Contributor

@jaapio jaapio commented Nov 17, 2022

Like normal methods the method tag might return by reference. This fix introduces the support of reference return types. However in a real world implementation it not very likely one would ever mix reference return types with none reference return types. If even possible using php __call.

fixes #158

Like normal methods the method tag might return by reference. This
fix introduces the support of reference return types. However in a
real world implementation it not very likely one would ever mix
reference return types with none reference return types. If even possible
using php __call.
@@ -340,6 +342,16 @@ private function parseMethodTagValue(TokenIterator $tokens): Ast\PhpDoc\MethodTa
$returnType = $isStatic ? new Ast\Type\IdentifierTypeNode('static') : null;
$methodName = $returnTypeOrMethodName->name;
$isStatic = false;
} elseif (
$returnTypeOrMethodName instanceof Ast\Type\IntersectionTypeNode
Copy link
Member

Choose a reason for hiding this comment

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

No, that's a horrible hack 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm sorry for this 😊

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How to solve this in a better way? I think this would require a change in the type parser as it is now to greedy.

@jaapio
Copy link
Contributor Author

jaapio commented Mar 12, 2023

@ondrejmirtes before I invest more time to improve this PR, would you merge this feature or is it not a valid case for phpstan? It would force me to find another solution on my side, but that's somehow okish.

@ondrejmirtes
Copy link
Member

@jaapio Hi, I'm pretty sceptical about this. I don't think that PHPStan would use this information in any way (that a method returns by reference). How do you think it'd enhance the analysis?

Also, what about just reading whether __call returns by reference, instead of changing the @method syntax?

@jaapio
Copy link
Contributor Author

jaapio commented Mar 12, 2023

I think from an analysis point of view, you could still read __call. But as a consumer of the parser not being phpstan, it makes sense, as the class containing the @method does not have to contain the implementation of __call.

In case of phpstan the return type being a & makes sense, because a method will have side effects in that case. So you could warn people about mixing @method with and without return type by reference. The only way to know that if they added it by intention to @method.

@ondrejmirtes
Copy link
Member

I’m sorry, that doesn’t sound that exciting, unless you have a bug that’d be prevented with this in mind 😊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Method tag is missing return by reference
2 participants