lib/reek/smells/feature_envy.rb in reek-1.2.7.1 vs lib/reek/smells/feature_envy.rb in reek-1.2.7.2
- old
+ new
@@ -1,8 +1,7 @@
require File.join( File.dirname( File.expand_path(__FILE__)), 'smell_detector')
require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'smell_warning')
-require File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'source')
module Reek
module Smells
#
@@ -33,20 +32,26 @@
# often than it refers to (ie. send messages to) some other object.
#
class FeatureEnvy < SmellDetector
include ExcludeInitialize
+ SMELL_CLASS = 'LowCohesion'
+ SMELL_SUBCLASS = self.name.split(/::/)[-1]
+
+ RECEIVER_KEY = 'receiver'
+ REFERENCES_KEY = 'references'
+
#
# Checks whether the given +context+ includes any code fragment that
# might "belong" on another class.
# Remembers any smells found.
#
def examine_context(method_ctx)
method_ctx.envious_receivers.each do |ref, occurs|
- target = Source::SexpFormatter.format(ref)
- smell = SmellWarning.new('LowCohesion', method_ctx.full_name, [method_ctx.exp.line],
+ target = ref.format
+ smell = SmellWarning.new(SMELL_CLASS, method_ctx.full_name, [method_ctx.exp.line],
"refers to #{target} more than self", @masked,
- @source, 'FeatureEnvy', {'receiver' => target, 'references' => occurs})
+ @source, SMELL_SUBCLASS, {RECEIVER_KEY => target, REFERENCES_KEY => occurs})
@smells_found << smell
#SMELL: serious duplication
end
end
end