Class: Reek::Smells::DataClump Private
- Inherits:
-
SmellDetector
- Object
- SmellDetector
- Reek::Smells::DataClump
- Defined in:
- lib/reek/smells/data_clump.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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.
See Data-Clump for details.
Constant Summary collapse
- MAX_COPIES_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
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.
'max_copies'
- DEFAULT_MAX_COPIES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
2
- MIN_CLUMP_SIZE_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
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.
'min_clump_size'
- DEFAULT_MIN_CLUMP_SIZE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
2
Constants inherited from SmellDetector
SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY
Instance Attribute Summary
Attributes inherited from SmellDetector
Class Method Summary collapse
-
.contexts ⇒ Object
private
:nodoc:.
- .default_config ⇒ Object private
Instance Method Summary collapse
-
#examine_context(ctx) ⇒ Array<SmellWarning>
private
Checks the given class or module for multiple identical parameter sets.
Methods inherited from SmellDetector
#config_for, #configure_with, default_smell_category, descendants, #enabled?, #enabled_for?, #examine, #exception?, #initialize, #register, #report_on, smell_category, #smell_category, #smell_type, smell_type, #value
Constructor Details
This class inherits a constructor from Reek::Smells::SmellDetector
Class Method Details
.contexts ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
:nodoc:
38 39 40 |
# File 'lib/reek/smells/data_clump.rb', line 38 def self.contexts # :nodoc: [:class, :module] end |
.default_config ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
42 43 44 45 46 47 |
# File 'lib/reek/smells/data_clump.rb', line 42 def self.default_config super.merge( MAX_COPIES_KEY => DEFAULT_MAX_COPIES, MIN_CLUMP_SIZE_KEY => DEFAULT_MIN_CLUMP_SIZE ) end |
Instance Method Details
#examine_context(ctx) ⇒ Array<SmellWarning>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks the given class or module for multiple identical parameter sets.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/reek/smells/data_clump.rb', line 54 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| print_clump = DataClump.print_clump(clump) SmellWarning.new self, context: ctx.full_name, lines: methods.map(&:line), message: "takes parameters #{print_clump} " \ "to #{methods.length} methods", parameters: { parameters: clump.map(&:to_s), count: methods.length, methods: methods.map(&:name) } end end |