class RubyCritic::Analyser::FlogSmells

Constants

HIGH_COMPLEXITY_SCORE_THRESHOLD
VERY_HIGH_COMPLEXITY_SCORE_THRESHOLD

Public Class Methods

new(analysed_modules) click to toggle source
# File lib/rubycritic/analysers/smells/flog.rb, line 14
def initialize(analysed_modules)
  @flog = Flog.new
  @analysed_modules = analysed_modules
end

Public Instance Methods

run() click to toggle source
# File lib/rubycritic/analysers/smells/flog.rb, line 19
def run
  @analysed_modules.each do |analysed_module|
    add_smells_to(analysed_module)
    print green '.'
  end
  puts ''
end
to_s() click to toggle source
# File lib/rubycritic/analysers/smells/flog.rb, line 27
def to_s
  'flog smells'
end

Private Instance Methods

add_smells_to(analysed_module) click to toggle source
# File lib/rubycritic/analysers/smells/flog.rb, line 33
def add_smells_to(analysed_module)
  @flog.reset
  @flog.flog(analysed_module.path)
  @flog.each_by_score do |class_method, original_score|
    score = original_score.round
    analysed_module.smells << create_smell(class_method, score) if score >= HIGH_COMPLEXITY_SCORE_THRESHOLD
  end
end
create_smell(context, score) click to toggle source
# File lib/rubycritic/analysers/smells/flog.rb, line 42
def create_smell(context, score)
  Smell.new(
    locations: smell_locations(context),
    context: context,
    message: "has a flog score of #{score}",
    score: score,
    type: type(score),
    analyser: 'flog',
    cost: 0
  )
end
smell_locations(context) click to toggle source
# File lib/rubycritic/analysers/smells/flog.rb, line 54
def smell_locations(context)
  line = @flog.method_locations[context]
  file_path, file_line = line.split(':')
  [Location.new(file_path, file_line)]
end
type(score) click to toggle source
# File lib/rubycritic/analysers/smells/flog.rb, line 60
def type(score)
  if score >= VERY_HIGH_COMPLEXITY_SCORE_THRESHOLD
    'VeryHighComplexity'
  else
    'HighComplexity'
  end
end