Class: Simplabs::Excellent::Checks::ControlCouplingCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/simplabs/excellent/checks/control_coupling_check.rb

Overview

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

Instance Attribute Summary

Attributes inherited from Base

#interesting_files, #interesting_nodes, #warnings

Instance Method Summary collapse

Methods inherited from Base

#add_warning, #evaluate_node, #warnings_for

Constructor Details

#initializeControlCouplingCheck

:nodoc:



18
19
20
21
# File 'lib/simplabs/excellent/checks/control_coupling_check.rb', line 18

def initialize #:nodoc:
  super
  @interesting_nodes = [:if, :case]
end

Instance Method Details

#evaluate(context) ⇒ Object

:nodoc:



23
24
25
26
27
# File 'lib/simplabs/excellent/checks/control_coupling_check.rb', line 23

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