rspec/rules/S128/php/rule.adoc

78 lines
1.5 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2020-06-30 10:16:44 +02:00
include::../description.adoc[]
=== Noncompliant code example
2020-06-30 10:16:44 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2020-06-30 10:16:44 +02:00
----
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
2020-06-30 10:16:44 +02:00
2022-02-04 17:28:24 +01:00
[source,php]
2020-06-30 10:16:44 +02:00
----
switch ($myVariable) {
case 1:
foo();
break;
case 2:
do_something();
break;
default:
do_something_else();
break;
}
----
=== Exceptions
2020-06-30 10:16:44 +02:00
This rule is relaxed in following cases:
2021-02-02 15:02:10 +01:00
[source,php]
2020-06-30 10:16:44 +02:00
----
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[]