Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AbstractPatternSniff: prevent PHP notice #579

Merged
merged 2 commits into from
Aug 1, 2024

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 29, 2024

Description

Squiz/FunctionDeclaration: rename test case file

.... to allow for adding additional test case files.

AbstractPatternSniff: prevent PHP notice

In a live coding situation, the token triggering the pattern being looked for could be at or near the end of the file.
This could lead to a situation where the pattern could never match anyhow as there are not enough tokens left in the file to match against.

In this situation, the sniff could trigger the following PHP error:

Increment on type bool has no effect, this will change in the next major version of PHP in path/to/phpcs/src/Sniffs/AbstractPatternSniff.php on line 627

This commit prevents this error by bowing out early if there are not enough tokens in the file under scan to match the pattern.

Tested via the Squiz.Functions.FunctionDeclaration sniff via which this issue was discovered.

Suggested changelog entry

AbstractPatternSniff: bug fix for potential PHP notice during live coding

Related issues/external references

Loosely related to #152 as this issue was discovered when creating an update for the fixer conflict list.

Types of changes

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

Copy link
Member

@fredden fredden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change makes sense. I have verified locally that this allows the fixer conflict checker to run.

.... to allow for adding additional test case files.
In a live coding situation, the token triggering the pattern being looked for could be at or near the end of the file.
This could lead to a situation where the pattern could never match anyhow as there are not enough tokens left in the file to match against.

In this situation, the sniff could trigger the following PHP error:
```
Increment on type bool has no effect, this will change in the next major version of PHP in path/to/phpcs/src/Sniffs/AbstractPatternSniff.php on line 627
```

This commit prevents this error by bowing out early if there are not enough tokens in the file under scan to match the pattern.

Tested via the `Squiz.Functions.FunctionDeclaration` sniff via which this issue was discovered.
@jrfnl jrfnl force-pushed the feature/abstractpatternsniff-fix-bug branch from e536947 to 49b8494 Compare August 1, 2024 20:04
@jrfnl
Copy link
Member Author

jrfnl commented Aug 1, 2024

Rebased without changes. Merging once the build has passed.

@jrfnl jrfnl merged commit 2014d6f into master Aug 1, 2024
48 checks passed
@jrfnl jrfnl deleted the feature/abstractpatternsniff-fix-bug branch August 1, 2024 20:34
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.

2 participants