rails-api/active_model_serializers

View on GitHub
lib/active_model_serializers/adapter/json_api/deserialization.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Method validate_payload has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

        def validate_payload(payload)
          unless payload.is_a?(Hash)
            yield payload, 'Expected hash'
            return
          end
Severity: Minor
Found in lib/active_model_serializers/adapter/json_api/deserialization.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 parse_relationship has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

        def parse_relationship(assoc_name, assoc_data, options)
          prefix_key = field_key(assoc_name, options).to_s.singularize
          hash =
            if assoc_data.is_a?(Array)
              { "#{prefix_key}_ids".to_sym => assoc_data.map { |ri| ri['id'] } }
Severity: Minor
Found in lib/active_model_serializers/adapter/json_api/deserialization.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 parse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def parse(document, options = {})
          document = document.dup.permit!.to_h if document.is_a?(ActionController::Parameters)

          validate_payload(document) do |invalid_document, reason|
            yield invalid_document, reason if block_given?
Severity: Minor
Found in lib/active_model_serializers/adapter/json_api/deserialization.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