-
-
Notifications
You must be signed in to change notification settings - Fork 359
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
Improve UnaryPlus and UnaryMinus support in isDynamicExpr #5177
Merged
samsonasik
merged 8 commits into
rectorphp:main
from
JulianCBC:improve-unary-plus-minus-support-isdynamicexpr
Oct 16, 2023
Merged
Improve UnaryPlus and UnaryMinus support in isDynamicExpr #5177
samsonasik
merged 8 commits into
rectorphp:main
from
JulianCBC:improve-unary-plus-minus-support-isdynamicexpr
Oct 16, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The more I think about this, the more I want it to strictly follow the syntax instead of trying to be sane. One sec... |
…ollowing syntax instead of types
samsonasik
reviewed
Oct 16, 2023
...s_/InlineConstructorDefaultToPropertyRector/Fixture/negative_positive_numeric_string.php.inc
Outdated
Show resolved
Hide resolved
samsonasik
reviewed
Oct 16, 2023
...s_/InlineConstructorDefaultToPropertyRector/Fixture/negative_positive_numeric_string.php.inc
Outdated
Show resolved
Hide resolved
samsonasik
reviewed
Oct 16, 2023
...r/Class_/InlineConstructorDefaultToPropertyRector/Fixture/negative_positive_constant.php.inc
Outdated
Show resolved
Hide resolved
samsonasik
reviewed
Oct 16, 2023
...r/Class_/InlineConstructorDefaultToPropertyRector/Fixture/negative_positive_constant.php.inc
Outdated
Show resolved
Hide resolved
Thanks @samsonasik! Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>
samsonasik
approved these changes
Oct 16, 2023
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.
Looks good, thank you @JulianCBC
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This expands support in
ExprAnalyzer::isDynamicExpr()
forUnaryPlus
andUnaryMinus
to unwrap the expression for the purposes of determining if it's dynamic instead of only allowing numbers.This also contains a tiny bit of refactoring to reduce the indentation in the
isDynamicExpr()
method as it was getting a bit deep.This expands on the original (and correct) fix for rectorphp/rector#8261 to generalise the fix for just about every possible scenario.
From my investigation, adding a
-
or a+
to the front of just about any expression is valid syntax, but determining what is and isn't going to produce aTypeError
on execution was deemed to be too costly for what is ultimately a pretty "trivial" check, and policing "good" code by my standards is pretty pointless, all things considered.This obviously allows a lot of really bad and stupid code past. E.g. all of these are valid syntax but obviously will crash with
TypeError
s when executed:And there's also a huge amount of bad, wrong and incorrect code that does work, e.g.:
And this only covers scenarios that make sense within a couple of lines of code.
I've added some tests to the suite for
InlineConstructorDefaultToPropertyRector
as that was the Rector that triggered this whole story, however there should probably be a stack of direct tests onExprAnalyzer
as testing it via Rectors feels clunky.This has been verified as a working fix by modifying
InlineConstructorDefaultToPropertyRector
to execute functionally equivalent code.