Parent

Class/Module Index [+]

Quicksearch

Reek::Smells::DataClump

A Data Clump occurs when the same two or three items frequently appear together in classes and parameter lists, or when a group of instance variable names start or end with similar substrings.

The recurrence of the items often means there is duplicate code spread around to handle them. There may be an abstraction missing from the code, making the system harder to understand.

Currently Reek looks for a group of two or more parameters with the same names that are expected by three or more methods of a class.

Constants

DEFAULT_MAX_COPIES
DEFAULT_MIN_CLUMP_SIZE
MAX_COPIES_KEY

The name of the config field that sets the maximum allowed copies of any clump. No group of common parameters will be reported as a DataClump unless there are more than this many methods containing those parameters.

METHODS_KEY
MIN_CLUMP_SIZE_KEY

The name of the config field that sets the minimum clump size. No group of common parameters will be reported as a DataClump unless it contains at least this many parameters.

OCCURRENCES_KEY
PARAMETERS_KEY
SMELL_CLASS

Public Class Methods

contexts() click to toggle source

@private

# File lib/reek/smells/data_clump.rb, line 38
def self.contexts
  [:class, :module]
end
default_config() click to toggle source
# File lib/reek/smells/data_clump.rb, line 59
def self.default_config
  super.adopt(
          MAX_COPIES_KEY => DEFAULT_MAX_COPIES,
          MIN_CLUMP_SIZE_KEY => DEFAULT_MIN_CLUMP_SIZE
  )
end
new(source, config = DataClump.default_config) click to toggle source
# File lib/reek/smells/data_clump.rb, line 66
def initialize(source, config = DataClump.default_config)
  super(source, config)
end

Public Instance Methods

examine_context(ctx) click to toggle source

Checks the given class or module for multiple identical parameter sets.

@return [Array<SmellWarning>]

# File lib/reek/smells/data_clump.rb, line 75
def examine_context(ctx)
  @max_copies = value(MAX_COPIES_KEY, ctx, DEFAULT_MAX_COPIES)
  @min_clump_size = value(MIN_CLUMP_SIZE_KEY, ctx, DEFAULT_MIN_CLUMP_SIZE)
  MethodGroup.new(ctx, @min_clump_size, @max_copies).clumps.map do |clump, methods|
    SmellWarning.new('DataClump', ctx.full_name,
                     methods.map {|meth| meth.line},
                     "takes parameters #{DataClump.print_clump(clump)} to #{methods.length} methods",
                     @source, 'DataClump', {
                    PARAMETERS_KEY => clump.map {|name| name.to_s},
                    OCCURRENCES_KEY => methods.length,
                    METHODS_KEY => methods.map {|meth| meth.name}
            })
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.