scitools.com

← Metric catalog

Sonargraph's Maintainability Level is one of the source-code metrics Understand computes across 17+ languages — browse them in the GUI, export and track them, or script them with the Python API.

Sonargraph's Maintainability Level

API IDSonargraphMaintainability
TargetsArchitectures Project
LanguagesAny
SolutionProject Quality
CategoriesCoupling
CostCached
TagsDependencies

The percentage a system is maintainable based on dependencies, with higher values better.

Sonargraph defines their Maintainability Level metric in their blog article A Promising New Metric To Track Maintainability. It is calculated from a dependency graph of system components, with higher values indicating more independent components. Sonargraph recommends aiming for a value higher than 70%, and avoiding values lower than 50%.

Given a dependency graph of system components, the calculation first combines strongly connected components into a single node to get a directed acyclic graph. The graph is then split into levels.

Each node's value is 1 - (influenced_components / components_in_higher_levels). The idea is to reflect how easily a component can be changed. The more incoming dependencies, the harder it is to change a given component. A component in the highest layer is not depended on by anything so it can be easily changed (value = 1). In contrast, a component on a lower level is less maintainable based on how much of the system depends on it.

For a node representing multiple components (a cycle), the value is multiplied by the number of components in the cycle. Cycles bigger than 5 have an additional penalty of 5 / size multiplied with the node score.

The final value is the average of each node's value, multiplied by 100 to convert it to a percentage. For example, consider a system with 10 nodes: A-J. Suppose C, D, E, F, G and H form a cycle and A->C, B->I, H->J, and I->J.


Then:

So the final value is (1 + 1 + 0.5 + 2.5 + 0) / 10 = 0.5 = 50%.

In this implementation, a component is a file combined with its companion files, such as a C or C++ header and its source file. Files are companions when they have the same name up to the first dot (the last dot for web files) and are in the same folder, or when they are in different folders and one defines most of what the other declares, or when one is a file Qt generates for the other. A component depends on another if any of its files depends on any of the other's files.

This implementation is likely to differ from Sonargraph in the following ways:

For a similar metric not influenced by level, see PropagationCost.