Sha256: 2ebfd3ad430281696a3880520f41a93926658d6cb641f7281071a5bf6ac8ffbb

Contents?: true

Size: 1.48 KB

Versions: 27

Compression:

Stored size: 1.48 KB

Contents

# frozen_string_literal: true

require_relative 'base_detector'

module Reek
  module SmellDetectors
    #
    # 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.
    class TooManyMethods < BaseDetector
      # 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 = 15

      def self.contexts
        [:class]
      end

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

      #
      # Checks context for too many methods
      #
      # @return [Array<SmellWarning>]
      #
      def sniff
        # TODO: Only checks instance methods!
        actual = context.node_instance_methods.length
        return [] if actual <= max_allowed_methods

        [smell_warning(
          lines: [source_line],
          message: "has at least #{actual} methods",
          parameters: { count: actual })]
      end

      private

      def max_allowed_methods
        value(MAX_ALLOWED_METHODS_KEY, context)
      end
    end
  end
end

Version data entries

27 entries across 25 versions & 2 rubygems

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