Configuration | Metrics // every POU has an initial cyclomatic complexity of 1, since it has at least 1 branch CASE a OF 1: ; // +1 2: ; // +1 3,4,5: ; // +1 ELSE // the ELSE statement does not increase the cyclomatic complexity ; END_CASE The code snippet has a cyclomatic complexity of 4. Sample: Loop statement // every POU has an initial cyclomatic complexity of 1, since it has at least 1 branch WHILE b1 DO // +1 for the WHILE loop ; END_WHILE REPEAT // +1 for the REPEAT loop ; UNTIL b2 END_REPEAT FOR a := 0 TO 100 BY 2 DO // +1 for the REPEAT loop ; END_FOR The code snippet has a cyclomatic complexity of 4. Sample:
Other statements The following statements also lead to an increase in cyclomatic complexity: FUNCTION FUN : STRING VAR_INPUT bReturn : BOOL; bJump : BOOL; END_VAR // every POU has an initial cyclomatic complexity of 1, since it has at least 1 branch JMP(bJump) lbl; //Conditional jumps increase the cyclomatic complexity by 1 FUN := 'u'; RETURN(condition_return); //Conditional returns increase the cyclomatic complexity by 1, too lbl: FUN := 't'; The code snippet has a cyclomatic complexity of 3.
4.4.1.14 Cognitive complexity | Cognitive complexity Tip You can also use Command 'Show cognitive complexity for current editor' [ } 116] to display the increments for Structured Text directly in the editor. TE1200 100 Version: 2.11.1 Title short form Cognitive complexity Categories Maintainability Definition Sum of partial complexities resulting, for example, from branches in the control flow of the POU and from sophisticated Boolean expressions Further information Cognitive complexity is a measure of the readability and comprehensibility of source code introduced by Sonarsource™ in 2016. It penalizes a strong nesting of the control flow and sophisticated Boolean expressions.
The cognitive complexity is only calculated for structured text implementations. Standard upper limit for the associated rule SA0178: Cognitive 20 complexity [} 79]