-
Notifications
You must be signed in to change notification settings - Fork 103
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
SONARPHP-1562 Add basic support for PropertyHooks #1302
Conversation
7575917
to
84f1e61
Compare
84f1e61
to
49d4642
Compare
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.
LGTM! I believe everything from the RFC is covered (considering the other subtickets), good job!
Please see my few comments.
b.zeroOrMore(ATTRIBUTE_GROUP()), | ||
b.zeroOrMore(MEMBER_MODIFIER()), | ||
b.optional(b.token(PHPPunctuator.AMPERSAND)), | ||
NAME_IDENTIFIER_OR_KEYWORD(), |
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.
Instead of allowing any string here, couldn't we explicitly only allow get
or set
, with possibly enum values in the AST?
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 tried to do it by adding it to PHPKeywords
but this will conflict the parser when other method declarations try to declare get
or set
methods.
If you know another way, I'm happy to change 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.
Found one!
php-frontend/src/main/java/org/sonar/php/tree/impl/declaration/PropertyHookListTreeImpl.java
Outdated
Show resolved
Hide resolved
...tend/src/main/java/org/sonar/php/tree/impl/declaration/ClassPropertyDeclarationTreeImpl.java
Show resolved
Hide resolved
if (!"get".equals(name.text()) && !"set".equals(name.text())) { | ||
throw new RecognitionException(((PHPTree) name).getLine(), "Declared property hook must be named \"get\" or \"set\""); | ||
} |
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 seems strange to me to have part of the grammar logic in the TreeFactory
class. As mentioned above I would strictly match get
/set
in the grammar and not grab any word.
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 agree, but didn't find a good way to do it. I May try again.
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.
Found one!
php-frontend/src/main/java/org/sonar/php/parser/PHPGrammar.java
Outdated
Show resolved
Hide resolved
php-frontend/src/main/java/org/sonar/php/parser/PHPGrammar.java
Outdated
Show resolved
Hide resolved
Quality Gate passedIssues Measures |
SONARPHP-1562
Part of