Sha256: 7666d1174c185b1394fc3358471a8a70ea23a92a881f6eaf16d54057b84d6bfc
Contents?: true
Size: 1.45 KB
Versions: 1
Compression:
Stored size: 1.45 KB
Contents
$:.unshift File.dirname(__FILE__) require 'reek/smells/smell' module Reek module Smells # # Control Coupling occurs when a method or block checks the value of # a parameter in order to decide which execution path to take. The # offending parameter is often called a Control Couple. # # A simple example would be the <tt>quoted</tt> parameter # in the following method: # # def write(quoted) # if quoted # write_quoted(@value) # else # puts @value # end # end # # Control Coupling is a kind of duplication, because the calling method # already knows which path should be taken. # # Control Coupling reduces the code's flexibility by creating a # dependency between the caller and callee: # any change to the possible values of the controlling parameter must # be reflected on both sides of the call. # # A Control Couple also reveals a loss of simplicity: the called # method probably has more than one responsibility, # because it includes at least two different code paths. # class ControlCouple < Smell def initialize(context, args) super @args = args end def recognise?(cond) @couple = cond cond[0] == :lvar and @args.include?(@couple[1]) end def detailed_report "#{@context} is controlled by argument #{Printer.print(@couple)}" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
reek-0.3.1 | lib/reek/smells/control_couple.rb |