Sha256: 331ab02ab2662f8ae981c183d5de37680d2bdb4c546113712840ddebe8f60a4c

Contents?: true

Size: 1.4 KB

Versions: 12

Compression:

Stored size: 1.4 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.
    #
    # +TooManyStatements+ reports any method with more than 5 statements.
    #
    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 examine_context(ctx)
        @max_allowed_statements = value(MAX_ALLOWED_STATEMENTS_KEY,
                                        ctx,
                                        DEFAULT_MAX_STATEMENTS)
        count = ctx.num_statements
        return [] if count <= @max_allowed_statements
        [SmellWarning.new(self,
                          context: ctx.full_name,
                          lines: [ctx.exp.line],
                          message: "has approx #{count} statements",
                          parameters: { count: count })]
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
reek-2.0.4 lib/reek/smells/too_many_statements.rb
reek-2.0.3 lib/reek/smells/too_many_statements.rb
reek-2.0.2 lib/reek/smells/too_many_statements.rb
reek-2.0.1 lib/reek/smells/too_many_statements.rb
reek-2.0.0 lib/reek/smells/too_many_statements.rb
reek-1.6.6 lib/reek/smells/too_many_statements.rb
reek-1.6.5 lib/reek/smells/too_many_statements.rb
reek-1.6.4 lib/reek/smells/too_many_statements.rb
reek-1.6.3 lib/reek/smells/too_many_statements.rb
reek-1.6.2 lib/reek/smells/too_many_statements.rb
reek-1.6.1 lib/reek/smells/too_many_statements.rb
reek-1.6.0 lib/reek/smells/too_many_statements.rb