Class: Simplabs::Excellent::Checks::AbcMetricMethodCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/simplabs/excellent/checks/abc_metric_method_check.rb

Overview

This check reports methods with an ABC metric score that is higher than the threshold. The ABC metric is basically a measure for complexity and is calculated as:

a = number of assignments
b = number of branches
c = number of conditions

score = Math.sqrt(a*a + b*b + c*c)

Applies to

  • methods

Constant Summary collapse

DEFAULT_THRESHOLD =
10

Instance Attribute Summary

Attributes inherited from Base

#interesting_files, #interesting_nodes, #warnings

Instance Method Summary collapse

Methods inherited from Base

#add_warning, #evaluate_node, #warnings_for

Constructor Details

#initialize(options = {}) ⇒ AbcMetricMethodCheck

:nodoc:



25
26
27
28
29
# File 'lib/simplabs/excellent/checks/abc_metric_method_check.rb', line 25

def initialize(options = {}) #:nodoc:
  super()
  @threshold         = options[:threshold] || DEFAULT_THRESHOLD
  @interesting_nodes = [:defn, :defs]
end

Instance Method Details

#evaluate(context) ⇒ Object

:nodoc:



31
32
33
34
35
# File 'lib/simplabs/excellent/checks/abc_metric_method_check.rb', line 31

def evaluate(context) #:nodoc:
  unless context.abc_score <= @threshold
    add_warning(context, '{{method}} has abc score of {{score}}.', { :method => context.full_name, :score => context.abc_score })
  end
end