Squiz/IncrementDecrementUsage: various bug fixes - whitespace/comment tolerance #329
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
As the Squiz/IncrementDecrementUsage sniff is looking for certain functional code patterns, the sniff should disregard whitespace and comments when looking for the relevant tokens to determine whether the code under scan contains the code pattern the sniff is looking for.
The sniff, however, does not do this correctly (in multiple places).
Squiz/IncrementDecrementUsage: bug fix - code without whitespace [1]
This commit fixes just one of these issues, as reported in #325.
For this particular issue, the
$startPtr
for thefindNext()
is incremented for eachwhile
loop, but the initial$startPtr
was also incremented, which meant that if there was no whitespace after an equals sign, the first relevant token was being skipped over.Fixed now.
Includes tests.
Squiz/IncrementDecrementUsage: bug fix - code without whitespace [2]
This commit fixes the same issue as fixed in the previous commit, but now specifically for the part in the code where it is checking that a
$var = $var + 1;
like statement only has one variable in the code comprising the value being assigned.Same as before, the
$startPtr
for thefindNext()
is incremented for eachwhile
loop, but the initial$startPtr
was also incremented, which meant that if there was no whitespace after an equals sign, the first relevant token was being skipped over.Fixed now.
Includes tests.
Squiz/IncrementDecrementUsage: bug fix - comments between variable and equal sign
This commit fixes another one of these issues.
In this case, if there was a comment between the
$var
and the subsequent equal sign, the sniff would incorrectly disregard the assignment as one which should be examined.Fixed now.
Includes tests.
Squiz/IncrementDecrementUsage: bug fix - comments in value being assigned
This commit fixes one more of these issues.
In this case, if there was a comment anywhere in the value being assigned, the sniff would incorrectly disregard the assignment as one which should be examined.
Fixed now.
Includes tests.
Suggested changelog entry
Related issues/external references
Fixes #325
Types of changes