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'
Constants inherited from SmellDetector
SmellDetector::ENABLED_KEY, SmellDetector::EXCLUDE_KEY
Class Method Summary collapse
Instance Method Summary collapse
-
#examine_context(ctx, report) ⇒ Object
Checks the number of parameters in the given scope.
-
#initialize(config) ⇒ LongParameterList
constructor
A new instance of LongParameterList.
Methods inherited from SmellDetector
class_name, contexts, #examine, #exception?, listen, #smell_name
Constructor Details
#initialize(config) ⇒ LongParameterList
Returns a new instance of LongParameterList.
25 26 27 28 29 |
# File 'lib/reek/smells/long_parameter_list.rb', line 25 def initialize(config) super @max_params = config['max_params'] @action = 'has' end |
Class Method Details
.default_config ⇒ Object
21 22 23 |
# File 'lib/reek/smells/long_parameter_list.rb', line 21 def self.default_config super.adopt(MAX_ALLOWED_PARAMS_KEY => 3) end |
Instance Method Details
#examine_context(ctx, report) ⇒ Object
Checks the number of parameters in the given scope. Any smells found are added to the report
.
35 36 37 38 39 40 |
# File 'lib/reek/smells/long_parameter_list.rb', line 35 def examine_context(ctx, report) num_params = ctx.parameters.length return false if num_params <= @max_params report << SmellWarning.new(self, ctx, "#{@action} #{num_params} parameters") end |