Class Roodi::Checks::ParameterNumberCheck
In: lib/roodi/checks/parameter_number_check.rb
Parent: Roodi::Checks::Check

Checks a method to make sure the number of parameters it has is under the specified limit.

A method taking too many parameters is a code smell that indicates it might be doing too much, or that the parameters should be grouped into one or more objects of their own. It probably needs some refactoring.

Methods

Constants

DEFAULT_PARAMETER_COUNT = 5

Public Class methods

[Source]

# File lib/roodi/checks/parameter_number_check.rb, line 13
      def initialize(options = {})
        super()
        @parameter_count = options['parameter_count'] || DEFAULT_PARAMETER_COUNT
      end

Public Instance methods

[Source]

# File lib/roodi/checks/parameter_number_check.rb, line 22
      def evaluate_start(node)
        method_name = node[1]
        arguments = node[2]
        parameter_count = arguments.inject(-1) { |count, each| count = count + (each.class == Symbol ? 1 : 0) }
        add_error "Method name \"#{method_name}\" has #{parameter_count} parameters.  It should have #{@parameter_count} or less." unless parameter_count <= @parameter_count
      end

[Source]

# File lib/roodi/checks/parameter_number_check.rb, line 18
      def interesting_nodes
        [:defn]
      end

[Validate]