BluInsights offers cyclomatic complexity analysis for multiple languages (see the complete list).
Cyclomatic complexity is a software metric used to indicate the complexity of a program. It represents the number of linearly independent paths through a program's source code [wiki]. It also represents the minimum ideal number of tests, each testing a path.
There are two ways to calculate the cyclomatic complexity :
- Using the control flow graph of the program : Complexity = E - N + 2 (where E = number of edges and N = number of nodes).
- Or by calculating the number of decision points ("if" statements or conditional loops) contained in that program plus one : Complexity = P + 1 (where P = number of decision points). This is the method adopted by BluInsights.
Launch complexity analysis
The proposed complexity analysis is performed leveraging advanced parsing features for multiple languages. Launching the analysis is as simple as selecting the programming language. The analysis can be launched as many as you want (the intermediate results will not be saved).
The analysis of large projects (thousands of programs) may take few minutes. You will receive an email when the results are available. In the meantime, you can use the other features.
BluInsights also allows you to import your own values for the cyclomatic complexity using a JSON file (the required format is shown when the question mark is clicked).
If multiple files have the same filename, the field "path" of these files in the JSON must be filled.
Cyclomatic Complexity Computation
The cyclomatic complexity of any structured program with only one entry point and one exit point is equal to the number of decision points contained in that program plus one. The decision points are if, for, for-each, while, do, catch and case statements. For each method in a program, we calculate this cyclomatic complexity, and the sum of the cyclomatic complexity of each method of a file gives the total cyclomatic complexity of the file.
Each language has only certain types of files containing code: if a file doesn't contains code (such as Images), all the values are 0.
|Language||Files Extension with Code|
|PowerBuilder||SRM, SRU, SRW|
|Natural||NSP, NSM, NSN, NSC, NSH|
|Mainframe (Cobol, RPG, PL/I, PROC/PRC, JCL and CL)||Cobol Extensions (CBL, COB, SQLCBLLE, QLCBLLE, CBLLE, COBCOP, SCO...), RPG, RPGLE, SQLRPGLE, JCL, CL, PLI, REXX and OpenVMS (COM, ICM, IFDLCOP...)|
- The files of a given language must have their right extensions so they can be correctly parsed. For files without extensions, the computation will rely on the classification) feature to detect the underlying languages.
- The .Net (C#) cyclomatic complexity uses MSBuild and the NuGet package Microsoft.CodeAnalysis.Metrics, provided by Microsoft.
The Total Cyclomatic Complexity corresponds to the sum of the Cyclomatic Complexity of all the files in the project.
The Cyclomatic Complexity result is displayed as a table with all the files within the project. Each file is associated with its total cyclomatic complexity, method count and average cyclomatic complexity per method.
The result can also be displayed as a graph, with the number of Lines of Code as the x-axis and the Total Cyclomatic Complexity as the y-axis, each dot corresponding to a file. The graph can be filtered according to multiple criteria.
The results can also be downloaded as a json file or exported in an Excel file. This can be useful to add extra information and re-import the results again to update the project.