How Complexity metrics are calculated by CAST AIP

CAST Complexity Metrics

The CAST Quality Model contains various metrics that are classed as "Complexity metrics", i.e. metrics that measure the complexity of artifacts in an application. This page contains a basic description of the mechanisms used to determine the complexity of a given artifact. CAST provides data for the following "Complexity metrics":

  1. Cyclomatic Complexity
  2. Basic Cyclomatic Complexity
  3. Essential Complexity
  4. Integration Complexity
  5. Cost Complexity - used in the Cost Estimation feature

How is complexity calculated?

Cyclomatic, Basic Cyclomatic, Essential, Integration

During an analysis and subsequent snapshot generation, CAST determines a complexity score for an artifact by counting the number of statements (i.e. IF, ELSE-IF, WHILE, DO etc.) it encounters - an increment of one per statement encountered is used. In addition, nested statements are also counted, which contribute to the overall complexity score.

Each Complexity metric takes into account different statements - these are listed below.

For all the metrics listed below, the program or sub-program entry point is counted as 1. As a consequence, all the metrics below will have a minimum value of 1 (even if the object contains no code). When the minimum value is assigned to an object, an INFO message is listed in the analysis log, for example:

2021-09-22 09:03:15,587    INFO    MODULMSG ; Body    Missing cyclomatic complexity for <path_to_object). Assigned default value 1

Cyclomatic Complexity

To compute this metric, a counter is incremented by one each time one of the following statements is encountered:

  • IF
  • ELSE-IF
  • AND-OR
  • CASE
  • CATCH
  • CONTINUE (only in loops)
  • DO-WHILE
  • WHILE
  • FOR
  • TRY

Basic Cyclomatic Complexity

To compute this metric, a counter is incremented by one each time one of the following statements is encountered:

  • IF
  • ELSE-IF
  • CASE
  • CATCH
  • CONTINUE (only in loops)
  • DO-WHILE
  • WHILE
  • FOR
  • TRY

Essential Complexity

Two statement types are taken into account for this metric:

Primitive Statements

  • IF
  • ELSE-IF
  • AND-OR
  • SWITCH
  • CASE
  • TRY
  • CATCH
  • DO-WHILE
  • WHILE
  • FOR

Complex Statements

  • BREAK (Only in loops)
  • CONTINUE (Only in loops)
  • GOTO
  • RAISE

How does it work?

CAST walks through the Primitive statements in the artifact and then the Complex statements. If a statement is encountered in a Primitive statement but it is not determined to match one of the predefined Complex statements then the branch is "reduced" (i.e.skipped) back to the first Complex statement that was encountered (or the root if none). For example:

Complex statement encountered
Function XX 					=> Init = 1
	Prim 1 						=> +1
		Prim 2 					=> +1
			Prim 3 				=> +1
				Complex 1 		=> Complex => No reduction

Result = 4
Complex statement followed by non-Complex (reduction)
Function XX 					=> Init = 1
	Prim 1 						=> +1
		Complex 1 				=> Complex => No reduction
		Prim 2 					=> +1
			Prim 3 				=> +1
				Statement 		=> Non-Complex => Reduction to the first Complex statement
Result = 2
Non-Complex statement
Function XX             		=> Init = 1
	Prim 1               		=> +1
		Prim 2              	=> +1
			Prim 3            	=> +1
				Statement       => No Complex => Reduction to the root

Result: EvG = 1

Integration Complexity

This metric functions in exactly the same way as Essential Complexity (described above) except that the list of Complex Statements is different:

Primitive Statements

  • IF
  • ELSE-IF
  • AND-OR
  • SWITCH
  • CASE
  • TRY
  • CATCH
  • DO-WHILE
  • WHILE
  • FOR

Complex Statements

  • CALL

Cost

Cost Complexity is calculated in a different way to other Complexity metrics. It takes into account complexity scores for other types of complexity (such as Cylcomatic Complexity) and aggregates them to provide a score for Cost Complexity.

Items taken into account

The following are taken into account:

Lack of Comment index

Artifacts are positioned based on their comment/code ratio using the following thresholds:

  • Average Comment/Code ratio: 15
  • High Comment/Code Ratio: 7
  • Very High Comment/Code Ratio: 3

Cyclomatic Complexity index

Artifacts are positioned based on their Cyclomatic Complexity score as follows:

  • Moderate Cyclomatic Complexity: for all artifacts having a result for the metric 65503 (Moderate Complexity Artifacts)

  • High Cyclomatic Complexity: for all artifacts having a result for the metric 65504 (High Complexity Artifacts)

  • Very High Cyclomatic Complexity: for all artifacts having a result for the metric 65505 (Very High Complexity Artifacts)

SQL Complexity index

Artifacts are positioned based on their SQL Complexity score as follows:

  • Moderate SQL Complexity: for all artifacts having a result for the metric 65803 (Moderate SQL Complexity Artifacts)

  • High SQL Complexity: for all artifacts having a result for the metric 65804 (High SQL Complexity Artifacts)

  • Very High SQL Complexity: for all artifacts having a result for the metric 65805 (Very High SQL Complexity Artifacts)

Artifact Granularity index

Artifacts are positioned based on their Size Distribution score as follows:

  • Average Granularity: for all artifacts having a result for the metric 65102 (Average Size Artifacts)

  • High Granularity: for all artifacts having a result for the metric 65103 (Large Size Artifacts)

  • Very High Granularity: for all artifacts having a result for the metric 65104 (Very Large Size Artifacts)

Artifact Coupling index

Artifacts are positioned based on their Coupling Distribution score as follows:

  • Average Coupling: for all artifacts having a result for the metric 65302 (Average Coupling Artifacts)

  • High Coupling: for all artifacts having a result for the metric 65303 (High Coupling Artifacts)

  • Very High Coupling: for all artifacts having a result for the metric 65304 (Very High Coupling Artifacts)

Cost Complexity calculation

Once the above scores are determined for an artifact, the Cost Complexity score is then calculated as follows:

Very High Cost Complexity

Cost Complexity will be Very High when ONE of the following is true:

  • Cyclomatic Complexity index is Very High
  • SQL Complexity index is Very High
  • Artifact Granularity index is Very High and Lack of Comment index is Very High and Artifact Coupling index is Very High

High Cost Complexity

Cost Complexity will be High when ONE of the following is true:

  • Cyclomatic Complexity index is Moderate and SQL Complexity index is Moderate and (Artifact Granularity index is Very High or Lack of Comment index is Very High or Artifact Coupling index is Very High)
  • Cyclomatic Complexity index is High
  • Artifact Granularity index is High and Lack of Comment index is High and Artifact Coupling Index is High

Moderate Cost Complexity

Cost Complexity will be Moderate when ONE of the following is true:

  • Cyclomatic Complexity index is Low and SQL Complexity index is Low and (Artifact Granularity index is High and Lack of Comment index is High and Artifact Coupling index is High)
  • Cyclomatic Complexity index is Moderate
  • SQL Complexity index is Moderate
  • Artifact Granularity index is Moderate and Lack of Comment index is Moderate and Artifact Coupling index is Moderate