-
Notifications
You must be signed in to change notification settings - Fork 10
General informations
Konafets edited this page Dec 23, 2014
·
3 revisions
This standard covers all switch declarations. The keywords Switch, Case and Default should be lowercase
| Valid: Lowercase keywords | Invalid: Keywords begins with a uppercase letter or are complete uppercase |
|
switch ($something) { case '1': $case = '1'; break; case '2': $case = '3'; break; default: $case = null; } |
Switch ($something) { CASE '1': $case = '1'; break; CASE '2': $case = '3'; break; Default: $case = null; } |
| Valid: Case statement is indent with one tab | Invalid: Case statement is indent with one space. Case statement is not indent at all or with two tabs. |
| switch ($something) { [tab]case '1': ... } |
switch ($something) { [space]case '1': ... } switch ($something) { case '1': ... } switch ($something) { [tab][tab]case '1': ... } |
| Valid: Case statement is followed by a single space | Invalid: No space after Case statement |
| switch ($something) { case '1': ... } |
switch ($something) { case'1': ... } |
| Valid: No space before the colon | Invalid: Space before the colon |
| switch ($something) { case '1': ... } |
switch ($something) { case '1' : ... } |
| Valid: The fall-through is explained with a comment | Invalid: No comment at the fall-through |
| switch ($something) { case '1': $case = '1'; break; case '2': $case = '3'; // Fall through the next case on purpose case '3': $case = '3'; break; default: $case = null; } |
switch ($something) { case '1': $case = '1'; break; case '2': $case = '3'; case '3': $case = '3'; break; default: $case = null; } |
| Valid: The default statement is the last in the switch and have no break statement. | Invalid: Default statement is not the last element and it contains a break. |
| switch ($something) { case '1': $case = '1'; break; default: $case = null; } |
switch ($something) { case '1': $case = '1'; break; default: $case = null; case '2': $case = '2'; break; } switch ($something) { case '1': $case = '1'; break; default: $case = null; break; } |
| Valid: The code is indent one more tab then case statement. | Invalid: The code is indent with spaces or with only one tab. |
| switch ($something) { [tab]case '1': [tab][tab]$case = '1'; ... } |
switch ($something) { [tab]case '1': [space][space]$case = '1'; ... } switch ($something) { [tab]case '1': [tab]$case = '1'; ... } switch ($something) { [tab]case '1': [tab][tab][tab]$case = '1'; ... } |
| Valid: The break statement is aligned to the code. | Invalid: The break statement is not aligned with the code. |
| switch ($something) { [tab]case '1': [tab][tab]$case = '1'; [tab][tab]break; ... } |
switch ($something) { [tab]case '1': [tab][tab]$case = '1'; [tab]break; ... } switch ($something) { [tab]case '1': [tab][tab]$case = '1'; [tab][tab][tab]break; ... } |
| Valid: No blank line before the break statement | Invalid: Blank line before the break statement |
| switch ($something) { case '1': $case = '1'; break; default: $case = null; } |
switch ($something) { case '1': $case = '1'; break; default: $case = null; } |
| Valid: Only one break statement per case | Invalid: Two case statements per case |
| switch ($something) { case '1': $case = '1'; break; ... } |
switch ($something) { case '1': $case = '1'; break; break; ... } |
| Valid: No blank line after the case statement | Invalid: Blank line after the case statement |
| switch ($something) { case '1': $case = '1'; break; default: $case = null; } |
switch ($something) { case '1': $case = '1'; break; default: $case = null; } |
| Valid: Switch with a default case | Invalid: Switch without a default case |
| switch ($something) { case '1': $case = '1'; break; default: $case = null; } |
switch ($something) { case '1': $case = '1'; break; } |
| Valid: Closing brace aligned with the switch keyword | Invalid: Closing brace not aligned with the switch keyword |
| switch ($something) { case '1': $case = '1'; break; default: $case = null; } |
switch ($something) { case '1': $case = '1'; break; default: $case = null; } |
| Valid: Switch contains at least one case statement | Invalid: Switch contains not case statement |
| switch ($something) { case '1': $case = '1'; break; default: $case = null; } switch ($something) { default: $case = null; } |
switch ($something) { } |
| Valid: The ternary conditional operator is not nested. | Invalid: The ternary conditional operator is nested. |
| $result = ($useComma ? ',' : '.'); | $result = ($useComma ? ',' : $useDot ? '.' : ';'); |
| Valid: String concatenation operator surrounded by space | Invalid: String concatenation operator is not surrounded by space |
| $content = 'Hello ' . 'world!'; | $content = 'Hello '. 'world!'; $content = 'Hello ' .'world!'; $content = 'Hello '.'world!'; |
| Valid: String concatenation operator surrounded by one space on every side | Invalid: String concatenation operator surrounded by multiple spaces |
| $content = 'Hello ' . 'world!'; | $content = 'Hello ' . 'world!'; $content = 'Hello ' . 'world!'; |
| Valid: Space before and after assignment operator. | Invalid: No space before and after the assignment operator. |
| $foo = $bar; | $foo=$bar; $foo= $bar; $foo =$bar; |
| Valid: Space before and after arithmetic-assignment. | Invalid: No space before and after the arithmetic-assignment. |
| $foo += $bar; $foo -= $bar; $foo *= $bar; $foo /= $bar; $foo %= $bar; $foo &= $bar; $foo .= $bar; $foo ^= $bar; |
$foo+=$bar; $foo-=$bar; $foo*=$bar; $foo/=$bar; $foo%=$bar; $foo&=$bar; $foo.=$bar; $foo^=$bar; |
| Valid: Space before and after comparison. | Invalid: No space before and after the comparison. |
| $foo = ($bar == $baz); $foo = ($bar === $baz); $foo = ($bar != $baz); $foo = ($bar !== $baz); $foo = ($bar < $baz); $foo = ($bar > $baz); $foo = ($bar <= $baz); $foo = ($bar >= $baz); |
$foo = ($bar==$baz); $foo = ($bar===$baz); $foo = ($bar!=$baz); $foo = ($bar!==$baz); $foo = ($bar<$baz); $foo = ($bar>$baz); $foo = ($bar<=$baz); $foo = ($bar>=$baz); |
| Valid: Space before and after arithmetic operator. | Invalid: No space before and after arithmetic operator. |
| $foo = 1 + 2; $foo = 1 - 2; $foo = 1 * 2; $foo = 1 / 2; $foo = 1 % 2; $foo = (1 + 2) * (5 % 3); |
$foo = 1+2; $foo = 1-2; $foo = 1*2; $foo = 1/2; $foo = 1%2; $foo = (1+2)*(5%3); |
| Valid: Space before and after double arrow operator. | Invalid: No space before and after double arrow operator. |
| $foo = array('foo' => 'bar'); | $foo = array('foo'=>'bar'); |
| Valid: No space after minus. | Invalid: Space after minus. |
| foo::bar($baz, -10); foo::bar(-10, $baz); $foo = $bar * -1; function foo($bar){ return -5; } |
foo::bar($baz, - 10); $foo = $bar * - 1; $foo = $bar *-1; function foo($bar){ return - 5; } function foo($bar){ return- 5; } |
| Valid: No space after minus. | |
| $foo = $bar; $foo += $bar; $foo -= $bar; $foo .= $bar; $foo &= $bar; $foo %= $bar; $foo *= $bar; $foo /= $bar; $foo = ($bar == $baz); $foo = ($bar === $baz); $foo = ($bar != $baz); $foo = ($bar !== $baz); $foo = ($bar < $baz); $foo = ($bar > $baz); $foo = ($bar <= $baz); $foo = ($bar >= $baz); $foo = 1 + 2; $foo = 1 - 2; $foo = 1 * 2; $foo = 1 / 2; $foo = 1 % 2; $foo = (1 + 2) * (5 % 3); $foo ^= $bar; $foo = array('foo' => 'bar'); |
| Valid: No space after prefix operator. | Invalid: Space after prefix operator. |
| $foo = ++$i; $foo = --$i; |
$foo = ++ $i; $foo = -- $i; |
| Valid: No space before postfix operator. | Invalid: Space before postfix operator. |
| $foo = $i++; $foo = $i--; |
$foo = $i ++; $foo = $i --; |
| Valid: The closing curly brace starts on a new line. | Invalid: The closing curly brace doesn't starts on a new line. |
| if ($test) { $var = 1; } function test2() { } |
if ($test) { $var = 1;} function test2() {} |
| Valid: Consistent indentation level for scope. | Invalid: The ending brace is indented further than the if statement. |
| if ($test) { $var = 1; } |
if ($test) { $var = 1; } |