class Rubycritic::Analyser::FlaySmells
def cost(mass)
def cost(mass) mass / 25 end
def create_smell(structural_hash, nodes)
def create_smell(structural_hash, nodes) mass = @flay.masses[structural_hash] Smell.new( :locations => smell_locations(nodes), :context => similarity(structural_hash), :message => "found in #{nodes.size} nodes", :score => mass, :type => "DuplicateCode", :cost => cost(mass) ) end
def initialize(analysed_modules)
def initialize(analysed_modules) @analysed_modules = paths_to_analysed_modules(analysed_modules) @flay = Flay.new(@analysed_modules.keys) end
def paths_to_analysed_modules(analysed_modules)
def paths_to_analysed_modules(analysed_modules) paths = {} analysed_modules.each do |analysed_module| paths[analysed_module.path] = analysed_module end paths end
def run
def run @flay.hashes.each do |structural_hash, nodes| smell = create_smell(structural_hash, nodes) nodes.map(&:file).uniq.each do |file| @analysed_modules[file].smells << smell end nodes.each do |node| @analysed_modules[node.file].duplication += node.mass end end end
def similarity(structural_hash)
def similarity(structural_hash) if @flay.identical[structural_hash] "Identical code" else "Similar code" end end
def smell_locations(nodes)
def smell_locations(nodes) nodes.map do |node| Location.new(node.file, node.line) end.sort end