lib/reek/smells/feature_envy.rb in reek-2.0.4 vs lib/reek/smells/feature_envy.rb in reek-2.1.0
- old
+ new
@@ -1,7 +1,7 @@
-require 'reek/smells/smell_detector'
-require 'reek/smell_warning'
+require_relative 'smell_detector'
+require_relative '../smell_warning'
module Reek
module Smells
#
# Feature Envy occurs when a code fragment references another object
@@ -28,10 +28,13 @@
# in the unwilling host class.
#
# Currently +FeatureEnvy+ reports any method that refers to self less
# often than it refers to (ie. send messages to) some other object.
#
+ # If the method doesn't reference self at all, +UtilityFunction+ is
+ # reported instead.
+ #
class FeatureEnvy < SmellDetector
def self.smell_category
'LowCohesion'
end
@@ -40,9 +43,10 @@
# might "belong" on another class.
#
# @return [Array<SmellWarning>]
#
def examine_context(method_ctx)
+ return [] unless method_ctx.references_self?
method_ctx.envious_receivers.map do |ref, occurs|
target = ref.to_s
SmellWarning.new self,
context: method_ctx.full_name,
lines: [method_ctx.exp.line],