forked from troessner/reek
-
Notifications
You must be signed in to change notification settings - Fork 0
/
long_parameter_list.rb
41 lines (35 loc) · 1.11 KB
/
long_parameter_list.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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 = LongParameterList.default_config)
super(config)
@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 <= @config['max_params']
found(ctx, "#{@action} #{num_params} parameters")
end
end
end
end