Sha256: 4a66aeab83e62e7954317ca17bcd1815ecb33a53cc26c26cbab28e352b9751cf

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 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

      attr_reader :max_statements

      def initialize(config = LongMethod.default_config)
        super(config)
      end

      def max_statements
        @config['max_statements']
      end

      #
      # Checks the length of the given +method+.
      # Remembers any smells found.
      #
      def examine_context(method)
        num = method.num_statements
        return false if num <= max_statements
        found(method, "has approx #{num} statements")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kevinrutherford-reek-1.1.3.10 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.1.3.11 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.1.3.12 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.1.3.13 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.1.3.8 lib/reek/smells/long_method.rb
kevinrutherford-reek-1.1.3.9 lib/reek/smells/long_method.rb