Squiz/NonExecutableCode: simplify + improve handling of comments and closures #3898
+38
−33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Some tweaks for the sniff which I noticed while reviewing #3770.
Squiz/NonExecutableCode: make sniff more code style independent
When determining whether a
return
statement is the last code token in a function body, comments should be ignored, but weren't.Fixed now. Includes tests.
Squiz/NonExecutableCode: flag redundant return statements in closures too
A return statement which doesn't return a value at the end of a function body would be flagged as "not required" for named functions, but not so for anonymous functions.
Fixed now. Includes tests.
Squiz/NonExecutableCode: fold duplicate code
Follow up on commits 0e10f43 and 01754d9, which both deal with fixing bugs where the sniff would not handle if/elseif/else conditions without curly braces correctly.
This commit merges the two near duplicate code blocks, which the above mentioned commits introduced, each containing code doing essentially the same thing.
Also note that
T_ELSE
is handled separately now aselse
does not take parentheses and can therefore not be a parenthesis owner.This change is already covered by pre-existing tests.
Suggested changelog entry
return
statements just before a function close brace will now be flagged more often.Types of changes