-
-
Notifications
You must be signed in to change notification settings - Fork 178
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
EarlyExitNotUsed sniff promotes inconsistent code organization #371
Comments
@Majkl578 what do you think? |
I noticed this earlier too. But this is really personal thing, at work, we had multiple discussions about this sniff and some colleagues didn't fully accept even the more obvious cases... |
I'd make an exception here and only report the violation if the block is larger than one line. Otherwise, the |
Agreed. That's why is a little difficult to satisfy everyone's needs. Currently I prefer not to do any exceptions in the sniff. You can always use |
The "fixing" part should only be added where it won't break code. As such this must be just a warning (or at least a non fixable error) instead of the code flow continues as in this case. |
How would the sniff break the code? |
Ah, I see the [x] is only there for the 2nd if. So it seems fine then. Nothing that can be done here then. |
What about making the sniff customizable, so that the smallest block size that the violation should be reported for can be set as a property? |
I would suggest to revisit this issue, here's the kind of mess it creates: phpcs asks us to convert this code: public function __clone()
{
(...)
if ($this->where !== null) {
$this->where = clone $this->where;
}
if ($this->having !== null) {
$this->having = clone $this->having;
}
} to: public function __clone()
{
(...)
if ($this->where !== null) {
$this->where = clone $this->where;
}
if ($this->having === null) {
return;
}
$this->having = clone $this->having;
} Which kills consistency & readability in this specific case. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Consider an example:
The two
if
-statements are identical and have the same semantics. Using an early exit in the latter will make them look different and therefore will increas the cognitive load on the reader.Besides that, even with one
if
-statement in the block, the sniff sometimes produces a sub-optimal suggestion:In this case, fixing this violation will not reduce code nesting and will add one more line of code.
I like the sniff itself to not disable it entirely, but it'd be nice if it was optimized for handling cases like the above.
The text was updated successfully, but these errors were encountered: