MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / calculateComplexityMetrics

Method calculateComplexityMetrics

cmd/gosqlx/cmd/sql_analyzer.go:396–427  ·  view source on GitHub ↗

calculateComplexityMetrics calculates complexity metrics

()

Source from the content-addressed store, hash-verified

394
395// calculateComplexityMetrics calculates complexity metrics
396func (a *SQLAnalyzer) calculateComplexityMetrics() {
397 // Cyclomatic complexity based on conditions and branches
398 cyclomaticComplexity := 1 + len(a.Issues)
399
400 // Overall complexity calculation
401 complexityScore := float64(a.maxDepth)*2.0 +
402 float64(a.joinCount)*1.5 +
403 float64(a.subqueryCount)*3.0 +
404 float64(a.functionCount)*0.5
405
406 var complexityLevel string
407 switch {
408 case complexityScore < 5:
409 complexityLevel = "LOW"
410 case complexityScore < 15:
411 complexityLevel = "MEDIUM"
412 case complexityScore < 30:
413 complexityLevel = "HIGH"
414 default:
415 complexityLevel = "VERY_HIGH"
416 }
417
418 a.ComplexityMetrics = ComplexityMetrics{
419 CyclomaticComplexity: cyclomaticComplexity,
420 NestingDepth: a.maxDepth,
421 JoinComplexity: a.joinCount,
422 SubqueryDepth: a.subqueryCount,
423 FunctionCount: a.functionCount,
424 OverallComplexity: complexityLevel,
425 ComplexityScore: complexityScore,
426 }
427}
428
429// calculateScores calculates final analysis scores
430func (a *SQLAnalyzer) calculateScores() {

Callers 1

AnalyzeMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected