Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/Standards/Squiz/Sniffs/Arrays/ArrayDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@
class ArrayDeclarationSniff implements Sniff
{

/**
* Controls how to align the double arrow in multi-line arrays:
* - true: align the double arrow to the longest index
* - false: align the double arrow to length of the index
*
* @var boolean
*/
public bool $alignDoubleArrowToLongestIndex = true;


/**
* Returns an array of tokens this test wants to listen for.
Expand Down Expand Up @@ -823,7 +832,12 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
}
}//end if

$arrowStart = ($tokens[$indexPointer]['column'] + $maxLength + 1);
$arrowStart = ($tokens[$indexPointer]['column'] + $index['index_length'] + 1);

if ($this->alignDoubleArrowToLongestIndex === true) {
$arrowStart = ($tokens[$indexPointer]['column'] + $maxLength + 1);
}

if ($tokens[$index['arrow']]['column'] !== $arrowStart) {
$expected = ($arrowStart - ($index['index_length'] + $tokens[$indexPointer]['column']));
$found = ($tokens[$index['arrow']]['column'] - ($index['index_length'] + $tokens[$indexPointer]['column']));
Expand All @@ -847,11 +861,9 @@ public function processMultiLineArray($phpcsFile, $stackPtr, $arrayStart, $array
$phpcsFile->fixer->replaceToken(($index['arrow'] - 1), str_repeat(' ', $expected));
}
}

continue;
}//end if

$valueStart = ($arrowStart + 3);
$valueStart = ($tokens[$index['arrow']]['column'] + 3);
if ($tokens[$valuePointer]['column'] !== $valueStart) {
$expected = ($valueStart - ($tokens[$index['arrow']]['length'] + $tokens[$index['arrow']]['column']));
$found = ($tokens[$valuePointer]['column'] - ($tokens[$index['arrow']]['length'] + $tokens[$index['arrow']]['column']));
Expand Down
Loading