-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug #723 : ScopeIndent can fail when multiple array closers are…
… on the same line
- Loading branch information
Showing
7 changed files
with
104 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -226,16 +226,26 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | |
|
||
// Closing parenthesis should just be indented to at least | ||
// the same level as where they were opened (but can be more). | ||
if ($checkToken !== null | ||
if (($checkToken !== null | ||
&& $tokens[$checkToken]['code'] === T_CLOSE_PARENTHESIS | ||
&& isset($tokens[$checkToken]['parenthesis_opener']) === true | ||
&& isset($tokens[$checkToken]['parenthesis_opener']) === true) | ||
|| ($tokens[$i]['code'] === T_CLOSE_PARENTHESIS | ||
&& isset($tokens[$i]['parenthesis_opener']) === true | ||
&& isset($tokens[$i]['parenthesis_owner']) === true | ||
&& $tokens[$tokens[$i]['parenthesis_owner']]['code'] === T_ARRAY) | ||
) { | ||
if ($checkToken !== null) { | ||
$parenCloser = $checkToken; | ||
} else { | ||
$parenCloser = $i; | ||
} | ||
|
||
if ($this->_debug === true) { | ||
$line = $tokens[$i]['line']; | ||
echo "Closing parenthesis found on line $line".PHP_EOL; | ||
} | ||
|
||
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$checkToken]['parenthesis_opener'], true); | ||
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$parenCloser]['parenthesis_opener'], true); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
gsherwood
Author
Member
|
||
$checkIndent = ($tokens[$first]['column'] - 1); | ||
if (isset($adjustments[$first]) === true) { | ||
$checkIndent += $adjustments[$first]; | ||
|
@@ -249,7 +259,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | |
echo "\t* first token on line $line is $type *".PHP_EOL; | ||
} | ||
|
||
if ($first === $tokens[$checkToken]['parenthesis_opener']) { | ||
if ($first === $tokens[$parenCloser]['parenthesis_opener']) { | ||
// This is unlikely to be the start of the statement, so look | ||
// back further to find it. | ||
$first--; | ||
|
@@ -288,15 +298,22 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | |
|
||
// Closing short array bracket should just be indented to at least | ||
// the same level as where it was opened (but can be more). | ||
if ($checkToken !== null | ||
&& $tokens[$checkToken]['code'] === T_CLOSE_SHORT_ARRAY | ||
if ($tokens[$i]['code'] === T_CLOSE_SHORT_ARRAY | ||
|| ($checkToken !== null | ||
&& $tokens[$checkToken]['code'] === T_CLOSE_SHORT_ARRAY) | ||
) { | ||
if ($checkToken !== null) { | ||
$arrayCloser = $checkToken; | ||
} else { | ||
$arrayCloser = $i; | ||
} | ||
|
||
if ($this->_debug === true) { | ||
$line = $tokens[$i]['line']; | ||
$line = $tokens[$arrayCloser]['line']; | ||
echo "Closing short array bracket found on line $line".PHP_EOL; | ||
} | ||
|
||
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$checkToken]['bracket_opener'], true); | ||
$first = $phpcsFile->findFirstOnLine(T_WHITESPACE, $tokens[$arrayCloser]['bracket_opener'], true); | ||
$checkIndent = ($tokens[$first]['column'] - 1); | ||
if (isset($adjustments[$first]) === true) { | ||
$checkIndent += $adjustments[$first]; | ||
|
@@ -310,7 +327,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) | |
echo "\t* first token on line $line is $type *".PHP_EOL; | ||
} | ||
|
||
if ($first === $tokens[$checkToken]['bracket_opener']) { | ||
if ($first === $tokens[$arrayCloser]['bracket_opener']) { | ||
// This is unlikely to be the start of the statement, so look | ||
// back further to find it. | ||
$first--; | ||
|
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
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
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
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
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
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
The
t
letter is missing in$parenCloser
variable name. I guess it should be named$parentCloser
instead.