Parent

Class/Module Index [+]

Quicksearch

Reek::Smells::LongMethod

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

Currently LongMethod reports any method with more than 5 statements.

Constants

DEFAULT_MAX_STATEMENTS
MAX_ALLOWED_STATEMENTS_KEY

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

SMELL_CLASS
STATEMENT_COUNT_KEY
SUBCLASS_TOO_MANY_STATEMENTS

Public Class Methods

default_config() click to toggle source
# File lib/reek/smells/long_method.rb, line 26
def self.default_config
  super.adopt(
    MAX_ALLOWED_STATEMENTS_KEY => DEFAULT_MAX_STATEMENTS,
    EXCLUDE_KEY => ['initialize']
  )
end
new(source, config = LongMethod.default_config) click to toggle source
# File lib/reek/smells/long_method.rb, line 33
def initialize(source, config = LongMethod.default_config)
  super(source, config)
end

Public Instance Methods

examine_context(ctx) click to toggle source

Checks the length of the given method.

@return [Array<SmellWarning>]

# File lib/reek/smells/long_method.rb, line 42
def examine_context(ctx)
  @max_allowed_statements = value(MAX_ALLOWED_STATEMENTS_KEY, ctx, DEFAULT_MAX_STATEMENTS)
  num = ctx.num_statements
  return [] if num <= @max_allowed_statements
  smell = SmellWarning.new(SMELL_CLASS, ctx.full_name, [ctx.exp.line],
    "has approx #{num} statements",
    @source, SUBCLASS_TOO_MANY_STATEMENTS,
    {STATEMENT_COUNT_KEY => num})
  [smell]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.