Class: Reek::Smells::LongParameterList Private
- Inherits:
-
SmellDetector
- Object
- SmellDetector
- Reek::Smells::LongParameterList
- Defined in:
- lib/reek/smells/long_parameter_list.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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.
See Long-Parameter-List for details.
Constant Summary collapse
- MAX_ALLOWED_PARAMS_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
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 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
3
Constants inherited from SmellDetector
SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY
Instance Attribute Summary
Attributes inherited from SmellDetector
Class Method Summary collapse
- .default_config ⇒ Object private
Instance Method Summary collapse
-
#examine_context(ctx) ⇒ Array<SmellWarning>
private
Checks the number of parameters in the given method.
Methods inherited from SmellDetector
#config_for, #configure_with, contexts, default_smell_category, descendants, #enabled?, #enabled_for?, #examine, #exception?, #initialize, #register, #report_on, smell_category, #smell_category, smell_type, #smell_type, #value
Constructor Details
This class inherits a constructor from Reek::Smells::SmellDetector
Class Method Details
.default_config ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
23 24 25 26 27 28 29 30 |
# File 'lib/reek/smells/long_parameter_list.rb', line 23 def self.default_config super.merge( MAX_ALLOWED_PARAMS_KEY => DEFAULT_MAX_ALLOWED_PARAMS, SmellConfiguration::OVERRIDES_KEY => { 'initialize' => { MAX_ALLOWED_PARAMS_KEY => 5 } } ) end |
Instance Method Details
#examine_context(ctx) ⇒ Array<SmellWarning>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks the number of parameters in the given method.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/reek/smells/long_parameter_list.rb', line 37 def examine_context(ctx) @max_allowed_params = value(MAX_ALLOWED_PARAMS_KEY, ctx, DEFAULT_MAX_ALLOWED_PARAMS) count = ctx.exp.arg_names.length return [] if count <= @max_allowed_params [SmellWarning.new(self, context: ctx.full_name, lines: [ctx.exp.line], message: "has #{count} parameters", parameters: { count: count })] end |