Class: Reek::Smells::DuplicateMethodCall Private
- Inherits:
-
SmellDetector
- Object
- SmellDetector
- Reek::Smells::DuplicateMethodCall
- Defined in:
- lib/reek/smells/duplicate_method_call.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.
Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.
DuplicateMethodCall
checks for repeated identical method calls within any one method definition. For example, the following method will report a warning:
def double_thing()
@other.thing + @other.thing
end
See Duplicate-Method-Call for details.
Defined Under Namespace
Classes: CallCollector, FoundCall
Constant Summary collapse
- MAX_ALLOWED_CALLS_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 number of identical calls to be permitted within any single method.
'max_calls'
- DEFAULT_MAX_CALLS =
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.
1
- ALLOW_CALLS_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 names of any methods for which identical calls should be to be permitted within any single method.
'allow_calls'
- DEFAULT_ALLOW_CALLS =
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.
[]
Constants inherited from SmellDetector
SmellDetector::DEFAULT_EXCLUDE_SET, SmellDetector::EXCLUDE_KEY
Instance Attribute Summary
Attributes inherited from SmellDetector
Class Method Summary collapse
- .default_config ⇒ Object private
- .smell_category ⇒ Object private
Instance Method Summary collapse
-
#examine_context(ctx) ⇒ Array<SmellWarning>
private
Looks for duplicate calls within the body of the method
ctx
.
Methods inherited from SmellDetector
#config_for, #configure_with, contexts, default_smell_category, descendants, #enabled?, #enabled_for?, #examine, #exception?, #initialize, #register, #report_on, #smell_category, #smell_type, smell_type, #value
Constructor Details
This class inherits a constructor from Reek::Smells::SmellDetector
Class Method Details
.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.
37 38 39 40 41 42 |
# File 'lib/reek/smells/duplicate_method_call.rb', line 37 def self.default_config super.merge( MAX_ALLOWED_CALLS_KEY => DEFAULT_MAX_CALLS, ALLOW_CALLS_KEY => DEFAULT_ALLOW_CALLS ) end |
.smell_category ⇒ 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.
33 34 35 |
# File 'lib/reek/smells/duplicate_method_call.rb', line 33 def self.smell_category 'Duplication' 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.
Looks for duplicate calls within the body of the method ctx
.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/reek/smells/duplicate_method_call.rb', line 49 def examine_context(ctx) max_allowed_calls = value(MAX_ALLOWED_CALLS_KEY, ctx, DEFAULT_MAX_CALLS) allow_calls = value(ALLOW_CALLS_KEY, ctx, DEFAULT_ALLOW_CALLS) collector = CallCollector.new(ctx, max_allowed_calls, allow_calls) collector.smelly_calls.map do |found_call| SmellWarning.new self, context: ctx.full_name, lines: found_call.lines, message: "calls #{found_call.call} #{found_call.occurs} times", parameters: { name: found_call.call, count: found_call.occurs } end end |