Sha256: 01399e8636092490825aa7b4da12ef333d2496e448da095de3fa5bee9d53ccc3
Contents?: true
Size: 1.46 KB
Versions: 12
Compression:
Stored size: 1.46 KB
Contents
# frozen_string_literal: true module RuboCop module Cop module Metrics module Utils # > ABC is .. a software size metric .. computed by counting the number # > of assignments, branches and conditions for a section of code. # > http://c2.com/cgi/wiki?AbcMetric # # We separate the *calculator* from the *cop* so that the calculation, # the formula itself, is easier to test. module AbcSizeCalculator # > Branch -- an explicit forward program branch out of scope -- a # > function call, class method call .. # > http://c2.com/cgi/wiki?AbcMetric BRANCH_NODES = %i[send csend].freeze # > Condition -- a logical/Boolean test, == != <= >= < > else case # > default try catch ? and unary conditionals. # > http://c2.com/cgi/wiki?AbcMetric CONDITION_NODES = CyclomaticComplexity::COUNTED_NODES.freeze def self.calculate(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 end end end end end
Version data entries
12 entries across 10 versions & 2 rubygems