org.sonar.l10n.plsqlopen.rules.plsql.SameBranch.html Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of zpa-checks Show documentation
Show all versions of zpa-checks Show documentation
Z PL/SQL Analyzer :: Checks
The newest version!
Having two branches in the same if
structure with the same implementation is at best duplicate code,
and at worst a coding error. If the same logic is truly needed for both instances, then they should be combined.
Noncompliant Code Example
IF var BETWEEN 0 AND 10 THEN
do_the_thing();
ELSIF var BETWEEN 10 AND 20 THEN
do_the_thing(); -- Noncompliant; duplicates first condition
ELSIF var BETWEEN 20 AND 50 THEN
do_the_another_thing();
ELSE
do_the_rest()
END IF;
Compliant Solution
IF var BETWEEN 0 AND 10 THEN
do_the_thing();
ELSIF var BETWEEN 10 AND 20 THEN
do_the_second_thing();
ELSIF var BETWEEN 20 AND 50 THEN
do_the_another_thing();
ELSE
do_the_rest()
END IF;