McCabe Cyclomatic ComplexityCyclomatic complexity is a measure of a module's structural complexity. Studies show a correlation between a program's Cyclomatic Complexity and its maintainability and testability, implying that with files of higher complexity there is a higher probability of errors when fixing, enhancing, or refactoring source code. The selected threshold is based on categories established by the Software Engineering Institute, as follows:
Aggregation is affected by the selected structure, as defined in the selected model, and the scope, as defined by the structure preset. Cyclomatic complexity is calculated as follows: Cyclomatic Complexity = ( 1 + ifs + loops + cases ) where:
Here is the pseudo code of a simple program and the Cyclomatic Complexity metric for it. Function While If Else Endif Endwhile End Function Since there is one "if" and one "loop" operator, we can calculate the Cyclomatic Complexity metric as 1+1+1=3. |