cerebris/jsonapi-resources

View on GitHub
lib/jsonapi/request.rb

Summary

Maintainability
F
4 days
Test Coverage

File request.rb has 614 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module JSONAPI
  class Request
    attr_accessor :fields, :include, :filters, :sort_criteria, :errors, :controller_module_path,
                  :context, :paginator, :source_klass, :source_id,
                  :include_directives, :params, :warnings, :server_error_callbacks, :operations
Severity: Major
Found in lib/jsonapi/request.rb - About 1 day to fix

    Class Request has 37 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Request
        attr_accessor :fields, :include, :filters, :sort_criteria, :errors, :controller_module_path,
                      :context, :paginator, :source_klass, :source_id,
                      :include_directives, :params, :warnings, :server_error_callbacks, :operations
    
    
    Severity: Minor
    Found in lib/jsonapi/request.rb - About 4 hrs to fix

      Method verify_permitted_params has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

          def verify_permitted_params(params, allowed_fields)
            formatted_allowed_fields = allowed_fields.collect { |field| format_key(field).to_sym }
            params_not_allowed = []
      
            params.each do |key, value|
      Severity: Minor
      Found in lib/jsonapi/request.rb - About 3 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 parse_fields has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
      Open

          def parse_fields(resource_klass, fields)
            extracted_fields = {}
      
            return extracted_fields if fields.nil?
      
      
      Severity: Minor
      Found in lib/jsonapi/request.rb - About 3 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 verify_permitted_params has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def verify_permitted_params(params, allowed_fields)
            formatted_allowed_fields = allowed_fields.collect { |field| format_key(field).to_sym }
            params_not_allowed = []
      
            params.each do |key, value|
      Severity: Major
      Found in lib/jsonapi/request.rb - About 2 hrs to fix

        Method parse_fields has 44 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def parse_fields(resource_klass, fields)
              extracted_fields = {}
        
              return extracted_fields if fields.nil?
        
        
        Severity: Minor
        Found in lib/jsonapi/request.rb - About 1 hr to fix

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

              def parse_filters(resource_klass, filters)
                parsed_filters = {}
          
                # apply default filters
                resource_klass._allowed_filters.each do |filter, opts|
          Severity: Minor
          Found in lib/jsonapi/request.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_to_many_relationship has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def parse_to_many_relationship(resource_klass, link_value, relationship, &add_result)
                if (link_value.is_a?(Hash) || link_value.is_a?(ActionController::Parameters))
                  linkage = link_value[:data]
                else
                  fail JSONAPI::Exceptions::InvalidLinksObject.new(error_object_overrides)
          Severity: Minor
          Found in lib/jsonapi/request.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_to_many_relationship has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def parse_to_many_relationship(resource_klass, link_value, relationship, &add_result)
                if (link_value.is_a?(Hash) || link_value.is_a?(ActionController::Parameters))
                  linkage = link_value[:data]
                else
                  fail JSONAPI::Exceptions::InvalidLinksObject.new(error_object_overrides)
          Severity: Minor
          Found in lib/jsonapi/request.rb - About 1 hr to fix

            Method parse_params has 32 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def parse_params(resource_klass, params, allowed_fields)
                  verify_permitted_params(params, allowed_fields)
            
                  checked_attributes = {}
                  checked_to_one_relationships = {}
            Severity: Minor
            Found in lib/jsonapi/request.rb - About 1 hr to fix

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

                  def parse_sort_criteria(resource_klass, sort_criteria)
                    return unless sort_criteria.present?
              
                    unless JSONAPI.configuration.allow_sort
                      fail JSONAPI::Exceptions::ParameterNotAllowed.new(:sort)
              Severity: Minor
              Found in lib/jsonapi/request.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 setup_operations has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  def setup_operations(params)
                    return if params.nil?
              
                    resource_klass = Resource.resource_klass_for(params[:controller]) if params[:controller]
              
              
              Severity: Minor
              Found in lib/jsonapi/request.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_to_one_relationship has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  def parse_to_one_relationship(resource_klass, link_value, relationship)
                    if link_value.nil?
                      linkage = nil
                    else
                      linkage = link_value[:data]
              Severity: Minor
              Found in lib/jsonapi/request.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 check_include has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  def check_include(resource_klass, include_parts)
                    relationship_name = unformat_key(include_parts.first)
              
                    relationship = resource_klass._relationship(relationship_name)
                    if relationship && format_key(relationship_name) == include_parts.first
              Severity: Minor
              Found in lib/jsonapi/request.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_update_relationship_operation has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  def parse_update_relationship_operation(resource_klass, verified_params, relationship, parent_key)
                    options = {
                      context: @context,
                      resource_id: parent_key,
                      relationship_type: relationship.name
              Severity: Minor
              Found in lib/jsonapi/request.rb - About 45 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 parse_params has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  def parse_params(resource_klass, params, allowed_fields)
                    verify_permitted_params(params, allowed_fields)
              
                    checked_attributes = {}
                    checked_to_one_relationships = {}
              Severity: Minor
              Found in lib/jsonapi/request.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 parse_include_directives has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def parse_include_directives(resource_klass, raw_include)
                    raw_include ||= ''
              
                    included_resources = []
                    begin
              Severity: Minor
              Found in lib/jsonapi/request.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 setup_update_action has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def setup_update_action(params, resource_klass)
                    resolve_singleton_id(params, resource_klass)
                    fields = parse_fields(resource_klass, params[:fields])
                    include_directives = parse_include_directives(resource_klass, params[:include])
              
              
              Severity: Minor
              Found in lib/jsonapi/request.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