Class: Reek::Smells::LongParameterList
- Inherits:
-
SmellDetector
- Object
- SmellDetector
- Reek::Smells::LongParameterList
- Defined in:
- lib/reek/smells/long_parameter_list.rb
Overview
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.
Direct Known Subclasses
Constant Summary collapse
- MAX_ALLOWED_PARAMS_KEY =
The name of the config field that sets the maximum number of parameters permitted in any method or block.
'max_params'
- DEFAULT_MAX_ALLOWED_PARAMS =
The default value of the
MAX_ALLOWED_PARAMS_KEY
configuration value. 3
Constants inherited from SmellDetector
SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY
Class Method Summary collapse
Instance Method Summary collapse
-
#examine_context(ctx) ⇒ Object
Checks the number of parameters in the given scope.
-
#initialize(config = LongParameterList.default_config) ⇒ LongParameterList
constructor
A new instance of LongParameterList.
Methods inherited from SmellDetector
class_name, #configure, #configure_with, contexts, #copy, create, #enabled?, #examine, #exception?, #found, #has_smell?, listen, #listen_to, #num_smells, #report_on, #smell_name, #smelly?, #supersede_with, #value
Constructor Details
#initialize(config = LongParameterList.default_config) ⇒ LongParameterList
Returns a new instance of LongParameterList.
33 34 35 36 |
# File 'lib/reek/smells/long_parameter_list.rb', line 33 def initialize(config = LongParameterList.default_config) super(config) @action = 'has' end |
Class Method Details
.default_config ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/reek/smells/long_parameter_list.rb', line 24 def self.default_config super.adopt( MAX_ALLOWED_PARAMS_KEY => DEFAULT_MAX_ALLOWED_PARAMS, SmellConfiguration::OVERRIDES_KEY => { "initialize" => {MAX_ALLOWED_PARAMS_KEY => 5} } ) end |
Instance Method Details
#examine_context(ctx) ⇒ Object
Checks the number of parameters in the given scope. Remembers any smells found.
42 43 44 45 46 |
# File 'lib/reek/smells/long_parameter_list.rb', line 42 def examine_context(ctx) num_params = ctx.parameters.length return false if num_params <= value(MAX_ALLOWED_PARAMS_KEY, ctx, DEFAULT_MAX_ALLOWED_PARAMS) found(ctx, "#{@action} #{num_params} parameters") end |