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

[SOLID] Change if && to early return #4344

Merged
merged 6 commits into from Oct 10, 2020

Conversation

dobryy
Copy link
Contributor

@dobryy dobryy commented Oct 3, 2020

No description provided.

@dobryy
Copy link
Contributor Author

dobryy commented Oct 3, 2020

Just checking out very basic logic...

@dobryy dobryy force-pushed the solid-change-and-if-to-early-return branch 13 times, most recently from df95a6a to d2692f2 Compare October 9, 2020 15:41
@dobryy dobryy changed the title WIP: [SOLID] Change if && to early return [SOLID] Change if && to early return Oct 9, 2020
Comment on lines +9 to +17
if ($car->wheelsCount() > 2) {
if ($car->hasWheels && $car->hasFuel) {
$this->canDrive = true;
}

return;
}

$this->canDrive = true;
Copy link
Contributor Author

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.

Comment on lines +12 to +19
foreach ($nodes as $node) {
if ($node instanceof Name && $node instanceof Identifier) {
$this->processNameOrIdentifier($node);
}

return;
}

Copy link
Contributor Author

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.

@TomasVotruba TomasVotruba self-requested a review October 9, 2020 20:04
Copy link
Member

@TomasVotruba TomasVotruba left a 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

@dobryy dobryy force-pushed the solid-change-and-if-to-early-return branch from 23893fc to 38047f4 Compare October 9, 2020 20:18
@dobryy
Copy link
Contributor Author

dobryy commented Oct 9, 2020

I've added few comments

I've implemented changes as a new commit 38047f4

@dobryy dobryy force-pushed the solid-change-and-if-to-early-return branch from 532e4d7 to f853b9f Compare October 9, 2020 21:02
@dobryy
Copy link
Contributor Author

dobryy commented Oct 9, 2020

@TomasVotruba Pipeline is finally green.

@TomasVotruba TomasVotruba self-requested a review October 10, 2020 16:27
@TomasVotruba TomasVotruba merged commit 35537db into master Oct 10, 2020
@TomasVotruba TomasVotruba deleted the solid-change-and-if-to-early-return branch October 10, 2020 16:27
@TomasVotruba
Copy link
Member

Thank you

@ERuban
Copy link

ERuban commented Oct 19, 2020

@dobryy @TomasVotruba hey, I've just a one question - why it is a SOLID rule?

@TomasVotruba
Copy link
Member

TomasVotruba commented Oct 19, 2020

From all the sets there are now, SOLID and early returns are the closest.
What set would you suggest instead and why?

@ERuban
Copy link

ERuban commented Oct 20, 2020

@TomasVotruba So, I would suggest CodingStyle set for this rule - seems it will be better here, just because it is really more about accepted conventions in teams/companies, imho.
Also, why do you think it is closest to SOLID rules?

@TomasVotruba
Copy link
Member

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?

@ERuban
Copy link

ERuban commented Oct 20, 2020

Hm, it will be really nice to move it to a standalone set.
Or, maybe, to CodeQuality set :)

@TomasVotruba
Copy link
Member

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?

@TomasVotruba
Copy link
Member

There is an issue here: #4464

@ERuban
Copy link

ERuban commented Oct 21, 2020

So, ok, standalone set looks ok, imo.
Yeap, it is just academic curiosity (we haven't such rule in our team).

Btw, I've some issues after updating Rector from the older version, but will ask you separately about it. ;)

TomasVotruba added a commit that referenced this pull request Jun 25, 2023
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.

None yet

3 participants