CyclomaticComplexity
Since: PMD 5.1
Priority: Medium (3)
Complexity directly affects maintenance costs is determined by the number of decision points in a method plus one for the method entry. The decision points include ‘if’, ‘while’, ‘for’, and ‘case labels’ calls. Generally, numbers ranging from 1-4 denote low complexity, 5-7 denote moderate complexity, 8-10 denote high complexity, and 11+ is very high complexity.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.plsql.rule.design.CyclomaticComplexityRule
Example(s):
-- Cyclomatic Complexity of 25
CREATE OR REPLACE PACKAGE BODY pkg_pmd_working_sequence AS
1 PROCEDURE ty_logger IS BEGIN
2 IF true
THEN
DBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);
3 IF true
THEN
DBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);
4 IF true
THEN
DBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);
5 ELSIF false
THEN
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
ELSE
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
END IF;
6 ELSIF false
THEN
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
7 IF true
THEN
DBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);
8 ELSIF false
THEN
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
ELSE
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
9 IF true
THEN
DBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);
10 ELSIF false
THEN
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
ELSE
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
END IF;
END IF;
11 ELSIF false
THEN
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
12 IF true
THEN
DBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);
13 IF true
THEN
DBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);
14 ELSIF false
THEN
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
ELSE
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
END IF;
15 ELSIF false
THEN
16 IF true
THEN
DBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);
17 ELSIF false
THEN
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
ELSE
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
END IF;
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
ELSE
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
18 IF true
THEN
DBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);
19 IF true
THEN
DBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);
20 ELSIF false
THEN
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
ELSE
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
END IF;
21 ELSIF false
THEN
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
22 IF true
THEN
DBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);
23 ELSIF false
THEN
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
ELSE
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
END IF;
ELSE
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
24 IF true
THEN
DBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);
25 ELSIF false
THEN
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
ELSE
DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);
END IF;
END IF;
END IF;
END;
END;
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
showMethodsComplexity | true | Add method average violations to the report | no |
showClassesComplexity | true | Add class average violations to the report | no |
reportLevel | 10 | Cyclomatic Complexity reporting threshold | no |
Use this rule with the default properties by just referencing it:
<rule ref="category/plsql/design.xml/CyclomaticComplexity" />
Use this rule and customize it:
<rule ref="category/plsql/design.xml/CyclomaticComplexity">
<properties>
<property name="showMethodsComplexity" value="true" />
<property name="showClassesComplexity" value="true" />
<property name="reportLevel" value="10" />
</properties>
</rule>
ExcessiveMethodLength
Since: PMD 5.1
Priority: Medium (3)
When methods are excessively long this usually indicates that the method is doing more than its name/signature might suggest. They also become challenging for others to digest since excessive scrolling causes readers to lose focus. Try to reduce the method length by creating helper methods and removing any copy/pasted code.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.plsql.rule.design.ExcessiveMethodLengthRule
Example(s):
CREATE OR REPLACE
PROCEDURE doSomething BEGIN
DBMS_OUTPUT.PUT_LINE("Hello world!");
DBMS_OUTPUT.PUT_LINE("Hello world!");
-- 98 copies omitted for brevity.
END;
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
topscore | Deprecated Top score value | no | |
minimum | 100.0 | Minimum reporting threshold | no |
sigma | Deprecated Sigma value | no |
Use this rule with the default properties by just referencing it:
<rule ref="category/plsql/design.xml/ExcessiveMethodLength" />
Use this rule and customize it:
<rule ref="category/plsql/design.xml/ExcessiveMethodLength">
<properties>
<property name="minimum" value="100.0" />
</properties>
</rule>
ExcessiveObjectLength
Since: PMD 5.1
Priority: Medium (3)
Excessive object line lengths are usually indications that the object may be burdened with excessive responsibilities that could be provided by other objects. In breaking these methods apart the code becomes more managable and ripe for reuse.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.plsql.rule.design.ExcessiveObjectLengthRule
Example(s):
CREATE OR REPLACE
PACKAGE BODY Foo AS
PROCEDURE bar1 IS BEGIN
-- 1000 lines of code
END bar1;
PROCEDURE bar2 IS BEGIN
-- 1000 lines of code
END bar2;
PROCEDURE bar3 IS BEGIN
-- 1000 lines of code
END bar3;
PROCEDURE barN IS BEGIN
-- 1000 lines of code
END barn;
END;
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
topscore | Deprecated Top score value | no | |
minimum | 1000.0 | Minimum reporting threshold | no |
sigma | Deprecated Sigma value | no |
Use this rule with the default properties by just referencing it:
<rule ref="category/plsql/design.xml/ExcessiveObjectLength" />
Use this rule and customize it:
<rule ref="category/plsql/design.xml/ExcessiveObjectLength">
<properties>
<property name="minimum" value="1000.0" />
</properties>
</rule>
ExcessivePackageBodyLength
Since: PMD 5.1
Priority: Medium (3)
Excessive class file lengths are usually indications that the class may be burdened with excessive responsibilities that could be provided by external classes or functions. In breaking these methods apart the code becomes more managable and ripe for reuse.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.plsql.rule.design.ExcessivePackageBodyLengthRule
Example(s):
CREATE OR REPLACE
PACKAGE BODY Foo AS
PROCEDURE bar1 IS BEGIN
-- 1000 lines of code
END bar1;
PROCEDURE bar2 IS BEGIN
-- 1000 lines of code
END bar2;
PROCEDURE bar3 IS BEGIN
-- 1000 lines of code
END bar3;
PROCEDURE barN IS BEGIN
-- 1000 lines of code
END barn;
END;
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
topscore | Deprecated Top score value | no | |
minimum | 1000.0 | Minimum reporting threshold | no |
sigma | Deprecated Sigma value | no |
Use this rule with the default properties by just referencing it:
<rule ref="category/plsql/design.xml/ExcessivePackageBodyLength" />
Use this rule and customize it:
<rule ref="category/plsql/design.xml/ExcessivePackageBodyLength">
<properties>
<property name="minimum" value="1000.0" />
</properties>
</rule>
ExcessivePackageSpecificationLength
Since: PMD 5.1
Priority: Medium (3)
Excessive class file lengths are usually indications that the class may be burdened with excessive responsibilities that could be provided by external classes or functions. In breaking these methods apart the code becomes more managable and ripe for reuse.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.plsql.rule.design.ExcessivePackageSpecificationLengthRule
Example(s):
CREATE OR REPLACE
PACKAGE Foo AS
PROCEDURE bar1;
PROCEDURE bar2;
PROCEDURE bar3;
...
PROCEDURE barN;
END;
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
topscore | Deprecated Top score value | no | |
minimum | 1000.0 | Minimum reporting threshold | no |
sigma | Deprecated Sigma value | no |
Use this rule with the default properties by just referencing it:
<rule ref="category/plsql/design.xml/ExcessivePackageSpecificationLength" />
Use this rule and customize it:
<rule ref="category/plsql/design.xml/ExcessivePackageSpecificationLength">
<properties>
<property name="minimum" value="1000.0" />
</properties>
</rule>
ExcessiveParameterList
Since: PMD 5.1
Priority: Medium (3)
Methods with numerous parameters are a challenge to maintain, especially if most of them share the same datatype. These situations usually denote the need for new objects to wrap the numerous parameters.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.plsql.rule.design.ExcessiveParameterListRule
Example(s):
CREATE OR REPLACE
PROCEDURE addPerson( -- too many arguments liable to be mixed up
birthYear pls_integer, birthMonth pls_integer, birthDate pls_integer, height pls_integer, weight pls_integer, ssn pls_integer) {
. . . .
END ADDPERSON;
CREATE OR REPLACE
PROCEDURE addPerson( -- preferred approach
birthdate DATE, measurements BodyMeasurements , ssn INTEGER) BEGIN
. . . .
END;
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
topscore | Deprecated Top score value | no | |
minimum | 10.0 | Minimum reporting threshold | no |
sigma | Deprecated Sigma value | no |
Use this rule with the default properties by just referencing it:
<rule ref="category/plsql/design.xml/ExcessiveParameterList" />
Use this rule and customize it:
<rule ref="category/plsql/design.xml/ExcessiveParameterList">
<properties>
<property name="minimum" value="10.0" />
</properties>
</rule>
ExcessiveTypeLength
Since: PMD 5.1
Priority: Medium (3)
Excessive class file lengths are usually indications that the class may be burdened with excessive responsibilities that could be provided by external classes or functions. In breaking these methods apart the code becomes more managable and ripe for reuse.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.plsql.rule.design.ExcessiveTypeLengthRule
Example(s):
CREATE OR REPLACE
TYPE BODY Foo AS
MEMBER PROCEDURE bar1 IS BEGIN
-- 1000 lines of code
END bar1;
MEMBER PROCEDURE bar2 IS BEGIN
-- 1000 lines of code
END bar2;
MEMBER PROCEDURE bar3 IS BEGIN
-- 1000 lines of code
END bar3;
MEMBER PROCEDURE barN IS BEGIN
-- 1000 lines of code
END barn;
END;
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
topscore | Deprecated Top score value | no | |
minimum | 1000.0 | Minimum reporting threshold | no |
sigma | Deprecated Sigma value | no |
Use this rule with the default properties by just referencing it:
<rule ref="category/plsql/design.xml/ExcessiveTypeLength" />
Use this rule and customize it:
<rule ref="category/plsql/design.xml/ExcessiveTypeLength">
<properties>
<property name="minimum" value="1000.0" />
</properties>
</rule>
NcssMethodCount
Since: PMD 5.1
Priority: Medium (3)
This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of lines of code for a given method. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.plsql.rule.design.NcssMethodCountRule
Example(s):
CREATE OR REPLACE PACKAGE BODY AS
FUNCTION methd RETURN INTEGER IS
BEGIN
RETURN 1;;
END;
END;
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
topscore | Deprecated Top score value | no | |
minimum | 100.0 | Minimum reporting threshold | no |
sigma | Deprecated Sigma value | no |
Use this rule with the default properties by just referencing it:
<rule ref="category/plsql/design.xml/NcssMethodCount" />
Use this rule and customize it:
<rule ref="category/plsql/design.xml/NcssMethodCount">
<properties>
<property name="minimum" value="100.0" />
</properties>
</rule>
NcssObjectCount
Since: PMD 5.1
Priority: Medium (3)
This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of lines of code for a given Oracle object. NCSS ignores comments, and counts actual statements. Using this algorithm, lines of code that are split are counted as one.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.plsql.rule.design.NcssObjectCountRule
Example(s):
CREATE OR REPLACE PACKAGE pkg_
PROCEDURE Foo IS
BEGIN
--this class only has 6 NCSS lines
super();
super();
END;
}
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
topscore | Deprecated Top score value | no | |
minimum | 1500.0 | Minimum reporting threshold | no |
sigma | Deprecated Sigma value | no |
Use this rule with the default properties by just referencing it:
<rule ref="category/plsql/design.xml/NcssObjectCount" />
Use this rule and customize it:
<rule ref="category/plsql/design.xml/NcssObjectCount">
<properties>
<property name="minimum" value="1500.0" />
</properties>
</rule>
NPathComplexity
Since: PMD 5.1
Priority: Medium (3)
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity and increase readability.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.plsql.rule.design.NPathComplexityRule
Example(s):
CREATE OR REPLACE
PROCEDURE bar AS BEGIN -- this is something more complex than it needs to be,
if (y) THEN -- it should be broken down into smaller methods or functions
for j IN 0 .. j-1 LOOP
if (j > r) THEN
doSomething;
while (f < 5 ) LOOP
anotherThing;
f := f - 27;
END LOOP;
else
tryThis();
END IF;
END LOOP;
END IF;
if ( r - n > 45) THEN
while (doMagic) LOOP
findRabbits;
END LOOP;
END IF;
BEGIN
doSomethingDangerous();
EXCEPTION WHEN FooException THEN
makeAmends;
BEGIN
dontDoItAgain;
EXCEPTION
WHEN OTHERS THEN
log_problem;
END;
END;
END;
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
topscore | Deprecated Top score value | no | |
minimum | 200.0 | Minimum reporting threshold | no |
sigma | Deprecated Sigma value | no |
Use this rule with the default properties by just referencing it:
<rule ref="category/plsql/design.xml/NPathComplexity" />
Use this rule and customize it:
<rule ref="category/plsql/design.xml/NPathComplexity">
<properties>
<property name="minimum" value="200.0" />
</properties>
</rule>
TooManyFields
Since: PMD 5.1
Priority: Medium (3)
Classes that have too many fields can become unwieldy and could be redesigned to have fewer fields, possibly through grouping related fields in new objects. For example, a class with individual city/state/zip fields could park them within a single Address field.
This rule is defined by the following Java class: net.sourceforge.pmd.lang.plsql.rule.design.TooManyFieldsRule
Example(s):
CREATE OR REPLACE PACKAGE pkg_too_many_fields AS
C_CHAR_A CONSTANT CHAR(1 CHAR) := 'A';
C_CHAR_B CONSTANT CHAR(1 CHAR) := 'B';
...
C_CHAR_Z CONSTANT CHAR(1 CHAR) := 'Z';
END pkg_too_many_fields;
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
maxfields | 15 | Max allowable fields | no |
Use this rule with the default properties by just referencing it:
<rule ref="category/plsql/design.xml/TooManyFields" />
Use this rule and customize it:
<rule ref="category/plsql/design.xml/TooManyFields">
<properties>
<property name="maxfields" value="15" />
</properties>
</rule>
TooManyMethods
Since: PMD 5.1
Priority: Medium (3)
A package or type with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
This rule is defined by the following XPath expression:
//node()
[ (
local-name(.) = 'PackageSpecification'
or
local-name(.) = 'TypeSpecification'
)
and
(
count(/descendant::ProgramUnit[
not (
starts-with(@Name,'get')
or
starts-with(@Name,'set')
or
starts-with(@Name,'is')
)
]
)
+
count(/descendant::TypeMethod[
not (
starts-with(@Name,'get')
or
starts-with(@Name,'set')
or
starts-with(@Name,'is')
)
]
)
) > $maxmethods
]
This rule has the following properties:
Name | Default Value | Description | Multivalued |
---|---|---|---|
maxmethods | 1 | The method count reporting threshold | no |
Use this rule with the default properties by just referencing it:
<rule ref="category/plsql/design.xml/TooManyMethods" />
Use this rule and customize it:
<rule ref="category/plsql/design.xml/TooManyMethods">
<properties>
<property name="maxmethods" value="1" />
</properties>
</rule>