cerebris/jsonapi-resources

View on GitHub

Showing 156 of 156 total issues

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 jsonapi_resource has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def jsonapi_resource(*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

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

              if linkage_relationship.polymorphic? && linkage_relationship.belongs_to?
                linkage_relationship.resource_types.each do |resource_type|
                  klass = resource_klass_for(resource_type)
                  linkage_fields << {relationship: linkage_relationship, resource_klass: klass}
    
    
    Severity: Major
    Found in lib/jsonapi/active_relation_resource.rb and 1 other location - About 1 hr to fix
    lib/jsonapi/active_relation_resource.rb on lines 442..458

    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 62.

    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

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

              if linkage_relationship.polymorphic? && linkage_relationship.belongs_to?
                linkage_relationship.resource_types.each do |resource_type|
                  klass = resource_klass_for(resource_type)
                  linkage_fields << {relationship_name: name, resource_klass: klass}
    
    
    Severity: Major
    Found in lib/jsonapi/active_relation_resource.rb and 1 other location - About 1 hr to fix
    lib/jsonapi/active_relation_resource.rb on lines 628..644

    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 62.

    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 initialize has 36 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def initialize
          #:underscored_key, :camelized_key, :dasherized_key, or custom
          self.json_key_format = :dasherized_key
    
          #:underscored_route, :camelized_route, :dasherized_route, or custom
    Severity: Minor
    Found in lib/jsonapi/configuration.rb - About 1 hr to fix

      Method cached_relationships_hash has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def cached_relationships_hash(source, fetchable_fields, relationship_data)
            relationships = {}
      
            source.relationships.try(:each_pair) do |k,v|
              if fetchable_fields.include?(unformat_key(k).to_sym)
      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 _replace_fields has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def _replace_fields(field_data)
            field_data[:attributes].each do |attribute, value|
              begin
                send "#{attribute}=", value
                @save_needed = true
      Severity: Minor
      Found in lib/jsonapi/basic_resource.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 change has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def change(callback)
            completed = false
      
            if @changing
              run_callbacks callback do
      Severity: Minor
      Found in lib/jsonapi/basic_resource.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 perform_joins has 34 lines of code (exceeds 25 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 1 hr to fix

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

                    def jsonapi_link(*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 add_join has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                  def add_join(path, default_type = :inner, default_polymorphic_join_type = :left)
                    if source_relationship
                      if source_relationship.polymorphic?
                        # Polymorphic paths will come it with the resource_type as the first segment (for example `#documents.comments`)
                        # We just need to prepend the relationship portion the
            Severity: Minor
            Found in lib/jsonapi/active_relation/join_manager.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

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

                      if res._immutable
                        options[:except] << :create unless options[:except].include?(:create) || options[:except].include?('create')
                        options[:except] << :update unless options[:except].include?(:update) || options[:except].include?('update')
                        options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy')
                      end
            Severity: Major
            Found in lib/jsonapi/routing_ext.rb and 1 other location - About 1 hr to fix
            lib/jsonapi/routing_ext.rb on lines 43..47

            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 55.

            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

                      if res._immutable
                        options[:except] << :create unless options[:except].include?(:create) || options[:except].include?('create')
                        options[:except] << :update unless options[:except].include?(:update) || options[:except].include?('update')
                        options[:except] << :destroy unless options[:except].include?(:destroy) || options[:except].include?('destroy')
                      end
            Severity: Major
            Found in lib/jsonapi/routing_ext.rb and 1 other location - About 1 hr to fix
            lib/jsonapi/routing_ext.rb on lines 118..122

            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 55.

            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 _replace_to_many_links has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def _replace_to_many_links(relationship_type, relationship_key_values, options)
                  relationship = self.class._relationship(relationship_type)
            
                  reflect = reflect_relationship?(relationship, options)
            
            
            Severity: Minor
            Found in lib/jsonapi/basic_resource.rb - About 1 hr to fix

              Method links_page_params has 30 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def links_page_params(options = {})
                  record_count = options[:record_count]
                  links_page_params = {}
              
                  links_page_params['first'] = {
              Severity: Minor
              Found in lib/jsonapi/paginator.rb - About 1 hr to fix

                Method find has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def find
                      filters = params[:filters]
                      include_directives = params[:include_directives]
                      sort_criteria = params[:sort_criteria]
                      paginator = params[:paginator]
                Severity: Minor
                Found in lib/jsonapi/processor.rb - About 1 hr to fix
                  Severity
                  Category
                  Status
                  Source
                  Language