50 lines
948 B
Plaintext
50 lines
948 B
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;
|
|
----
|