Skip to content

Commit

Permalink
Merge branch 'feature/2512-squiz-nonexecutable-code-fix-alt-control-s…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Jun 26, 2019
2 parents f9dc6b4 + 19346c5 commit 0d6033d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Standards/Squiz/Sniffs/PHP/NonExecutableCodeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ public function process(File $phpcsFile, $stackPtr)
T_CASE,
T_DEFAULT,
T_CLOSE_CURLY_BRACKET,
T_ENDSWITCH,
],
($end + 1)
);
Expand Down
39 changes: 39 additions & 0 deletions src/Standards/Squiz/Tests/PHP/NonExecutableCodeUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,42 @@ switch ($var) {

end:
echo 'j hit 17';

// Issue 2512.
class TestAlternativeControlStructures {

public function alternative_switch_in_function( $var ) {

switch ( $var ) :
case 'value1':
do_something();
break;

default:
case 'value2':
do_something_else();
break;
endswitch;
}

public function various_alternative_control_structures() {
$_while = 1;

for ( $a = 0; $a++ < 1; ) :
foreach ( [ 1 ] as $b ) :
while ( $_while-- ) :
if ( 1 ) :
switch ( 1 ) :
default:
echo 'yay, we made it!';
break;
endswitch;
endif;
endwhile;
endforeach;
endfor;
}
}

$var_after_class_in_global_space = 1;
do_something_else();

0 comments on commit 0d6033d

Please sign in to comment.