## Stateflow Design Cyclomatic Complexity

### Metric ID

`slcomp.SFCyclomaticComplexity`

### Description

The *design cyclomatic complexity* is the number of possible
execution paths through a design. In general, the more paths there are through a design,
the more complex the design is. When you keep the design cyclomatic complexity low, the
design typically is easier to read, maintain, and test. The design cyclomatic complexity
is calculated as the number of decision paths plus one. The metric adds one to account
for the execution path represented by the default path. The design cyclomatic complexity
includes the default path because the metric identifies each possible outcome from an
execution path, including the default outcome.

Use the Stateflow^{®} design cyclomatic complexity metric to determine the design cyclomatic
complexity for the Stateflow components in your design.

This metric counts the total number of Stateflow-based execution paths through a unit or component. The total number of execution paths is calculated as the number of Stateflow decisions, Stateflow Decision Count, plus one for the default path. The default path is only counted once per unit or component.

To see the number of Stateflow decisions associated with different Stateflow components, see Decision Counts for Common Stateflow Components.

### Computation Details

The metric:

Only supports Stateflow objects that use MATLAB

^{®}as the action language.Analyzes Stateflow charts that use C as the action language, but does not represent decisions from short-circuiting in logical operations.

### Collection

To collect data for this metric, use `getMetrics`

with the metric
identifier `slcomp.SFCyclomaticComplexity`

.

### Results

For this metric, instances of `metric.Result`

return
`Value`

as the Stateflow design cyclomatic complexity of a unit or component.

### Examples

Suppose you have a unit that contains only a Truth Table block from the
Stateflow library. By default, the Truth Table block contains a
**Condition Table** with two condition rows and three decision
columns and an **Action Table** with two actions.

To see the number of Stateflow decisions associated with different Stateflow components, see Decision Counts for Common Stateflow Components.

For the Truth Table block, the number of graphical decisions is
calculated as the number of conditions (rows) multiplied by the number of decisions
(columns) in the **Condition Table**. In this example, the number of
graphical decisions is equal to 2 multiplied by 3.

For the Truth Table block, the number of MATLAB code decisions is calculated as the number of decisions in the
**Action Table**. In this example, there are
no decisions made in the code of the **Action
Table**.

The Stateflow design cyclomatic complexity is equal to the sum of the number of
graphical Stateflow decisions, plus the number of MATLAB code decisions in the Stateflow component, plus one (for the default path). In this case, the Stateflow design cyclomatic complexity is calculated as `6 + 0 + 1`

which equals seven.