Switch Declarations

Case statements should be indented 4 spaces from the switch keyword. It should also be followed by a space. Colons in switch declarations should not be preceded by whitespace. Break statements should be indented 4 more spaces from the case statement. There must be a comment when falling through from one case into the next.

Valid: Case statement indented correctly.

switch ($foo) { <em> </em>case 'bar': break; }

Invalid: Case statement not indented 4 spaces.

switch ($foo) { <em></em>case 'bar': break; }

Valid: Case statement followed by 1 space.

switch ($foo) { case<em> </em>'bar': break; }

Invalid: Case statement not followed by 1 space.

switch ($foo) { case<em></em>'bar': break; }

Valid: Colons not prefixed by whitespace.

switch ($foo) { case 'bar'<em></em>: break; default<em></em>: break; }

Invalid: Colons prefixed by whitespace.

switch ($foo) { case 'bar'<em> </em>: break; default<em> </em>: break; }

Valid: Break statement indented correctly.

switch ($foo) { case 'bar': <em> </em>break; }

Invalid: Break statement not indented 4 spaces.

switch ($foo) { case 'bar': <em> </em>break; }

Valid: Comment marking intentional fall-through.

switch ($foo) { case 'bar': <em>// no break</em> default<em></em>: break; }

Invalid: No comment marking intentional fall-through.

switch ($foo) { case 'bar': default<em></em>: break; }