rspec/rules/S128/php/rule.adoc
Fred Tingaud 51369b610e
Make sure that includes are always surrounded by empty lines (#2270)
When an include is not surrounded by empty lines, its content is inlined
on the same line as the adjacent content. That can lead to broken tags
and other display issues.
This PR fixes all such includes and introduces a validation step that
forbids introducing the same problem again.
2023-06-22 10:38:01 +02:00

79 lines
1.5 KiB
Plaintext

== Why is this an issue?
include::../description.adoc[]
=== Noncompliant code example
[source,php]
----
switch ($myVariable) {
case 1:
foo();
break;
case 2: // Both 'doSomething()' and 'doSomethingElse()' will be executed. Is it on purpose ?
do_something();
default:
do_something_else();
break;
}
----
=== Compliant solution
[source,php]
----
switch ($myVariable) {
case 1:
foo();
break;
case 2:
do_something();
break;
default:
do_something_else();
break;
}
----
=== Exceptions
This rule is relaxed in following cases:
[source,php]
----
switch ($myVariable) {
case 0: // Empty case used to specify the same behavior for a group of cases.
case 1:
do_something();
break;
case 2: // Use of continue statement
continue;
case 3: // Case includes a jump statement (exit, return, break &etc)
exit(0);
case 4:
echo 'Second case, which falls through';
// no break <- comment is used when fall-through is intentional in a non-empty case body
default: // For the last case, use of break statement is optional
doSomethingElse();
}
----
include::../see.adoc[]
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
include::../message.adoc[]
'''
== Comments And Links
(visible only on this page)
include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]