cerebris/jsonapi-resources

View on GitHub

Showing 156 of 156 total issues

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

Identical blocks of code found in 2 locations. Consider refactoring.
Open

class BugTest < Minitest::Test
  include Rack::Test::Methods

  def json_api_headers
    {'Accept' => JSONAPI::MEDIA_TYPE, 'CONTENT_TYPE' => JSONAPI::MEDIA_TYPE}
Severity: Major
Found in lib/bug_report_templates/rails_5_master.rb and 1 other location - About 3 hrs to fix
lib/bug_report_templates/rails_5_latest.rb on lines 86..123

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 108.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Identical blocks of code found in 2 locations. Consider refactoring.
Open

class BugTest < Minitest::Test
  include Rack::Test::Methods

  def json_api_headers
    {'Accept' => JSONAPI::MEDIA_TYPE, 'CONTENT_TYPE' => JSONAPI::MEDIA_TYPE}
Severity: Major
Found in lib/bug_report_templates/rails_5_latest.rb and 1 other location - About 3 hrs to fix
lib/bug_report_templates/rails_5_master.rb on lines 101..138

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 108.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Method verify_key has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

      def verify_key(key, context = nil)
        key_type = resource_key_type

        case key_type
        when :integer
Severity: Minor
Found in lib/jsonapi/basic_resource.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 find_related_monomorphic_fragments has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

      def find_related_monomorphic_fragments(source_fragments, relationship, options, connect_source_identity)
        filters = options.fetch(:filters, {})
        source_ids = source_fragments.collect {|item| item.identity.id}

        include_directives = options.fetch(:include_directives, {})
Severity: Minor
Found in lib/jsonapi/active_relation_resource.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 perform_joins has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
Open

      def perform_joins(records, options)
        join_array = flatten_join_tree_by_depth

        join_array.each do |level_joins|
          level_joins.each do |join_details|
Severity: Minor
Found in lib/jsonapi/active_relation/join_manager.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

Class Processor has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Processor
    include Callbacks
    define_jsonapi_resources_callbacks :find,
                                       :show,
                                       :show_relationship,
Severity: Minor
Found in lib/jsonapi/processor.rb - About 2 hrs to fix

    Method attribute has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

          def attribute(attribute_name, options = {})
            _clear_cached_attribute_options
            _clear_fields_cache
    
            attr = attribute_name.to_sym
    Severity: Minor
    Found in lib/jsonapi/basic_resource.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 find_fragments has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

          def find_fragments(filters, options = {})
            include_directives = options.fetch(:include_directives, {})
            resource_klass = self
    
            fragments = {}
    Severity: Minor
    Found in lib/jsonapi/active_relation_resource.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

    File acts_as_resource_controller.rb has 255 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'csv'
    
    module JSONAPI
      module ActsAsResourceController
        MEDIA_TYPE_MATCHER = /.+".+"[^,]*|[^,]+/
    Severity: Minor
    Found in lib/jsonapi/acts_as_resource_controller.rb - About 2 hrs to fix

      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 update_links has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            def update_links(serializer, result)
              @top_level_links.merge!(result.links)
        
              # Build pagination links
              if result.is_a?(JSONAPI::ResourceSetOperationResult) ||
        Severity: Minor
        Found in lib/jsonapi/response_document.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 show_related_resources has 48 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def show_related_resources
              source_klass = params[:source_klass]
              source_id = params[:source_id]
              relationship_type = params[:relationship_type]
              filters = params[:filters]
        Severity: Minor
        Found in lib/jsonapi/processor.rb - About 1 hr to fix

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

              def add_resources_to_tree(resource_klass,
                                        tree,
                                        resources,
                                        include_related,
                                        source_rid: nil,
          Severity: Minor
          Found in lib/jsonapi/resource_tree.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 jsonapi_resources has 45 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                  def jsonapi_resources(*resources, &_block)
                    @resource_type = resources.first
                    res = JSONAPI::Resource.resource_klass_for(resource_type_with_module_prefix(@resource_type))
          
                    res._routed = true
          Severity: Minor
          Found in lib/jsonapi/routing_ext.rb - About 1 hr 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 relationships_hash has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  def relationships_hash(source, fetchable_fields, relationship_data)
                    relationships = source.class._relationships.select{|k,_v| fetchable_fields.include?(k) }
                    field_set = supplying_relationship_fields(source.class) & relationships.keys
              
                    relationships.each_with_object({}) do |(name, relationship), hash|
              Severity: Minor
              Found in lib/jsonapi/resource_serializer.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 jsonapi_links has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                      def jsonapi_links(*links)
                        link_type = links.first
                        formatted_relationship_name = format_route(link_type)
                        options = links.extract_options!.dup
              
              
              Severity: Minor
              Found in lib/jsonapi/routing_ext.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_pagination_params has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                def parse_pagination_params(params)
                  if params.nil?
                    @offset = 0
                    @limit = JSONAPI.configuration.default_page_size
                  elsif params.is_a?(ActionController::Parameters)
              Severity: Minor
              Found in lib/jsonapi/paginator.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_pagination_params has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                def parse_pagination_params(params)
                  if params.nil?
                    @number = 1
                    @size = JSONAPI.configuration.default_page_size
                  elsif params.is_a?(ActionController::Parameters)
              Severity: Minor
              Found in lib/jsonapi/paginator.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

              Severity
              Category
              Status
              Source
              Language