Class: Reek::Smells::ControlParameter::ControlParameterFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/reek/smells/control_parameter.rb

Overview

Finds cases of ControlParameter in a particular node for a particular parameter

Constant Summary collapse

CONDITIONAL_NODE_TYPES =
[:if, :case, :and, :or]

Instance Method Summary collapse

Constructor Details

#initialize(node, param) ⇒ ControlParameterFinder

Returns a new instance of ControlParameterFinder


90
91
92
93
# File 'lib/reek/smells/control_parameter.rb', line 90

def initialize(node, param)
  @node = node
  @param = param
end

Instance Method Details

#find_matchesObject


95
96
97
98
# File 'lib/reek/smells/control_parameter.rb', line 95

def find_matches
  return [] if legitimite_uses?
  nested_finders.flat_map(&:find_matches) + uses_of_param_in_condition
end

#legitimite_uses?Boolean

Returns:

  • (Boolean)

100
101
102
103
104
105
# File 'lib/reek/smells/control_parameter.rb', line 100

def legitimite_uses?
  return true if uses_param_in_body?
  return true if uses_param_in_call_in_condition?
  return true if nested_finders.any?(&:legitimite_uses?)
  false
end