class MetricFu::ReekHotspot

Constants

COLUMNS

Note that in practice, the prefix reek__ is appended to each one This was a partially implemented idea to avoid column name collisions but it is only done in the ReekHotspot

Public Class Methods

numeric_smell?(type) click to toggle source
# File lib/metric_fu/metrics/reek/hotspot.rb, line 53
def self.numeric_smell?(type)
  ["Large Class", "Long Method", "Long Parameter List"].include?(type)
end

Public Instance Methods

columns() click to toggle source
# File lib/metric_fu/metrics/reek/hotspot.rb, line 8
def columns
  COLUMNS.map { |column| "#{name}__#{column}" }
end
generate_records(data, table) click to toggle source
# File lib/metric_fu/metrics/reek/hotspot.rb, line 28
def generate_records(data, table)
  return if data == nil
  data[:matches].each do |match|
    file_path = match[:file_path]
    match[:code_smells].each do |smell|
      location = MetricFu::Location.for(smell[:method])
      smell_type = smell[:type]
      message = smell[:message]
      table << {
        "metric" => name, # important
        "file_path" => file_path, # important
        # NOTE: ReekHotspot is currently different than other hotspots with regard
        # to column name. Note the COLUMNS constant and #columns method
        "reek__message" => message,
        "reek__type_name" => smell_type,
        "reek__value" => parse_value(message),
        "reek__value_description" => build_value_description(smell_type, message),
        "reek__comparable_message" => comparable_message(smell_type, message),
        "class_name" => location.class_name, # important
        "method_name" => location.method_name, # important
      }
    end
  end
end
map_strategy() click to toggle source
# File lib/metric_fu/metrics/reek/hotspot.rb, line 16
def map_strategy
  :present
end
name() click to toggle source
# File lib/metric_fu/metrics/reek/hotspot.rb, line 12
def name
  :reek
end
present_group(group) click to toggle source
# File lib/metric_fu/metrics/reek/hotspot.rb, line 57
def present_group(group)
  occurences = group.size
  "found #{occurences} code smells"
end
reduce_strategy() click to toggle source
# File lib/metric_fu/metrics/reek/hotspot.rb, line 20
def reduce_strategy
  :sum
end
score_strategy() click to toggle source
# File lib/metric_fu/metrics/reek/hotspot.rb, line 24
def score_strategy
  :percentile
end

Private Instance Methods

build_value_description(type_name, message) click to toggle source
# File lib/metric_fu/metrics/reek/hotspot.rb, line 77
def build_value_description(type_name, message)
  item_type = message.match(/\d+ (.*)$/)
  if item_type
    "number of #{item_type[1]} in #{type_name.downcase}"
  else
    nil
  end
end
comparable_message(type_name, message) click to toggle source
# File lib/metric_fu/metrics/reek/hotspot.rb, line 64
def comparable_message(type_name, message)
  if self.class.numeric_smell?(type_name)
    match = message.match(/\d+/)
    if match
      match.pre_match + match.post_match
    else
      message
    end
  else
    message
  end
end
parse_value(message) click to toggle source
# File lib/metric_fu/metrics/reek/hotspot.rb, line 86
def parse_value(message)
  # mf_debug "parsing #{message}"
  match = message.match(/\d+/)
  if match
    match[0].to_i
  else
    nil
  end
end