joaquimadraz/compel

View on GitHub

Showing 11 of 14 total issues

Method validate has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

      def validate
        schemas.keys.each do |key|
          value = output[key].nil? ? input[key] : output[key]

          validator = TypeValidator.validate(value, schemas[key])
Severity: Minor
Found in lib/compel/validators/hash_validator.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

Method add has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def add(key, error)
      if error.nil? || error.empty?
        return
      end

Severity: Minor
Found in lib/compel/errors.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

Method validate has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

    def validate(value, type, options)
      if value.nil? && !!(options[:required] && options[:required][:value])
        return [options[:required][:message] || 'is required']
      end

Severity: Minor
Found in lib/compel/validation/validation.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

Method validate has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

      def validate
        input.each_with_index do |item, index|

          if !schema.required? && item.nil?
            next
Severity: Minor
Found in lib/compel/validators/array_validator.rb - About 55 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

Consider simplifying this complex logical expression.
Open

        if proc && proc.is_a?(Proc) &&
          (proc.arity == 1 || proc.arity == 0 &&
            (proc.call.is_a?(::Symbol) || proc.call.is_a?(::String)))
          proc
        else
Severity: Major
Found in lib/compel/builder/common.rb - About 40 mins to fix

    Method coerce_value has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def coerce_value
            @format = default_format
    
            if options[:format]
              @format = options[:format][:value]
    Severity: Minor
    Found in lib/compel/coercion/types/date_type.rb - About 35 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

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

          def valid?
            unless value.nil?
              _value = value.is_a?(Array) || value.is_a?(Hash) ? value.dup : "#{value}"
    
              return _value.length <= option_value
    Severity: Minor
    Found in lib/compel/validation/conditions/max_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

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

          def valid?
            unless value.nil?
              _value = value.is_a?(Array) || value.is_a?(Hash) ? value.dup : "#{value}"
    
              return option_value <= _value.length
    Severity: Minor
    Found in lib/compel/validation/conditions/min_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

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

          def array_valid?
            if !schema.required? && input.nil?
              return false
            end
    
    
    Severity: Minor
    Found in lib/compel/validators/array_validator.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

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

          def validate
            if !schema.required? && input.nil?
              return self
            end
    
    
    Severity: Minor
    Found in lib/compel/validators/type_validator.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

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

          def coerce_if_proc(proc)
            if proc && proc.is_a?(Proc) &&
              (proc.arity == 1 || proc.arity == 0 &&
                (proc.call.is_a?(::Symbol) || proc.call.is_a?(::String)))
              proc
    Severity: Minor
    Found in lib/compel/builder/common.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

    Severity
    Category
    Status
    Source
    Language