lib/reek/smells/duplicate_method_call.rb in reek-1.5.1 vs lib/reek/smells/duplicate_method_call.rb in reek-1.6.0

- old
+ new

@@ -15,29 +15,25 @@ # def double_thing() # @other.thing + @other.thing # end # class DuplicateMethodCall < SmellDetector - SMELL_CLASS = 'Duplication' - SMELL_SUBCLASS = name.split(/::/)[-1] - - CALL_KEY = 'call' - OCCURRENCES_KEY = 'occurrences' - # The name of the config field that sets the maximum number of # identical calls to be permitted within any single method. MAX_ALLOWED_CALLS_KEY = 'max_calls' - DEFAULT_MAX_CALLS = 1 # The name of the config field that sets the names of any # methods for which identical calls should be to be permitted # within any single method. ALLOW_CALLS_KEY = 'allow_calls' - DEFAULT_ALLOW_CALLS = [] + def self.smell_category + 'Duplication' + end + def self.default_config super.merge( MAX_ALLOWED_CALLS_KEY => DEFAULT_MAX_CALLS, ALLOW_CALLS_KEY => DEFAULT_ALLOW_CALLS ) @@ -50,15 +46,17 @@ # def examine_context(ctx) max_allowed_calls = value(MAX_ALLOWED_CALLS_KEY, ctx, DEFAULT_MAX_CALLS) allow_calls = value(ALLOW_CALLS_KEY, ctx, DEFAULT_ALLOW_CALLS) - CallCollector.new(ctx, max_allowed_calls, allow_calls).smelly_calls.map do |found_call| - SmellWarning.new(SMELL_CLASS, ctx.full_name, found_call.lines, - found_call.smell_message, - @source, SMELL_SUBCLASS, - CALL_KEY => found_call.call, OCCURRENCES_KEY => found_call.occurs) + collector = CallCollector.new(ctx, max_allowed_calls, allow_calls) + collector.smelly_calls.map do |found_call| + SmellWarning.new self, + context: ctx.full_name, + lines: found_call.lines, + message: "calls #{found_call.call} #{found_call.occurs} times", + parameters: { name: found_call.call, count: found_call.occurs } end end # Collects information about a single found call class FoundCall @@ -67,14 +65,9 @@ @occurences = [] end def record(occurence) @occurences.push occurence - end - - def smell_message - multiple = occurs == 2 ? 'twice' : "#{occurs} times" - "calls #{call} #{multiple}" end def call @call ||= @call_node.format_ruby end