Sha256: 7142f4f0ca5c13ca060c9ef70f956c86c1f2dd60037ce79b115575d90a730b52
Contents?: true
Size: 1.07 KB
Versions: 4
Compression:
Stored size: 1.07 KB
Contents
require 'simplabs/excellent/checks/base' module Simplabs module Excellent module Checks # 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 class AbcMetricMethodCheck < Base DEFAULT_THRESHOLD = 10 def initialize(options = {}) #:nodoc: super() @threshold = options[:threshold] || DEFAULT_THRESHOLD @interesting_contexts = [Parsing::MethodContext, Parsing::SingletonMethodContext] end 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 end end end end
Version data entries
4 entries across 4 versions & 1 rubygems