Sha256: 3487bf832316e2d2cc45456afca9adca9d135b24008820c3246b3e796e19f71a

Contents?: true

Size: 1.21 KB

Versions: 28

Compression:

Stored size: 1.21 KB

Contents

# frozen_string_literal: true

require_relative 'base_detector'

module Reek
  module SmellDetectors
    #
    # 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 < BaseDetector
      # 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.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 sniff
        count = context.number_of_statements
        return [] if count <= max_allowed_statements

        [smell_warning(
          lines: [source_line],
          message: "has approx #{count} statements",
          parameters: { count: count })]
      end

      private

      def max_allowed_statements
        value(MAX_ALLOWED_STATEMENTS_KEY, context)
      end
    end
  end
end

Version data entries

28 entries across 26 versions & 2 rubygems

Version Path
reek-6.4.0 lib/reek/smell_detectors/too_many_statements.rb
reek-6.3.0 lib/reek/smell_detectors/too_many_statements.rb
reek-6.2.0 lib/reek/smell_detectors/too_many_statements.rb
reek-6.1.4 lib/reek/smell_detectors/too_many_statements.rb
reek-6.1.3 lib/reek/smell_detectors/too_many_statements.rb
reek-6.1.2 lib/reek/smell_detectors/too_many_statements.rb
reek-6.1.1 lib/reek/smell_detectors/too_many_statements.rb
reek-6.1.0 lib/reek/smell_detectors/too_many_statements.rb
reek-6.0.6 lib/reek/smell_detectors/too_many_statements.rb
reek-6.0.5 lib/reek/smell_detectors/too_many_statements.rb
reek-6.0.4 lib/reek/smell_detectors/too_many_statements.rb
reek-6.0.3 lib/reek/smell_detectors/too_many_statements.rb
reek-6.0.2 lib/reek/smell_detectors/too_many_statements.rb
reek-6.0.1 lib/reek/smell_detectors/too_many_statements.rb
reek-6.0.0 lib/reek/smell_detectors/too_many_statements.rb
reek-5.6.0 lib/reek/smell_detectors/too_many_statements.rb
reek-5.5.0 lib/reek/smell_detectors/too_many_statements.rb
reek-5.4.1 lib/reek/smell_detectors/too_many_statements.rb
reek-5.4.0 lib/reek/smell_detectors/too_many_statements.rb
reek-5.3.2 lib/reek/smell_detectors/too_many_statements.rb