Sha256: ef49cf623a8fa0d37521c13203e27e8cdbad47fc69278c2cc40af559fbd0b516

Contents?: true

Size: 999 Bytes

Versions: 15

Compression:

Stored size: 999 Bytes

Contents

require 'reek/smells/smell_detector'
require 'reek/smell_warning'

module Reek
  module Smells

    # 
    # A Utility Function is any instance method that has no
    # dependency on the state of the instance.
    # 
    # Currently +UtilityFunction+ will warn about any method that:
    # 
    # * is non-empty
    # * does not override an inherited method
    # * calls at least one method on another object
    # * doesn't use any of self's instance variables
    # * doesn't use any of self's methods
    #
    class UtilityFunction < SmellDetector

      #
      # Checks whether the given +method+ is a utility function.
      # Any smells found are added to the +report+.
      #
      def examine_context(method, report)
        return false if method.calls.keys.length == 0 or
          method.num_statements == 0 or
          method.depends_on_instance?
        report << SmellWarning.new(self, method,
                      "doesn't depend on instance state")
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 3 rubygems

Version Path
kevinrutherford-reek-0.3.1.4 lib/reek/smells/utility_function.rb
kevinrutherford-reek-0.3.1.5 lib/reek/smells/utility_function.rb
kevinrutherford-reek-0.3.1.6 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.0.0 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.0.1 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.1 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.2.1 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.2 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.1 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.2 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3 lib/reek/smells/utility_function.rb
teksymmetry-reek-1.1.3.1 lib/reek/smells/utility_function.rb
teksymmetry-reek-1.1.3.2 lib/reek/smells/utility_function.rb
reek-1.1.3 lib/reek/smells/utility_function.rb
reek-1.0.0 lib/reek/smells/utility_function.rb