Skip to content

Conversation

@jrfnl
Copy link
Member

@jrfnl jrfnl commented Feb 7, 2024

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 the findNext() is incremented for each while 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 the findNext() is incremented for each while 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

  • Squiz.Operators.IncrementDecrementUsage : the sniff was underreporting when there was (no) whitespace and/or comments in unexpected places

Related issues/external references

Fixes #325

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

jrfnl added 4 commits February 8, 2024 12:27
As this is a sniff 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).

This commit fixes just one of these issues, as reported in 325.

For this particular issue, the `$startPtr` for the `findNext()` is incremented for each `while` 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.

Fixes 325
As this is a sniff 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).

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 the `findNext()` is incremented for each `while` 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.
…d equal sign

As this is a sniff 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).

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.
…gned

As this is a sniff 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).

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.
@jrfnl jrfnl force-pushed the feature/325-squiz-incrementdecrementusage-bugfix branch from 982e40a to 1643fb6 Compare February 8, 2024 11:27
@jrfnl
Copy link
Member Author

jrfnl commented Feb 8, 2024

Rebased without changes. Merging once the build passes.

Fix has been tested and been confirmed as working by the original reporter.

@jrfnl jrfnl merged commit 293b617 into master Feb 8, 2024
@jrfnl jrfnl deleted the feature/325-squiz-incrementdecrementusage-bugfix branch February 8, 2024 11:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Squiz.Operators.IncrementDecrementUsage.Found no longer works with missing spaces

2 participants