Class: Reek::Smells::DataClump
- Inherits:
-
SmellDetector
- Object
- SmellDetector
- Reek::Smells::DataClump
- Defined in:
- lib/reek/smells/data_clump.rb
Overview
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.
Constant Summary collapse
- MAX_COPIES_KEY =
The name of the config field that sets the maximum allowed copies of any clump.
'max_copies'
- DEFAULT_MAX_COPIES =
2
- MIN_CLUMP_SIZE_KEY =
'min_clump_size'
- DEFAULT_MIN_CLUMP_SIZE =
2
Constants inherited from SmellDetector
SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY
Class Method Summary collapse
Instance Method Summary collapse
-
#examine_context(klass) ⇒ Object
Checks the given ClassContext for multiple identical conditional tests.
-
#initialize(config = DataClump.default_config) ⇒ DataClump
constructor
A new instance of DataClump.
Methods inherited from SmellDetector
class_name, #configure, #configure_with, #copy, create, #enabled?, #examine, #exception?, #found, #has_smell?, listen, #listen_to, #num_smells, #report_on, #smell_name, #smelly?, #supersede_with, #value
Constructor Details
#initialize(config = DataClump.default_config) ⇒ DataClump
Returns a new instance of DataClump.
42 43 44 |
# File 'lib/reek/smells/data_clump.rb', line 42 def initialize(config = DataClump.default_config) super(config) end |
Class Method Details
.contexts ⇒ Object
:nodoc:
22 23 24 |
# File 'lib/reek/smells/data_clump.rb', line 22 def self.contexts # :nodoc: [:class] end |
.default_config ⇒ Object
35 36 37 38 39 40 |
# File 'lib/reek/smells/data_clump.rb', line 35 def self.default_config super.adopt( MAX_COPIES_KEY => DEFAULT_MAX_COPIES, MIN_CLUMP_SIZE_KEY => DEFAULT_MIN_CLUMP_SIZE ) end |
.print_clump(clump) ⇒ Object
58 59 60 |
# File 'lib/reek/smells/data_clump.rb', line 58 def self.print_clump(clump) "[#{clump.map {|name| name.to_s}.join(', ')}]" end |
Instance Method Details
#examine_context(klass) ⇒ Object
Checks the given ClassContext for multiple identical conditional tests. Remembers any smells found.
50 51 52 53 54 55 56 |
# File 'lib/reek/smells/data_clump.rb', line 50 def examine_context(klass) max_copies = value(MAX_COPIES_KEY, klass, DEFAULT_MAX_COPIES) min_clump_size = value(MIN_CLUMP_SIZE_KEY, klass, DEFAULT_MIN_CLUMP_SIZE) MethodGroup.new(klass, min_clump_size, max_copies).clumps.each do |clump, occurs| found(klass, "takes parameters #{DataClump.print_clump(clump)} to #{occurs} methods") end end |