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

Squiz/OperatorBracket: prevent PHP notices during live coding #580

Merged

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jul 29, 2024

Description

Squiz/OperatorBracket: rename test case file

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

Squiz/OperatorBracket: prevent PHP notices during live coding

During live coding (or in the case of parse errors), the "end of the expression" cannot always be correctly determined. In such a case, the sniff should stay silent.

This wasn't always handled correctly so far and could lead to the following PHP notices:

Undefined array key "parenthesis_closer" in path/to/phpcs/src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php on line 357
Undefined array key "bracket_closer" in path/to/phpcs/src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php on line 362

This commit fixes these by adding some extra defensive coding and bowing out when an unclosed bracket set is encountered.

Includes tests.

Suggested changelog entry

Squiz.Formatting.OperatorBracket: 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.

These changes look good. I have verified locally that this unblocks the conflict checker.

.... to allow for adding additional test case files.
During live coding (or in the case of parse errors), the "end of the expression" cannot always be correctly determined. In such a case, the sniff should stay silent.

This wasn't always handled correctly so far and could lead to the following PHP notices:
```
Undefined array key "parenthesis_closer" in path/to/phpcs/src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php on line 357
Undefined array key "bracket_closer" in path/to/phpcs/src/Standards/Squiz/Sniffs/Formatting/OperatorBracketSniff.php on line 362
```

This commit fixes these by adding some extra defensive coding and bowing out when an unclosed bracket set is encountered.

Includes tests.
@jrfnl jrfnl force-pushed the feature/squiz-operatorbracket-fix-php-notice-live-coding branch from e667042 to 7a4c787 Compare August 1, 2024 20:36
@jrfnl
Copy link
Member Author

jrfnl commented Aug 1, 2024

Rebased without changes. Merging once the build has passed.

@jrfnl jrfnl merged commit d49ea71 into master Aug 1, 2024
48 checks passed
@jrfnl jrfnl deleted the feature/squiz-operatorbracket-fix-php-notice-live-coding branch August 1, 2024 21:08
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