tiagopog/jsonapi-utils

View on GitHub

Showing 4 of 4 total issues

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

        def sanitize(errors)
          Array(errors).map do |error|
            MEMBERS.reduce({}) do |sum, key|
              value = error.try(key) || error.try(:[], key)
              if value.nil?
Severity: Minor
Found in lib/jsonapi/utils/support/error.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

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

        def hash_to_active_record(data, model)
          return data if model.nil?
          coerced = [data].flatten.map { |hash| model.new(hash) }
          data.is_a?(Array) ? coerced : coerced.first
        rescue ActiveRecord::UnknownAttributeError
Severity: Minor
Found in lib/jsonapi/utils/response/formatters.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

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

        def source_member(field)
          resource_key = resource_key_for(field)
          return {} unless field == :base || resource.fetchable_fields.include?(resource_key)
          id = key_format(field)

Severity: Minor
Found in lib/jsonapi/utils/exceptions/active_record.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 result_options has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def result_options(records, options)
          {}.tap do |data|
            if include_pagination_links?
              data[:pagination_params] = pagination_params(records, options)
            end
Severity: Minor
Found in lib/jsonapi/utils/response/formatters.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