Class: Roodi::Checks::ControlCouplingCheck

Inherits:
Check
  • Object
show all
Defined in:
lib/roodi/checks/control_coupling_check.rb

Overview

Checks if a method uses an argument to decide on what execution path to take

It is a kind of duplication, since the caller knows what path should be taken. Also, it means the method has more than one responsibility.

Constant Summary

Constants inherited from Check

Roodi::Checks::Check::NODE_TYPES

Instance Method Summary collapse

Methods inherited from Check

#add_error, #end_file, #errors, #evaluate_end, #evaluate_node, #evaluate_node_end, #evaluate_node_start, #evaluate_start, #initialize, make, #position, #start_file

Constructor Details

This class inherits a constructor from Roodi::Checks::Check

Instance Method Details

#evaluate_start_defn(node) ⇒ Object



14
15
16
17
# File 'lib/roodi/checks/control_coupling_check.rb', line 14

def evaluate_start_defn(node)
  @method_name = node[1]
  @arguments = node[2][1..-1]
end

#evaluate_start_lvar(node) ⇒ Object



19
20
21
# File 'lib/roodi/checks/control_coupling_check.rb', line 19

def evaluate_start_lvar(node)
  add_error "Method \"#{@method_name}\" uses the argument \"#{node[1]}\" for internal control." if @arguments.detect {|each| each == node[1]}
end

#interesting_nodesObject



10
11
12
# File 'lib/roodi/checks/control_coupling_check.rb', line 10

def interesting_nodes
  [:defn, :lvar]
end