ProxyTestService#perform has approx 9 statements Open
def perform
- Read upRead up
- Exclude checks
A method with Too Many Statements
is any method that has a large number of lines.
Too Many Statements
warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements
counts +1 for every simple statement in a method and +1 for every statement within a control structure (if
, else
, case
, when
, for
, while
, until
, begin
, rescue
) but it doesn't count the control structure itself.
So the following method would score +6 in Reek's statement-counting algorithm:
def parse(arg, argv, &error)
if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
return nil, block, nil # +1
end
opt = (val = parse_arg(val, &error))[1] # +2
val = conv_arg(*val) # +3
if opt and !arg
argv.shift # +4
else
val[0] = nil # +5
end
val # +6
end
(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)
ProxyTestService::ProxyResponse has initialize method Open
module ProxyResponse
- Read upRead up
- Exclude checks
A module is usually a mixin, so when an #initialize
method is present it is
hard to tell initialization order and parameters so having #initialize
in a module is usually a bad idea.
Example
The Foo
module below contains a method initialize
. Although class B
inherits from A
, the inclusion of Foo
stops A#initialize
from being called.
class A
def initialize(a)
@a = a
end
end
module Foo
def initialize(foo)
@foo = foo
end
end
class B < A
include Foo
def initialize(b)
super('bar')
@b = b
end
end
A simple solution is to rename Foo#initialize
and call that method by name:
module Foo
def setup_foo_module(foo)
@foo = foo
end
end
class B < A
include Foo
def initialize(b)
super 'bar'
setup_foo_module('foo')
@b = b
end
end