Sha256: 0f5927ecea8f3bcda233243a1bc37f1d86bea049cfb05c9bee6627e7bfe126ea

Contents?: true

Size: 922 Bytes

Versions: 4

Compression:

Stored size: 922 Bytes

Contents

# frozen_string_literal: true

require_relative 'base_detector'

module Reek
  module SmellDetectors
    #
    # A Manual Dispatch occurs when a method is only called after a
    # manual check that the method receiver is of the correct type.
    #
    # The +ManualDispatch+ checker reports any invocation of +respond_to?+
    #
    # See {file:docs/Manual-Dispatch.md} for details.
    class ManualDispatch < BaseDetector
      MESSAGE = 'manually dispatches method call'.freeze

      #
      # Checks for +respond_to?+ usage within the given method
      #
      # @return [Array<SmellWarning>]
      #
      # :reek:FeatureEnvy
      def sniff(ctx)
        smelly_nodes = ctx.each_node(:send).select { |node| node.name == :respond_to? }
        return [] if smelly_nodes.empty?
        lines = smelly_nodes.map(&:line)
        [smell_warning(context: ctx, lines: lines, message: MESSAGE)]
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
reek-4.7.2 lib/reek/smell_detectors/manual_dispatch.rb
reek-4.7.1 lib/reek/smell_detectors/manual_dispatch.rb
reek-4.7.0 lib/reek/smell_detectors/manual_dispatch.rb
reek-4.6.2 lib/reek/smell_detectors/manual_dispatch.rb