Since: PMD 5.1
Priority: Medium (3)
Complexity directly affects maintenance costs is determined by the number of decision points in a methodplus 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 denotehigh 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 25CREATEORREPLACEPACKAGEBODYpkg_pmd_working_sequenceAS1PROCEDUREty_loggerISBEGIN2IFtrueTHENDBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);3IFtrueTHENDBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);4IFtrueTHENDBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);5ELSIFfalseTHENDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ELSEDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ENDIF;6ELSIFfalseTHENDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);7IFtrueTHENDBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);8ELSIFfalseTHENDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ELSEDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ENDIF;ELSEDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);9IFtrueTHENDBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);10ELSIFfalseTHENDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ELSEDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ENDIF;ENDIF;11ELSIFfalseTHENDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);12IFtrueTHENDBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);13IFtrueTHENDBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);14ELSIFfalseTHENDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ELSEDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ENDIF;15ELSIFfalseTHEN16IFtrueTHENDBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);17ELSIFfalseTHENDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ELSEDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ENDIF;DBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ELSEDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ENDIF;ELSEDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);18IFtrueTHENDBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);19IFtrueTHENDBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);20ELSIFfalseTHENDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ELSEDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ENDIF;21ELSIFfalseTHENDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);22IFtrueTHENDBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);23ELSIFfalseTHENDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ELSEDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ENDIF;ELSEDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);24IFtrueTHENDBMS_OUTPUT.PUT_LINE('IF/THEN l_Integer='||l_integer);25ELSIFfalseTHENDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ELSEDBMS_OUTPUT.PUT_LINE('ELSIF l_Integer='||l_integer);ENDIF;ENDIF;ENDIF;END;END;This rule has the following properties:
| Name | Default Value | Description |
|---|---|---|
| reportLevel | 10 | Cyclomatic Complexity reporting threshold |
| showClassesComplexity | true | Add class average violations to the report |
| showMethodsComplexity | true | Add method average violations to the report |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/CyclomaticComplexity"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/CyclomaticComplexity"><properties><propertyname="reportLevel"value="10"/><propertyname="showClassesComplexity"value="true"/><propertyname="showMethodsComplexity"value="true"/></properties></rule>Deprecated
Since: PMD 5.1
Priority: Medium (3)
When methods are excessively long this usually indicates that the method is doing more than itsname/signature might suggest. They also become challenging for others to digest since excessivescrolling causes readers to lose focus.Try to reduce the method length by creating helper methods and removing any copy/pasted code.
Deprecated: This rule is deprecated since PMD 7.19.0 and will be removed with PMD 8.0.0. UseNcssCount to find big methods.
This rule is defined by the following Java class:net.sourceforge.pmd.lang.plsql.rule.design.ExcessiveMethodLengthRule
Example(s):
CREATEORREPLACEPROCEDUREdoSomethingBEGINDBMS_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 |
|---|---|---|
| minimum | 100 | Threshold at or above which a node is reported |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/ExcessiveMethodLength"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/ExcessiveMethodLength"><properties><propertyname="minimum"value="100"/></properties></rule>Deprecated
Since: PMD 5.1
Priority: Medium (3)
Excessive object line lengths are usually indications that the object may be burdened with excessiveresponsibilities that could be provided by other objects. In breaking these methodsapart the code becomes more manageable and ripe for reuse.
Deprecated: This rule is deprecated since PMD 7.19.0 and will be removed with PMD 8.0.0. UseNcssCount to find big objects.
This rule is defined by the following Java class:net.sourceforge.pmd.lang.plsql.rule.design.ExcessiveObjectLengthRule
Example(s):
CREATEORREPLACEPACKAGEBODYFooASPROCEDUREbar1ISBEGIN-- 1000 lines of codeENDbar1;PROCEDUREbar2ISBEGIN-- 1000 lines of codeENDbar2;PROCEDUREbar3ISBEGIN-- 1000 lines of codeENDbar3;PROCEDUREbarNISBEGIN-- 1000 lines of codeENDbarn;END;This rule has the following properties:
| Name | Default Value | Description |
|---|---|---|
| minimum | 1000 | Threshold at or above which a node is reported |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/ExcessiveObjectLength"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/ExcessiveObjectLength"><properties><propertyname="minimum"value="1000"/></properties></rule>Deprecated
Since: PMD 5.1
Priority: Medium (3)
Excessive class file lengths are usually indications that the class may be burdened with excessiveresponsibilities that could be provided by external classes or functions. In breaking these methodsapart the code becomes more manageable and ripe for reuse.
Deprecated: This rule is deprecated since PMD 7.19.0 and will be removed with PMD 8.0.0. UseNcssCount to find big objects.
This rule is defined by the following Java class:net.sourceforge.pmd.lang.plsql.rule.design.ExcessivePackageBodyLengthRule
Example(s):
CREATEORREPLACEPACKAGEBODYFooASPROCEDUREbar1ISBEGIN-- 1000 lines of codeENDbar1;PROCEDUREbar2ISBEGIN-- 1000 lines of codeENDbar2;PROCEDUREbar3ISBEGIN-- 1000 lines of codeENDbar3;PROCEDUREbarNISBEGIN-- 1000 lines of codeENDbarn;END;This rule has the following properties:
| Name | Default Value | Description |
|---|---|---|
| minimum | 1000 | Threshold at or above which a node is reported |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/ExcessivePackageBodyLength"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/ExcessivePackageBodyLength"><properties><propertyname="minimum"value="1000"/></properties></rule>Deprecated
Since: PMD 5.1
Priority: Medium (3)
Excessive class file lengths are usually indications that the class may be burdened with excessiveresponsibilities that could be provided by external classes or functions. In breaking these methodsapart the code becomes more manageable and ripe for reuse.
Deprecated: This rule is deprecated since PMD 7.19.0 and will be removed with PMD 8.0.0. UseNcssCount to find big objects.
This rule is defined by the following Java class:net.sourceforge.pmd.lang.plsql.rule.design.ExcessivePackageSpecificationLengthRule
Example(s):
CREATEORREPLACEPACKAGEFooASPROCEDUREbar1;PROCEDUREbar2;PROCEDUREbar3;...PROCEDUREbarN;END;This rule has the following properties:
| Name | Default Value | Description |
|---|---|---|
| minimum | 1000 | Threshold at or above which a node is reported |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/ExcessivePackageSpecificationLength"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/ExcessivePackageSpecificationLength"><properties><propertyname="minimum"value="1000"/></properties></rule>Since: PMD 5.1
Priority: Medium (3)
Methods with numerous parameters are a challenge to maintain, especially if most of them share thesame 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):
CREATEORREPLACEPROCEDUREaddPerson(-- too many arguments liable to be mixed upbirthYearpls_integer,birthMonthpls_integer,birthDatepls_integer,heightpls_integer,weightpls_integer,ssnpls_integer){....ENDADDPERSON;CREATEORREPLACEPROCEDUREaddPerson(-- preferred approachbirthdateDATE,measurementsBodyMeasurements,ssnINTEGER)BEGIN....END;This rule has the following properties:
| Name | Default Value | Description |
|---|---|---|
| minimum | 10 | Threshold at or above which a node is reported |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/ExcessiveParameterList"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/ExcessiveParameterList"><properties><propertyname="minimum"value="10"/></properties></rule>Deprecated
Since: PMD 5.1
Priority: Medium (3)
Excessive class file lengths are usually indications that the class may be burdened with excessiveresponsibilities that could be provided by external classes or functions. In breaking these methodsapart the code becomes more manageable and ripe for reuse.
Deprecated: This rule is deprecated since PMD 7.19.0 and will be removed with PMD 8.0.0. UseNcssCount to find big objects.
This rule is defined by the following Java class:net.sourceforge.pmd.lang.plsql.rule.design.ExcessiveTypeLengthRule
Example(s):
CREATEORREPLACETYPEBODYFooASMEMBERPROCEDUREbar1ISBEGIN-- 1000 lines of codeENDbar1;MEMBERPROCEDUREbar2ISBEGIN-- 1000 lines of codeENDbar2;MEMBERPROCEDUREbar3ISBEGIN-- 1000 lines of codeENDbar3;MEMBERPROCEDUREbarNISBEGIN-- 1000 lines of codeENDbarn;END;This rule has the following properties:
| Name | Default Value | Description |
|---|---|---|
| minimum | 1000 | Threshold at or above which a node is reported |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/ExcessiveTypeLength"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/ExcessiveTypeLength"><properties><propertyname="minimum"value="1000"/></properties></rule>Since: PMD 7.19.0
Priority: Medium (3)
This rule uses the NCSS (Non-Commenting Source Statements) metric to determine the number of linesof code in a plsql type or method. NCSS ignores comments, blank lines, and only counts actualstatements. For more details on the calculation, see the documentationNCSS.
This rule is defined by the following Java class:net.sourceforge.pmd.lang.plsql.rule.design.NcssCountRule
Example(s):
DECLARE-- total Ncss: 14PROCEDUREbigMethodIS-- +1xNUMBER;-- +1yNUMBER:=2;-- +1aBOOLEAN:=FALSE;-- +1bBOOLEAN:=TRUE;-- +1BEGINIF(aORb)THEN-- +1LOOP-- +1x:=x+2;-- +1EXITWHENx>=12;-- +1ENDLOOP;DBMS_OUTPUT.PUT_LINE('done');-- +1ELSE-- +1DBMS_OUTPUT.PUT_LINE('false');-- +1ENDIF;EXCEPTIONWHENPROGRAM_ERRORTHENDBMS_OUTPUT.PUT_LINE('Error Occurred');-- +1ENDbigMethod;BEGINbigMethod();-- +1END;This rule has the following properties:
| Name | Default Value | Description |
|---|---|---|
| methodReportLevel | 40 | NCSS reporting threshold for methods |
| objectReportLevel | 500 | NCSS reporting threshold for objects |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/NcssCount"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/NcssCount"><properties><propertyname="methodReportLevel"value="40"/><propertyname="objectReportLevel"value="500"/></properties></rule>Deprecated
Since: PMD 5.1
Priority: Medium (3)
This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of linesof 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.
Deprecated: This rule is deprecated since PMD 7.19.0 and will be removed with PMD 8.0.0. UseNcssCount instead.
This rule is defined by the following Java class:net.sourceforge.pmd.lang.plsql.rule.design.NcssMethodCountRule
Example(s):
CREATEORREPLACEPACKAGEBODYASFUNCTIONmethodRETURNINTEGERISBEGINRETURN1;END;END;This rule has the following properties:
| Name | Default Value | Description |
|---|---|---|
| minimum | 100 | Threshold at or above which a node is reported |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/NcssMethodCount"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/NcssMethodCount"><properties><propertyname="minimum"value="100"/></properties></rule>Deprecated
Since: PMD 5.1
Priority: Medium (3)
This rule uses the NCSS (Non-Commenting Source Statements) algorithm to determine the number of linesof 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.
Deprecated: This rule is deprecated since PMD 7.19.0 and will be removed with PMD 8.0.0. UseNcssCount instead.
This rule is defined by the following Java class:net.sourceforge.pmd.lang.plsql.rule.design.NcssObjectCountRule
Example(s):
CREATEORREPLACEPACKAGEpkg_ISPROCEDUREFooISBEGIN--this class only has 6 NCSS linessuper();super();ENDFoo;END;This rule has the following properties:
| Name | Default Value | Description |
|---|---|---|
| minimum | 1500 | Threshold at or above which a node is reported |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/NcssObjectCount"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/NcssObjectCount"><properties><propertyname="minimum"value="1500"/></properties></rule>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 reducecomplexity and increase readability.
This rule is defined by the following Java class:net.sourceforge.pmd.lang.plsql.rule.design.NPathComplexityRule
Example(s):
CREATEORREPLACEPROCEDUREbarASBEGIN-- this is something more complex than it needs to be,if(y)THEN-- it should be broken down into smaller methods or functionsforjIN0..j-1LOOPif(j>r)THENdoSomething;while(f<5)LOOPanotherThing;f:=f-27;ENDLOOP;elsetryThis();ENDIF;ENDLOOP;ENDIF;if(r-n>45)THENwhile(doMagic)LOOPfindRabbits;ENDLOOP;ENDIF;BEGINdoSomethingDangerous();EXCEPTIONWHENFooExceptionTHENmakeAmends;BEGINdontDoItAgain;EXCEPTIONWHENOTHERSTHENlog_problem;END;END;END;This rule has the following properties:
| Name | Default Value | Description |
|---|---|---|
| minimum | 200 | Threshold at or above which a node is reported |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/NPathComplexity"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/NPathComplexity"><properties><propertyname="minimum"value="200"/></properties></rule>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 individualcity/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):
CREATEORREPLACEPACKAGEpkg_too_many_fieldsASC_CHAR_ACONSTANTCHAR(1CHAR):='A';C_CHAR_BCONSTANTCHAR(1CHAR):='B';...C_CHAR_ZCONSTANTCHAR(1CHAR):='Z';ENDpkg_too_many_fields;This rule has the following properties:
| Name | Default Value | Description |
|---|---|---|
| maxfields | 15 | Max allowable fields |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/TooManyFields"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/TooManyFields"><properties><propertyname="maxfields"value="15"/></properties></rule>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 tohave more fine grained objects.
This rule is defined by the following XPath expression:
//node()[(local-name(.)='PackageSpecification'orlocal-name(.)='TypeSpecification')and(count(/descendant::ProgramUnit[not(starts-with(@Name,'get')orstarts-with(@Name,'set')orstarts-with(@Name,'is'))])+count(/descendant::TypeMethod[not(starts-with(@Name,'get')orstarts-with(@Name,'set')orstarts-with(@Name,'is'))]))>$maxmethods]This rule has the following properties:
| Name | Default Value | Description |
|---|---|---|
| maxmethods | 1 | The method count reporting threshold |
Use this rule with the default properties by just referencing it:
<ruleref="category/plsql/design.xml/TooManyMethods"/>Use this rule and customize it:
<ruleref="category/plsql/design.xml/TooManyMethods"><properties><propertyname="maxmethods"value="1"/></properties></rule>