class CodeKeeper::Metrics::CyclomaticComplexity

Caluculate cyclomatic complexity

Constants

CONSIDERED_NODES

Public Class Methods

new(file_path) click to toggle source
# File lib/code_keeper/metrics/cyclomatic_complexity.rb, line 12
def initialize(file_path)
  ps = Parser.parse(file_path)
  @body = ps.ast
end

Public Instance Methods

score() click to toggle source

returns score of cyclomatic complexity

# File lib/code_keeper/metrics/cyclomatic_complexity.rb, line 18
def score
  @body.each_node(:lvasgn, *CONSIDERED_NODES).reduce(1) do |score, node|
    next score if !iterating_block?(node) || node.lvasgn_type?
    next score if node.csend_type? && discount_for_repeated_csend?(node)

    next 1 + score
  end
end