-
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
3 changed files
with
24 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.2.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
// Intentional parse error. This has to be the last (and only) test in the file. | ||
// Live coding test. The sniff should stay silent. | ||
class ParseErrors { | ||
const A|(B PARSE_ERROR = null; | ||
} |
5 changes: 5 additions & 0 deletions
5
src/Standards/Squiz/Tests/Formatting/OperatorBracketUnitTest.3.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
// Intentional parse error. This has to be the last (and only) test in the file. | ||
// Live coding test. The sniff should stay silent. | ||
$a = [10, 20] + [ |