lib/simplabs/excellent/checks/control_coupling_check.rb in simplabs-excellent-1.0.1 vs lib/simplabs/excellent/checks/control_coupling_check.rb in simplabs-excellent-1.2.1
- old
+ new
@@ -4,23 +4,26 @@
module Excellent
module Checks
+ # This check reports methods that check the value of a parameter to decide which execution path to take. Control Coupling introduces a
+ # dependency between the caller and the callee. Any changes to the possible values of the parameter must be reflected at the caller side
+ # as well as at the called method.
+ #
+ # ==== Applies to
+ #
+ # * methods
class ControlCouplingCheck < Base
- def interesting_nodes
- [:defn, :lvar]
+ def initialize #:nodoc:
+ super
+ @interesting_nodes = [:if, :case]
end
- def evaluate_defn(node)
- @method_name = node[1]
- @arguments = node[2][1..-1]
- end
-
- def evaluate_lvar(node)
- if @arguments.detect { |argument| argument == node[1] }
- add_error('Control of {{method}} is coupled to {{argument}}.', { :method => @method_name, :argument => node[1] }, -1)
+ def evaluate(context) #:nodoc:
+ if tested_parameter = context.tests_parameter?
+ add_warning(context, '{{method}} is coupled to {{argument}}.', { :method => context.parent.full_name, :argument => tested_parameter.to_s }, -2)
end
end
end