Sha256: dc99add210940b1b27b7f2f39e26e8f6742fe678182478124dc5f1cb19e04700

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

require 'reek/smells/smell_detector'
require 'reek/smell_warning'

module Reek
  module Smells

    #
    # A Long Parameter List occurs when a method has more than one
    # or two parameters, or when a method yields more than one or
    # two objects to an associated block.
    #
    # Currently +LongParameterList+ reports any method or block with too
    # many parameters.
    #
    class LongParameterList < SmellDetector

      # The name of the config field that sets the maximum number of
      # parameters permitted in any method or block.
      MAX_ALLOWED_PARAMS_KEY = 'max_params'

      def self.default_config
        super.adopt(MAX_ALLOWED_PARAMS_KEY => 3)
      end

      def initialize(config)
        super
        @max_params = config['max_params']
        @action = 'has'
      end

      #
      # Checks the number of parameters in the given scope.
      # Remembers any smells found.
      #
      def examine_context(ctx)
        num_params = ctx.parameters.length
        return false if num_params <= @max_params
        found(ctx, "#{@action} #{num_params} parameters")
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
kevinrutherford-reek-1.1.3.3 lib/reek/smells/long_parameter_list.rb
kevinrutherford-reek-1.1.3.4 lib/reek/smells/long_parameter_list.rb
kevinrutherford-reek-1.1.3.5 lib/reek/smells/long_parameter_list.rb
kevinrutherford-reek-1.1.3.6 lib/reek/smells/long_parameter_list.rb
kevinrutherford-reek-1.1.3.7 lib/reek/smells/long_parameter_list.rb