Sha256: 276f9a0c1c278d400949fa17407c30ca129d2fca5e86d3c6326dcaf344012cf2

Contents?: true

Size: 1.37 KB

Versions: 8

Compression:

Stored size: 1.37 KB

Contents

require_relative 'smell_detector'
require_relative 'smell_warning'

module Reek
  module Smells
    #
    # A Long Method is any method that has a large number of lines.
    #
    # +TooManyStatements+ reports any method with more than 5 statements.
    #
    # See {file:docs/Too-Many-Statements.md} for details.
    class TooManyStatements < SmellDetector
      # The name of the config field that sets the maximum number of
      # statements permitted in any method.
      MAX_ALLOWED_STATEMENTS_KEY = 'max_statements'
      DEFAULT_MAX_STATEMENTS = 5

      def self.smell_category
        'LongMethod'
      end

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

      #
      # Checks the length of the given +method+.
      #
      # @return [Array<SmellWarning>]
      #
      def inspect(ctx)
        max_allowed_statements = value(MAX_ALLOWED_STATEMENTS_KEY,
                                       ctx,
                                       DEFAULT_MAX_STATEMENTS)
        count = ctx.number_of_statements
        return [] if count <= max_allowed_statements
        [smell_warning(
          context: ctx,
          lines: [ctx.exp.line],
          message: "has approx #{count} statements",
          parameters: { count: count })]
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
reek-3.10.1 lib/reek/smells/too_many_statements.rb
reek-3.10.0 lib/reek/smells/too_many_statements.rb
reek-3.9.1 lib/reek/smells/too_many_statements.rb
reek-3.9.0 lib/reek/smells/too_many_statements.rb
reek-3.8.3 lib/reek/smells/too_many_statements.rb
reek-3.8.2 lib/reek/smells/too_many_statements.rb
reek-3.8.1 lib/reek/smells/too_many_statements.rb
reek-3.8.0 lib/reek/smells/too_many_statements.rb