class Reek::SmellDetectors::DuplicateMethodCall
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
DuplicateMethodCall
checks for repeated identical method calls within any one method definition. For example, the following method will report a warning:
def double_thing() @other.thing + @other.thing end
See {file:docs/Duplicate-Method-Call.md} for details.
Constants
- ALLOW_CALLS_KEY
-
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.
- DEFAULT_ALLOW_CALLS
- DEFAULT_MAX_CALLS
- MAX_ALLOWED_CALLS_KEY
-
The name of the config field that sets the maximum number of identical calls to be permitted within any single method.
Public Class Methods
Source
# File lib/reek/smell_detectors/duplicate_method_call.rb, line 33 def self.default_config super.merge( MAX_ALLOWED_CALLS_KEY => DEFAULT_MAX_CALLS, ALLOW_CALLS_KEY => DEFAULT_ALLOW_CALLS) end
Calls superclass method
Reek::SmellDetectors::BaseDetector::default_config
Public Instance Methods
Source
# File lib/reek/smell_detectors/duplicate_method_call.rb, line 44 def sniff collector = CallCollector.new(context, max_allowed_calls, allow_calls) collector.smelly_calls.map do |found_call| call = found_call.call occurs = found_call.occurs smell_warning( lines: found_call.lines, message: "calls '#{call}' #{occurs} times", parameters: { name: call, count: occurs }) end end
Looks for duplicate calls within the body of the method context.
@return [Array<SmellWarning>]
Private Instance Methods
Source
# File lib/reek/smell_detectors/duplicate_method_call.rb, line 62 def allow_calls value(ALLOW_CALLS_KEY, context) end
Source
# File lib/reek/smell_detectors/duplicate_method_call.rb, line 58 def max_allowed_calls value(MAX_ALLOWED_CALLS_KEY, context) end