-
-
Notifications
You must be signed in to change notification settings - Fork 336
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
[Downgrade 7.0] Strip unnecessary parentheses around expressions #1617
Conversation
rules/DowngradePhp70/Rector/Expr/DowngradeUnnecessarilyParenthesizedExpressionRector.php
Outdated
Show resolved
Hide resolved
rules/DowngradePhp70/Rector/Expr/DowngradeUnnecessarilyParenthesizedExpressionRector.php
Outdated
Show resolved
Hide resolved
b150a32
to
3996410
Compare
The class name seems too long: https://github.com/rectorphp/rector-src/runs/4708654341?check_suite_focus=true#step:5:9 Could you try rename to the shorter name? Thank you |
It looks to me the rule thinks more than five lines of comments must be code even when it is documentation: |
I see, How about move comment to the method? |
The comment already has a method for itself (sharing it with two statements). I guess I could make the lines slightly longer so it fits on five lines. |
Or remove the rule since it does not actually check for commented out code but comment length. |
rules/DowngradePhp70/Rector/Expr/DowngradeUnnecessarilyParenthesizedExpressionRector.php
Outdated
Show resolved
Hide resolved
be68c84
to
e1246ab
Compare
rules/DowngradePhp70/Rector/Expr/DowngradeUnnecessarilyParenthesizedExpressionRector.php
Outdated
Show resolved
Hide resolved
0f0010c
to
bfd678a
Compare
The Uniform variable syntax RFC implemented in PHP 7.0 allows wrapping arbitrary expressions in parentheses, which is not supported by PHP 5. Since PHP 5 cannot parse that we need to strip them. And because parenthesization is not part of the AST, we need to force the code to be re-generated. Rector will re-generate code for AST nodes that changed. Or we can remove the original node reference to the same effect. The code generator will only put parentheses where strictly necessary, like to disambiguate method call from calling a callable property in `($foo->bar)()`. That should be handled by a different rule.
bfd678a
to
197e5cb
Compare
Thank you |
The Uniform variable syntax RFC implemented in PHP 7.0 allows wrapping arbitrary expressions in parentheses, which is not supported by PHP 5. Let’s re-create those AST nodes so that the parentheses are stripped where not strictly necessary.
This does not deal with syntax like
($foo->bar)()
, where parentheses are mandatory, which is used to disambiguate method calls from calling callable properties.