Skip to content

Commit

Permalink
Added missing autofix test file
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Nov 3, 2020
1 parent dbfd9e6 commit 75a0512
Show file tree
Hide file tree
Showing 2 changed files with 343 additions and 0 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
<file baseinstalldir="PHP/CodeSniffer" name="LowercaseDeclarationUnitTest.inc.fixed" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="LowercaseDeclarationUnitTest.php" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="SwitchDeclarationUnitTest.inc" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="SwitchDeclarationUnitTest.inc.fixed" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="SwitchDeclarationUnitTest.js" role="test" />
<file baseinstalldir="PHP/CodeSniffer" name="SwitchDeclarationUnitTest.php" role="test" />
</dir>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,342 @@
<?php

// Valid SWITCH statement.
switch ($something) {
case '1':
$case = '1';
break;

case '2':
case '3':
$case = '5';
break;

case '4':
$case = '4';
break;

default:
$case = null;
break;
}

// Alignment wrong.
switch ($something) {
case '1':
$case = '1';
return '1';

case '2':
case '3':
$case = '5';
break;

case '4':
$case = '4';
break;

default:
$case = null;
break;
}

// Closing brace wrong.
switch ($something) {
case '1':
$case = '1';
break;
}

// PEAR style.
switch ($something) {
case '1':
$case = '1';
break;

case '2':
case '3':
$case = '5';
break;

case '4':
$case = '4';
break;

default:
$case = null;
break;
}

// Valid, but missing BREAKS.
switch ($something) {
case '1':
$case = '1';

case '2':
case '3':
$case = '5';

case '4':
$case = '4';

default:
$case = null;
}

// Invalid, and missing BREAKS.
switch ($something) {
case '1':
$case = '1';

case '2':
case '3':
$case = '5';

case '4':
$case = '4';

default:
$case = null;
$something = 'hello';
$other = 'hi';
}

// Valid
switch ($condition) {
case 'string':
$varStr = 'test';

default:
// Ignore the default.
break;
}

// No default comment
switch ($condition) {
case 'string':
$varStr = 'test';

default:
break;
}

// Break problems
switch ($condition) {
case 'string':


$varStr = 'test';

break;

case 'bool':
$varStr = 'test';


break;

default:

$varStr = 'test';
break;

}

switch ($var) {
case 'one':
case 'two':
break;

case 'three':
// Nothing to do.
break;

case 'four':
echo $hi;
break;

default:
// No default.
break;
}

switch ($var) {
case 'one':
if ($blah) {
}

break;

default:
// No default.
break;
}

switch ($name) {
case "1":
switch ($name2) {
case "1":
return true;

break;

case "2":
return true;

break;

default:
// No default.
break;
}
break;

case "2":
switch ($name2) {
case "1":
return true;

break;

case "2":
return true;

break;

default:
// No default.
break;
}
break;
}

switch ($name) {
case "1":
switch ($name2) {
case "1":
return true;

default:
// No default.
break;
}
break;

default:
// No default.
break;
}

switch ($name2) {
default:
// No default.
break;
}

switch ($foo) {
case "1":
return true;

default:
if ($foo === FALSE) {
break(2);
}
break;
}

// Valid SWITCH statement.
switch ($something) {
case '1';
$case = '1';
return '1';

case '2';
case '3';
$case = '5';
return '2';

case '4';
$case = '4';
return '3';

default;
$case = null;
return '4';
}

switch ($something) {
case '1':
$case = '1';
break;

case '2':
throw new Exception('message');

default:
throw new Exception('message');
}

switch ($something) {
case '1';
echo 'one';
break;

default:
echo 'default';
exit;
}

switch ($foo) {
case '1':
return;

// comment
break;

}

// Correct Multi line breaking statement with return.
switch ($foo) {
case 1:
return array(
'whiz',
'bang',
);

case 2:
return helper_func(
'whiz',
'bang'
);

default:
throw new Exception();
}

switch ($foo) {
case 'bar':
throw new \Exception(
'bar'
);

default:
throw new \Exception(
'bar'
);
}

$foo = $foo ?
function () {
switch ($a) {
case 'a':
break;

case (preg_match('/foo/i', $foo) ? $a : $b):
echo 'really?'
break;

default:
break;
}
} :
null;

0 comments on commit 75a0512

Please sign in to comment.