Sha256: 48b3d8330634dc82eea7e7d808ef17bba22c19c2dcb1f89c2cc0a26e2375152b

Contents?: true

Size: 926 Bytes

Versions: 13

Compression:

Stored size: 926 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.
      # Remembers any smells found.
      #
      def examine_context(method)
        return false if method.calls.keys.length == 0 or
          method.num_statements == 0 or
          method.depends_on_instance?
        found(method, "doesn't depend on instance state")
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
kevinrutherford-reek-1.1.3.10 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.11 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.12 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.13 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.14 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.15 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.3 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.4 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.5 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.6 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.7 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.8 lib/reek/smells/utility_function.rb
kevinrutherford-reek-1.1.3.9 lib/reek/smells/utility_function.rb