activemodel/lib/active_model/validations/length.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Method validate_each has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

      def validate_each(record, attribute, value)
        value_length = value.respond_to?(:length) ? value.length : value.to_s.length
        errors_options = options.except(*RESERVED_OPTIONS)

        CHECKS.each do |key, validity_check|
Severity: Minor
Found in activemodel/lib/active_model/validations/length.rb - About 2 hrs to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Method initialize has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

      def initialize(options)
        if range = (options.delete(:in) || options.delete(:within))
          raise ArgumentError, ":in and :within must be a Range" unless range.is_a?(Range)
          options[:minimum] = range.min if range.begin
          options[:maximum] = (range.exclude_end? ? range.end - 1 : range.end) if range.end
Severity: Minor
Found in activemodel/lib/active_model/validations/length.rb - About 1 hr to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

Consider simplifying this complex logical expression.
Open

          unless (value.is_a?(Integer) && value >= 0) ||
                  value == Float::INFINITY || value == -Float::INFINITY ||
                  value.is_a?(Symbol) || value.is_a?(Proc)
            raise ArgumentError, ":#{key} must be a non-negative Integer, Infinity, Symbol, or Proc"
          end
Severity: Major
Found in activemodel/lib/active_model/validations/length.rb - About 40 mins to fix

    Method check_validity! has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def check_validity!
            keys = CHECKS.keys & options.keys
    
            if keys.empty?
              raise ArgumentError, "Range unspecified. Specify the :in, :within, :maximum, :minimum, or :is option."
    Severity: Minor
    Found in activemodel/lib/active_model/validations/length.rb - About 25 mins to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    There are no issues that match your filters.

    Category
    Status