-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
QA: remove unreachable code #3912
Conversation
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.
Thanks for this @jrfnl. The changes here make sense to me. I have two additions to request:
-
Please can you add
<rule ref="Squiz.PHP.NonExecutableCode"/>
tophpcs.xml.dist
so that this problem does not re-occur. (Note that until Respect all sniffs when reviewing PHP_CodeSniffer itself #3914 is merged, any warnings that the sniff produces will be masked/hidden/ignored.) -
When reviewing the code in this branch, I noticed that there are three other files in violation of
Squiz.PHP.NonExecutableCode.ReturnNotRequired
. Is fixing those in-scope for this pull request?
........................................................W... 60 / 68 (88%)
...W..W. 68 / 68 (100%)
FILE: src/Standards/Squiz/Sniffs/WhiteSpace/MemberVarSpacingSniff.php
----------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------
215 | WARNING | Empty return statement not required here
| | (Squiz.PHP.NonExecutableCode.ReturnNotRequired)
----------------------------------------------------------------------------------------------------------
FILE: src/Sniffs/AbstractScopeSniff.php
----------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------
151 | WARNING | Empty return statement not required here
| | (Squiz.PHP.NonExecutableCode.ReturnNotRequired)
----------------------------------------------------------------------------------------------------------
FILE: tests/Standards/AbstractSniffUnitTest.php
----------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------------------------------------------
434 | WARNING | Empty return statement not required here
| | (Squiz.PHP.NonExecutableCode.ReturnNotRequired)
----------------------------------------------------------------------------------------------------------
Time: 2.42 secs; Memory: 6MB
@fredden Thanks for looking this over. I didn't use the Having said that, I agree that adding those three extra fixes and adding the sniff to the ruleset makes sense. I'm generally cautious about making additions to the CS ruleset used by the repo (or any repo which is not owned/controlled by me), but this seems like a trivial addition. |
Yes, I agree with this approach. In this case, I see the rule-set adjustment as the "add tests to cover the change" part of the contribution. If the maintainer doesn't want the changes to the rule-set, then they probably also don't need the code changes. I also see you as a primary contributor to this repository. |
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.
👍
bbbd75d
to
4f7d703
Compare
`break` after a `return` statement is redundant. As a side-note: I did have to chuckle when I saw that the `NonExecutableCode` test file also included this 😂
... when the `return` is at the end of the function without a value, and therefore not needed.
4f7d703
to
bac22ae
Compare
... which is used for PHPCS itself.
bac22ae
to
91cd66a
Compare
Closing as replaced by PHPCSStandards/PHP_CodeSniffer#96 |
Description
Tests: remove unreachable code
break
after areturn
statement is redundant.As a side-note: I did have to chuckle when I saw that the
NonExecutableCode
test file also included this 😂Various: remove some redundant return statements
... when the
return
is at the end of the function without a value, and therefore not needed.PHPCS: add the
Squiz.PHP.NonExecutableCode
sniff to the ruleset... which is used for PHPCS itself.
Suggested changelog entry
N/A