-
-
Notifications
You must be signed in to change notification settings - Fork 430
[dead-code] Add RemoveConditionExactReturnRector #7482
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
Conversation
|
I've realized this can be extended for any compared value, WIP |
320cef7 to
98456f6
Compare
b4aa078 to
7f19815
Compare
| if ($identicalOrEqual->right instanceof MethodCall) { | ||
| continue; | ||
| } | ||
|
|
||
| if ($identicalOrEqual->right instanceof StaticCall) { |
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.
there is SideEffectNodeDetector service for it, I will create new PR for 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.
| <<<'CODE_SAMPLE' | ||
| final class SomeClass | ||
| { | ||
| public function __construct(array $items) | ||
| { | ||
| if ($items === []) { | ||
| return []; | ||
| } | ||
|
|
||
| return $items; | ||
| } | ||
| } | ||
| CODE_SAMPLE | ||
|
|
||
| , | ||
| <<<'CODE_SAMPLE' | ||
| final class SomeClass | ||
| { | ||
| public function __construct(array $items) | ||
| { | ||
| if ($items === []) { | ||
| return []; | ||
| } | ||
|
|
||
| return $items; | ||
| } | ||
| } |
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.
before vs after code sample is equal, detected at getrector.com website
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.
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.
We should have a CI check for this here.
These structure are identical and can be narrowed:
It doesn't make sense to compare variable to X and then return X or X. Just return X directly :)