PHPCSStandards / PHP_CodeSniffer

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.
BSD 3-Clause "New" or "Revised" License
937 stars 56 forks source link

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

Closed jrfnl closed 2 months ago

jrfnl commented 3 months ago

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 https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/152 as this issue was discovered when creating an update for the fixer conflict list.

Types of changes

jrfnl commented 2 months ago

Rebased without changes. Merging once the build has passed.