Skip to content

Commit

Permalink
Had to make a special exception for braceless IF/ELSEIF/ELSE as fix f…
Browse files Browse the repository at this point in the history
…or bug #879 broke tokenizing for some case statements (bug #893)
  • Loading branch information
gsherwood committed Feb 15, 2016
1 parent 858934b commit 63c9e3a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
21 changes: 19 additions & 2 deletions CodeSniffer/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -2129,10 +2129,27 @@ private static function _recurseScopeMap(
if (PHP_CODESNIFFER_VERBOSITY > 1) {
$type = $tokens[$stackPtr]['type'];
echo str_repeat("\t", $depth);
echo "=> Found new opening condition before scope opener for $stackPtr:$type, bailing".PHP_EOL;
echo "=> Found new opening condition before scope opener for $stackPtr:$type, ";
}

return ($i - 1);
if (($tokens[$stackPtr]['code'] === T_IF
|| $tokens[$stackPtr]['code'] === T_ELSEIF
|| $tokens[$stackPtr]['code'] === T_ELSE)
&& ($tokens[$i]['code'] === T_ELSE
|| $tokens[$i]['code'] === T_ELSEIF)
) {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "continuing".PHP_EOL;
}

return ($i - 1);
} else {
if (PHP_CODESNIFFER_VERBOSITY > 1) {
echo "backtracking".PHP_EOL;
}

return $stackPtr;
}
}//end if

if (PHP_CODESNIFFER_VERBOSITY > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,17 @@ endif;
<li><?php echo $value ?></li>
<?php endforeach ?>
</ul>
<?php
switch ( $a ) {
case 'foo':
do {
$a = 'b';
} while ( $a );
return 5;

case 'bar':
foreach ( $a as $b ) {
$e = 'b';
}
return 5;
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,17 @@ endif;
<li><?php echo $value ?></li>
<?php endforeach ?>
</ul>
<?php
switch ( $a ) {
case 'foo':
do {
$a = 'b';
} while ( $a );
return 5;

case 'bar':
foreach ( $a as $b ) {
$e = 'b';
}
return 5;
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public function getErrorList()
98 => 1,
122 => 1,
127 => 1,
135 => 1,
141 => 1,
);

}//end getErrorList()
Expand Down

0 comments on commit 63c9e3a

Please sign in to comment.