Sha256: d598c4a5fad1ec1143688103d99cc2e71fa766aa529958f1efed6966443671b4

Contents?: true

Size: 1.63 KB

Versions: 7

Compression:

Stored size: 1.63 KB

Contents

require_relative 'smell_detector'
require_relative 'smell_warning'

module Reek
  module Smells
    #
    # A Large Class is a class or module that has a large number of
    # instance variables, methods or lines of code.
    #
    # +TooManyMethods+ reports classes having more than a configurable number
    # of methods. The method count includes public, protected and private
    # methods, and excludes methods inherited from superclasses or included
    # modules.
    #
    # See {file:docs/Too-Many-Methods.md} for details.
    # @api private
    class TooManyMethods < SmellDetector
      # The name of the config field that sets the maximum number of methods
      # permitted in a class.
      MAX_ALLOWED_METHODS_KEY = 'max_methods'
      DEFAULT_MAX_METHODS = 25

      def self.smell_category
        'LargeClass'
      end

      def self.contexts # :nodoc:
        [:class]
      end

      def self.default_config
        super.merge(
          MAX_ALLOWED_METHODS_KEY => DEFAULT_MAX_METHODS,
          EXCLUDE_KEY => []
        )
      end

      #
      # Checks +ctx+ for too many methods
      #
      # @return [Array<SmellWarning>]
      #
      def examine_context(ctx)
        @max_allowed_methods = value(MAX_ALLOWED_METHODS_KEY, ctx, DEFAULT_MAX_METHODS)
        actual = ctx.node_instance_methods.length
        return [] if actual <= @max_allowed_methods
        [SmellWarning.new(self,
                          context: ctx.full_name,
                          lines: [ctx.exp.line],
                          message:  "has at least #{actual} methods",
                          parameters: { count: actual })]
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
reek-3.2.1 lib/reek/smells/too_many_methods.rb
reek-3.1 lib/reek/smells/too_many_methods.rb
reek-3.0.4 lib/reek/smells/too_many_methods.rb
reek-3.0.3 lib/reek/smells/too_many_methods.rb
reek-3.0.2 lib/reek/smells/too_many_methods.rb
reek-3.0.1 lib/reek/smells/too_many_methods.rb
reek-3.0.0 lib/reek/smells/too_many_methods.rb