Skip to content

Commit

Permalink
Generic/ScopeIndent: minor bug fix (undefined array index)
Browse files Browse the repository at this point in the history
While looking at issue 3362 in an attempt to debug it, binarykitten and me came across a `An error occurred during processing; checking has been aborted. The error message was: Undefined array key "" in /src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php on line 646 (Internal.Exception)` error notice.

While this will probably only occur in exceptional circumstances, it was caused by an operator precedence issue in the scope closer check condition.

Adding the extra parentheses fixes the operator precedence snafu and prevents the above error notice.

Note: this does not fix 3362, but still, is one less bug to worry about ;-)
  • Loading branch information
jrfnl committed May 21, 2021
1 parent 3d6ae7f commit 783d946
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Standards/Generic/Sniffs/WhiteSpace/ScopeIndentSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,11 +616,11 @@ public function process(File $phpcsFile, $stackPtr)

// Scope closers reset the required indent to the same level as the opening condition.
if (($checkToken !== null
&& isset($openScopes[$checkToken]) === true
&& (isset($openScopes[$checkToken]) === true
|| (isset($tokens[$checkToken]['scope_condition']) === true
&& isset($tokens[$checkToken]['scope_closer']) === true
&& $tokens[$checkToken]['scope_closer'] === $checkToken
&& $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['scope_opener']]['line']))
&& $tokens[$checkToken]['line'] !== $tokens[$tokens[$checkToken]['scope_opener']]['line'])))
|| ($checkToken === null
&& isset($openScopes[$i]) === true)
) {
Expand Down

0 comments on commit 783d946

Please sign in to comment.