Class: Reek::SmellDetectors::TooManyStatements

Inherits:
BaseDetector
  • Object
show all
Defined in:
lib/reek/smell_detectors/too_many_statements.rb

Overview

A Long Method is any method that has a large number of lines.

TooManyStatements reports any method with more than 5 statements.

See Too-Many-Statements for details.

Constant Summary collapse

MAX_ALLOWED_STATEMENTS_KEY =

The name of the config field that sets the maximum number of statements permitted in any method.

'max_statements'
DEFAULT_MAX_STATEMENTS =
5

Constants inherited from BaseDetector

BaseDetector::DEFAULT_EXCLUDE_SET, BaseDetector::EXCLUDE_KEY

Instance Attribute Summary

Attributes inherited from BaseDetector

#config, #context

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseDetector

#config_for, configuration_keys, contexts, descendants, #enabled?, #exception?, #expression, inherited, #initialize, #run, #smell_type, smell_type, #smell_warning, #source_line, to_detector, todo_configuration_for, #value

Constructor Details

This class inherits a constructor from Reek::SmellDetectors::BaseDetector

Class Method Details

.default_configObject



19
20
21
22
23
# File 'lib/reek/smell_detectors/too_many_statements.rb', line 19

def self.default_config
  super.merge(
    MAX_ALLOWED_STATEMENTS_KEY => DEFAULT_MAX_STATEMENTS,
    EXCLUDE_KEY => ['initialize'])
end

Instance Method Details

#max_allowed_statementsObject (private)



42
43
44
# File 'lib/reek/smell_detectors/too_many_statements.rb', line 42

def max_allowed_statements
  value(MAX_ALLOWED_STATEMENTS_KEY, context)
end

#sniffArray<SmellWarning>

Checks the length of the given method.

Returns:



30
31
32
33
34
35
36
37
38
# File 'lib/reek/smell_detectors/too_many_statements.rb', line 30

def sniff
  count = context.number_of_statements
  return [] if count <= max_allowed_statements

  [smell_warning(
    lines: [source_line],
    message: "has approx #{count} statements",
    parameters: { count: count })]
end