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

SONARPHP-1562 Add basic support for PropertyHooks #1302

Merged
merged 5 commits into from
Nov 7, 2024

Conversation

jonas-wielage-sonarsource
Copy link
Contributor

@jonas-wielage-sonarsource jonas-wielage-sonarsource commented Nov 7, 2024

SONARPHP-1562

Part of

Copy link
Contributor

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(),
Copy link
Contributor

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?

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 tried to do it by adding it to PHPKeywordsbut this will conflict the parser when other method declarations try to declare getor setmethods.
If you know another way, I'm happy to change it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found one!

Comment on lines 730 to 732
if (!"get".equals(name.text()) && !"set".equals(name.text())) {
throw new RecognitionException(((PHPTree) name).getLine(), "Declared property hook must be named \"get\" or \"set\"");
}
Copy link
Contributor

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.

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 agree, but didn't find a good way to do it. I May try again.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Found one!

@jonas-wielage-sonarsource jonas-wielage-sonarsource merged commit ab99908 into master Nov 7, 2024
18 checks passed
@jonas-wielage-sonarsource jonas-wielage-sonarsource deleted the SONARPHP-1562 branch November 7, 2024 15:55
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.

2 participants