Skip to content

Commit

Permalink
Fixed bug squizlabs#1681 : Huge arrays are super slow to scan with Sq…
Browse files Browse the repository at this point in the history
…uiz.Arrays.ArrayDeclaration sniff
  • Loading branch information
gsherwood committed Oct 5, 2017
1 parent 39f2600 commit 1eb9067
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #1656 : Using the --sniffs argument has a problem with case sensitivity
- Fixed bug #1657 : Uninitialized string offset: 0 when sniffing CSS
- Fixed bug #1669 : Temporary expression proceeded by curly brace is detected as function call
- Fixed bug #1681 : Huge arrays are super slow to scan with Squiz.Arrays.ArrayDeclaration sniff
</notes>
<contents>
<dir name="/">
Expand Down
10 changes: 7 additions & 3 deletions src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,14 @@ public function processSingleLineArray($phpcsFile, $stackPtr, $arrayStart, $arra
}//end while

if ($valueCount > 0) {
$conditionCheck = $phpcsFile->findPrevious(array(T_OPEN_PARENTHESIS, T_SEMICOLON), ($stackPtr - 1), null, false);
$nestedParenthesis = false;
if (isset($tokens[$stackPtr]['nested_parenthesis']) === true) {
$nested = $tokens[$stackPtr]['nested_parenthesis'];
$nestedParenthesis = array_pop($nested);
}

if ($conditionCheck === false
|| $tokens[$conditionCheck]['line'] !== $tokens[$stackPtr]['line']
if ($nestedParenthesis === false
|| $tokens[$nestedParenthesis]['line'] !== $tokens[$stackPtr]['line']
) {
$error = 'Array with multiple values cannot be declared on a single line';
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'SingleLineNotAllowed');
Expand Down

0 comments on commit 1eb9067

Please sign in to comment.