Skip to content

Commit

Permalink
Lines without assignments were causing problems when in the middle of…
Browse files Browse the repository at this point in the history
… assignment blocks
  • Loading branch information
gsherwood committed Jan 20, 2014
1 parent 0f7d9dc commit 579d39c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public function checkAlignment(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$maxPadding = null;
$stopped = null;
$lastCode = $stackPtr;
$lastSemi = null;

$find = array_diff(PHP_CodeSniffer_Tokens::$assignmentTokens, array(T_DOUBLE_ARROW));
for ($assign = $stackPtr; $assign < $phpcsFile->numTokens; $assign++) {
Expand All @@ -129,10 +130,24 @@ public function checkAlignment(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}

$lastCode = $assign;
}

if ($tokens[$assign]['code'] === T_SEMICOLON) {
if ($tokens[$assign]['conditions'] === $tokens[$stackPtr]['conditions']) {
if ($lastSemi !== null && $prevAssign !== null && $lastSemi > $prevAssign) {
// This statement did not have an assignment operator in it.
break;
} else {
$lastSemi = $assign;
}
} else {
// Statement is in a different context, so the block is over.
break;
}
}
}//end if

continue;
}
}//end if

if ($assign !== $stackPtr) {
// Has to be nested inside the same conditions as the first assignment.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,8 @@ $varonetwothree = 'three';
$varonetwothreefour = 'four';

// @codingStandardsChangeSetting Generic.Formatting.MultipleStatementAlignment maxPadding 1000

$filterQuery = SquizRoadmap::getSearchQueryFilter($searchParams);
Channels::addToBasket('itemid', $filterQuery);
$query = DAL::getDALQuery('SquizRoadmapItem', 'getItemIds');
$results = DAL::getAssoc($query, 0);

0 comments on commit 579d39c

Please sign in to comment.