rspec/rules/S1871/apex/compliant.adoc
2023-10-24 12:02:02 +00:00

35 lines
598 B
Plaintext

If the same logic is truly needed for both instances, then:
* in an `if` chain they should be combined
[source,apex,diff-id=1,diff-type=compliant]
----
if ((a >= 0 && a < 10) || (a >= 20 && a < 50)) {
doFirstThing();
doTheThing();
}
else if (a >= 10 && a < 20) {
doTheOtherThing();
}
else {
doTheRest();
}
----
* for a `switch`, the values should be put in the `when` values list.
[source,apex,diff-id=2,diff-type=compliant]
----
switch on i {
when 1, 3 {
doFirstThing();
doSomething();
}
when 2 {
doSomethingDifferent();
}
when else {
doTheRest();
}
}
----