Class Roodi::Checks::AbcMetricMethodCheck
In: lib/roodi/checks/abc_metric_method_check.rb
Parent: Roodi::Checks::Check

TODO: Add summary

TODO: Add detail

Methods

Constants

ASSIGNMENTS = [:lasgn]
BRANCHES = [:vcall, :call]
CONDITIONS = [:==, :<=, :>=, :<, :>]
OPERATORS = [:*, :/, :%, :+, :<<, :>>, :&, :|, :^]
DEFAULT_SCORE = 10

Public Class methods

[Source]

# File lib/roodi/checks/abc_metric_method_check.rb, line 19
      def initialize(options = {})
        super()
        @score = options['score'] || DEFAULT_SCORE
      end

Public Instance methods

[Source]

# File lib/roodi/checks/abc_metric_method_check.rb, line 28
      def evaluate_start(node)
        method_name = node[1]
        a = count_assignments(node)
        b = count_branches(node)
        c = count_conditionals(node)
        score = Math.sqrt(a*a + b*b + c*c)
        add_error "Method name \"#{method_name}\" has an ABC metric score of <#{a},#{b},#{c}> = #{score}.  It should be #{@score} or less." unless score <= @score
      end

[Source]

# File lib/roodi/checks/abc_metric_method_check.rb, line 24
      def interesting_nodes
        [:defn]
      end

[Validate]