Skip to content

Commit

Permalink
Merge pull request #72 from Halleck45/69_fix_incorrect_ccn
Browse files Browse the repository at this point in the history
#69 fixes incorrect CCN calculation for methods and cases
  • Loading branch information
Halleck45 authored Nov 19, 2024
2 parents 528e8e4 + 85de6c6 commit 65052ba
Show file tree
Hide file tree
Showing 4 changed files with 232 additions and 402 deletions.
13 changes: 12 additions & 1 deletion src/Analyzer/Complexity/CyclomaticVisitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ func (v *CyclomaticComplexityVisitor) Calculate(stmts *pb.Stmts) int32 {
ccn = int32(len(stmts.StmtLoop) +
len(stmts.StmtDecisionIf) +
len(stmts.StmtDecisionElseIf) +
len(stmts.StmtDecisionCase))
len(stmts.StmtDecisionCase) +
len(stmts.StmtDecisionSwitch) +
len(stmts.StmtFunction)) // +1 for the function itself
// else is not a decision point for ccn
// class is not a decision point for ccn

// iterate over children
for _, stmt := range stmts.StmtFunction {
Expand All @@ -70,5 +73,13 @@ func (v *CyclomaticComplexityVisitor) Calculate(stmts *pb.Stmts) int32 {
ccn += v.Calculate(stmt.Stmts)
}

for _, stmt := range stmts.StmtClass {
ccn += v.Calculate(stmt.Stmts)
}

for _, stmt := range stmts.StmtDecisionSwitch {
ccn += v.Calculate(stmt.Stmts)
}

return ccn
}
Loading

0 comments on commit 65052ba

Please sign in to comment.