59 lines
1.1 KiB
Plaintext
59 lines
1.1 KiB
Plaintext
Having all branches in a ``++CASE++`` or ``++IF++``/``++ELSIF++`` chain with the same implementation is an error. Either a copy-paste error was made and something different should be executed, or there shouldn't be a ``++CASE++``/``++IF++``/``++ELSIF++`` chain at all.
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
IF param = 1 THEN
|
|
result := 'A';
|
|
ELSIF param = 2 THEN
|
|
result := 'A';
|
|
ELSE
|
|
result := 'A';
|
|
END IF;
|
|
|
|
result := CASE param
|
|
WHEN 1 THEN 'A'
|
|
WHEN 2 THEN 'A'
|
|
ELSE 'A'
|
|
END;
|
|
----
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
IF param = 1 THEN
|
|
result := 'A';
|
|
ELSIF param = 2 THEN
|
|
result := 'B';
|
|
ELSE
|
|
result := 'C';
|
|
END IF;
|
|
|
|
result := CASE param
|
|
WHEN 1 THEN 'A'
|
|
WHEN 2 THEN 'B'
|
|
ELSE 'C'
|
|
END;
|
|
----
|
|
|
|
== Exceptions
|
|
|
|
This rule does not apply to ``++IF++``/``++CASE++`` chains without ``++ELSE++`` clauses.
|
|
|
|
|
|
----
|
|
IF param = 1 THEN -- no issue, this could have been done on purpose to make the code more readable
|
|
result := 'A';
|
|
ELSIF param = 2 THEN
|
|
result := 'A';
|
|
END IF;
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
'''
|
|
== Comments And Links
|
|
(visible only on this page)
|
|
|
|
include::../comments-and-links.adoc[]
|
|
endif::env-github,rspecator-view[]
|