class Reek::SmellDetectors::DuplicateMethodCall::CallCollector
Collects all calls in a given context
Attributes
Public Class Methods
Source
# File lib/reek/smell_detectors/duplicate_method_call.rb, line 100 def initialize(context, max_allowed_calls, allow_calls) @context = context @max_allowed_calls = max_allowed_calls @allow_calls = allow_calls end
Public Instance Methods
Source
# File lib/reek/smell_detectors/duplicate_method_call.rb, line 106 def calls result = Hash.new { |hash, key| hash[key] = FoundCall.new(key) } collect_calls(result) result.values.sort_by(&:call) end
Source
# File lib/reek/smell_detectors/duplicate_method_call.rb, line 112 def smelly_calls calls.select { |found_call| smelly_call? found_call } end
Private Instance Methods
Source
# File lib/reek/smell_detectors/duplicate_method_call.rb, line 143 def allow_calls?(method) allow_calls.any? { |allow| /#{allow}/ =~ method } end
Source
# File lib/reek/smell_detectors/duplicate_method_call.rb, line 122 def collect_calls(result) context.local_nodes(:send, [:mlhs]) do |call_node| next if call_node.object_creation_call? next if simple_method_call? call_node result[call_node].record(call_node) end context.local_nodes(:block) do |call_node| result[call_node].record(call_node) end end
@quality :reek:TooManyStatements { max_statements: 6 } @quality :reek:DuplicateMethodCall { max_calls: 2 }
Source
# File lib/reek/smell_detectors/duplicate_method_call.rb, line 139 def simple_method_call?(call_node) !call_node.receiver && call_node.args.empty? end
@quality :reek:UtilityFunction
Source
# File lib/reek/smell_detectors/duplicate_method_call.rb, line 134 def smelly_call?(found_call) found_call.occurs > max_allowed_calls && !allow_calls?(found_call.call) end