-
Notifications
You must be signed in to change notification settings - Fork 82
Add more modifier checks to MethodDeclaration node #306
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
Add more modifier checks to MethodDeclaration node #306
Conversation
|
Thanks for the PR! Can you tell me about why you want this change or what you are using this parser for? |
|
I'm working on a PHP linter that uses this parser, and I need to be able to query the nodes more easily. I originally was decorating the nodes, but decided to try a PR to see how receptive you'd be to this kind of improvement. Sorry about the really sparse PR! |
roblourens
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense, thanks!
| } | ||
|
|
||
| public function isPublic() : bool { | ||
| return $this->hasModifier(TokenKind::PublicKeyword); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class X { function test() {}} still has an implicitly public method X::test(), but this returns false - I can see this being misunderstood in applications using this helper, for that edge case.
This is low priority for me, though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's a good point. Could change isPublic to just check !isPrivate but it might be better to just expose hasModifier, I think the goal is to expose the AST but not necessarily "interpret" it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be useful to have a link to projects using tolerant-php-parser in the documentation, as examples for people writing their own applications/libraries.
E.g. there's https://github.com/tysonandre/tolerant-php-parser-to-php-ast (part of Phan), https://github.com/felixfbecker/php-language-server , etc.
The first one is notable in trying to convert all of the information provided by various node types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made that change and just left hasModifier, FYI @inxilpro
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could also see changing these to hasPublicModifier()/etc to be more clear about what question it's answering.
No description provided.