Sha256: 5ea2490b2e4d7a97cecc2e96a0de13bf90308855e2d8ab1590ebc1dbae269e33

Contents?: true

Size: 1.11 KB

Versions: 15

Compression:

Stored size: 1.11 KB

Contents

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

module Reek
  module Smells

    #
    # A Long Method is any method that has a large number of lines.
    #
    # Currently +LongMethod+ reports any method with more than
    # 5 statements.
    #
    class LongMethod < SmellDetector

      # The name of the config field that sets the maximum number of
      # statements permitted in any method.
      MAX_ALLOWED_STATEMENTS_KEY = 'max_statements'

      def self.default_config
        super.adopt(
          MAX_ALLOWED_STATEMENTS_KEY => 5,
          EXCLUDE_KEY => ['initialize']
        )
      end

      def initialize(config = LongMethod.default_config)
        super
        @max_statements = config[MAX_ALLOWED_STATEMENTS_KEY]
      end

      #
      # Checks the length of the given +method+.
      # Any smells found are added to the +report+.
      #
      def examine_context(method, report)
        num = method.num_statements
        return false if num <= @max_statements
        report << SmellWarning.new(self, method,
                    "has approx #{num} statements")
      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/long_method.rb
kevinrutherford-reek-0.3.1.5 lib/reek/smells/long_method.rb
kevinrutherford-reek-0.3.1.6 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.0.0 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.0.1 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.1.1 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.1.2.1 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.1.2 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.1.3.1 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.1.3.2 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.1.3 lib/reek/smells/long_method.rb
teksymmetry-reek-1.1.3.1 lib/reek/smells/long_method.rb
teksymmetry-reek-1.1.3.2 lib/reek/smells/long_method.rb
reek-1.1.3 lib/reek/smells/long_method.rb
reek-1.0.0 lib/reek/smells/long_method.rb