PHP 7.3: New DiscouragedSwitchContinue
sniff
#687
Merged
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.
As of PHP 7.3, using
continue
to targetswitch
will start throwing anE_WARNING
.Refs:
This PR adds a new sniff to detect this.
Notes:
ForbiddenBreakContinueOutsideLoop
sniff.For this sniff, I've elected to prevent the false positives which plague the other sniff, though this does mean that the sniff will underreport (false negatives) for
continue
targetingswitch
when nested control structures without braces are encountered.This underreporting is minimized by examining each
case
individually.Case
s with unscoped control structures will be ignored by this sniff.Case
s within the sameswitch
without unscoped control structures will be handled correctly.The minimum PHPCS requirement in Composer has been adjusted to reflect this.
As PHPCS 2.3.0 was released over three years ago, I would expect this not to be an issue.
nightly
will fail.Fixes #686
As this issue will start breaking build for anyone running unit tests against PHP
nightly
, I've targeted the8.2.0
release for this sniff.