Parent

Class/Module Index [+]

Quicksearch

Reek::Smells::LongParameterList

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.

Constants

DEFAULT_MAX_ALLOWED_PARAMS

The default value of the MAX_ALLOWED_PARAMS_KEY configuration value.

MAX_ALLOWED_PARAMS_KEY

The name of the config field that sets the maximum number of parameters permitted in any method or block.

PARAMETER_COUNT_KEY
SMELL_CLASS
SMELL_SUBCLASS

Public Class Methods

default_config() click to toggle source
# File lib/reek/smells/long_parameter_list.rb, line 31
def self.default_config
  super.adopt(
    MAX_ALLOWED_PARAMS_KEY => DEFAULT_MAX_ALLOWED_PARAMS,
    Core::SmellConfiguration::OVERRIDES_KEY => {
      "initialize" => {MAX_ALLOWED_PARAMS_KEY => 5}
      }
  )
end
new(source, config = LongParameterList.default_config) click to toggle source
# File lib/reek/smells/long_parameter_list.rb, line 40
def initialize(source, config = LongParameterList.default_config)
  super(source, config)
end

Public Instance Methods

examine_context(ctx) click to toggle source

Checks the number of parameters in the given method.

@return [Array<SmellWarning>]

# File lib/reek/smells/long_parameter_list.rb, line 49
def examine_context(ctx)
  @max_allowed_params = value(MAX_ALLOWED_PARAMS_KEY, ctx, DEFAULT_MAX_ALLOWED_PARAMS)
  num_params = ctx.exp.arg_names.length
  return [] if num_params <= @max_allowed_params
  smell = SmellWarning.new(SMELL_CLASS, ctx.full_name, [ctx.exp.line],
    "has #{num_params} parameters",
    @source, SMELL_SUBCLASS,
    {PARAMETER_COUNT_KEY => num_params})
  [smell]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.