class RubbyCop::Cop::Metrics::AbcSize

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See c2.com/cgi/wiki?AbcMetric

Constants

BRANCH_NODES
CONDITION_NODES
MSG

Private Instance Methods

complexity(node) click to toggle source
# File lib/rubbycop/cop/metrics/abc_size.rb, line 19
def complexity(node)
  assignment = 0
  branch = 0
  condition = 0

  node.each_node do |child|
    if child.assignment?
      assignment += 1
    elsif BRANCH_NODES.include?(child.type)
      branch += 1
    elsif CONDITION_NODES.include?(child.type)
      condition += 1
    end
  end

  Math.sqrt(assignment**2 + branch**2 + condition**2).round(2)
end