| Class | Reek::Smells::ControlCouple |
| In: |
lib/reek/smells/control_couple.rb
|
| Parent: | SmellDetector |
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 quoted 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.
# File lib/reek/smells/control_couple.rb, line 42 def self.default_config super.adopt(EXCLUDE_KEY => ['initialize']) end
# File lib/reek/smells/control_couple.rb, line 46 def initialize(config = ControlCouple.default_config) super end