-
-
Notifications
You must be signed in to change notification settings - Fork 680
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
[SOLID] Change if && to early return #4344
Conversation
Just checking out very basic logic... |
df95a6a
to
d2692f2
Compare
rules/solid/tests/Rector/If_/ChangeAndIfToEarlyReturnRector/Fixture/equals.php.inc
Show resolved
Hide resolved
...ests/Rector/If_/ChangeAndIfToEarlyReturnRector/Fixture/skip_more_than_two_conditions.php.inc
Show resolved
Hide resolved
if ($car->wheelsCount() > 2) { | ||
if ($car->hasWheels && $car->hasFuel) { | ||
$this->canDrive = true; | ||
} | ||
|
||
return; | ||
} | ||
|
||
$this->canDrive = true; |
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.
@TomasVotruba This situation can be handled in the next PR.
foreach ($nodes as $node) { | ||
if ($node instanceof Name && $node instanceof Identifier) { | ||
$this->processNameOrIdentifier($node); | ||
} | ||
|
||
return; | ||
} | ||
|
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.
@TomasVotruba This situation looks crazy but also can be handled in the next PR.
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've added few comments
23893fc
to
38047f4
Compare
I've implemented changes as a new commit 38047f4 |
532e4d7
to
f853b9f
Compare
@TomasVotruba Pipeline is finally green. |
Thank you |
@dobryy @TomasVotruba hey, I've just a one question - why it is a SOLID rule? |
From all the sets there are now, SOLID and early returns are the closest. |
@TomasVotruba So, I would suggest |
In this it's rather about code quality than convention. We choose solid, as it's in similar group of more advanced code quality, so are object calisthenics, where is early return mentioned https://williamdurand.fr/2013/06/03/object-calisthenics The same way SOLID principles require more experience knowledge, the early returns are not so easy to refactor. Yet, I believe if we both have doubt about rule set location, I think it should be improved. I was thinking about standalone "early return" set. As it include continue, really return for and/or etc. It's not a small group and the name would sell it better. What do you think? |
Hm, it will be really nice to move it to a standalone set. |
Then, next month we a question, why it's part of CodeQuality set :D Btw, is current situation causing any undesired behavior of Rector in your code or is it rather academic curiosity? |
There is an issue here: #4464 |
So, ok, standalone set looks ok, imo. Btw, I've some issues after updating Rector from the older version, but will ask you separately about it. ;) |
rectorphp/rector-src@53e4e9f [CodingStyle] Reduce parent attribute usage on NameImporter (#4344)
No description provided.