SmellDetector
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
Currently Duplication 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
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.
The name of the config field that sets the maximum number of identical calls to be permitted within any single method.
Looks for duplicate calls within the body of the method ctx.
@return [Array<SmellWarning>]
# File lib/reek/smells/duplication.rb, line 56 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) calls(ctx).select do |call_exp, copies| copies.length > @max_allowed_calls and not allow_calls?(call_exp.format_ruby) end.map do |call_exp, copies| occurs = copies.length call = call_exp.format_ruby multiple = occurs == 2 ? 'twice' : "#{occurs} times" smell = SmellWarning.new(SMELL_CLASS, ctx.full_name, copies.map {|exp| exp.line}, "calls #{call} #{multiple}", @source, SMELL_SUBCLASS, {CALL_KEY => call, OCCURRENCES_KEY => occurs}) smell end end
Generated with the Darkfish Rdoc Generator 2.