cerebris/jsonapi-resources

View on GitHub
lib/jsonapi/active_relation_resource.rb

Summary

Maintainability
F
5 days
Test Coverage

File active_relation_resource.rb has 620 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module JSONAPI
  class ActiveRelationResource < BasicResource
    root_resource

    def find_related_ids(relationship, options = {})
Severity: Major
Found in lib/jsonapi/active_relation_resource.rb - About 1 day to fix

    Method find_related_polymorphic_fragments has 133 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def find_related_polymorphic_fragments(source_fragments, relationship, options, connect_source_identity)
            filters = options.fetch(:filters, {})
            source_ids = source_fragments.collect {|item| item.identity.id}
    
            resource_klass = relationship.resource_klass
    Severity: Major
    Found in lib/jsonapi/active_relation_resource.rb - About 5 hrs to fix

      Method find_related_polymorphic_fragments has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
      Open

            def find_related_polymorphic_fragments(source_fragments, relationship, options, connect_source_identity)
              filters = options.fetch(:filters, {})
              source_ids = source_fragments.collect {|item| item.identity.id}
      
              resource_klass = relationship.resource_klass
      Severity: Minor
      Found in lib/jsonapi/active_relation_resource.rb - About 5 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 ActiveRelationResource has 38 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class ActiveRelationResource < BasicResource
          root_resource
      
          def find_related_ids(relationship, options = {})
            self.class.find_related_fragments([self], relationship.name, options).keys.collect { |rid| rid.id }
      Severity: Minor
      Found in lib/jsonapi/active_relation_resource.rb - About 5 hrs to fix

        Method find_related_monomorphic_fragments has 96 lines of code (exceeds 25 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: Major
        Found in lib/jsonapi/active_relation_resource.rb - About 3 hrs to fix

          Method find_fragments has 85 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def find_fragments(filters, options = {})
                  include_directives = options.fetch(:include_directives, {})
                  resource_klass = self
          
                  fragments = {}
          Severity: Major
          Found in lib/jsonapi/active_relation_resource.rb - About 3 hrs to fix

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

            Method concat_table_field has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def concat_table_field(table, field, quoted = false)
                    if table.blank? || field.to_s.include?('.')
                      # :nocov:
                      if quoted
                        quote(field)
            Severity: Minor
            Found in lib/jsonapi/active_relation_resource.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 apply_single_sort has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def apply_single_sort(records, field, direction, options)
                    context = options[:context]
            
                    strategy = _allowed_sort.fetch(field.to_sym, {})[:apply]
            
            
            Severity: Minor
            Found in lib/jsonapi/active_relation_resource.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 apply_join has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def apply_join(records:, relationship:, resource_type:, join_type:, options:)
                    if relationship.polymorphic? && relationship.belongs_to?
                      case join_type
                      when :inner
                        records = records.joins(resource_type.to_s.singularize.to_sym)
            Severity: Minor
            Found in lib/jsonapi/active_relation_resource.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 alias_table_field has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def alias_table_field(table, field, quoted = false)
                    if table.blank? || field.to_s.include?('.')
                      # :nocov:
                      if quoted
                        quote(field)
            Severity: Minor
            Found in lib/jsonapi/active_relation_resource.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 apply_request_settings_to_records has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

                  def apply_request_settings_to_records(records:,
                                                        join_manager: ActiveRelation::JoinManager.new(resource_klass: self),
                                                        resource_klass: self,
                                                        filters: {},
                                                        primary_keys: nil,
            Severity: Minor
            Found in lib/jsonapi/active_relation_resource.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

            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

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

                      linkage_fields.each do |linkage_field|
                        fragments[rid].initialize_related(linkage_field[:relationship_name])
                        related_id = row[attributes_offset]
                        if related_id
                          related_rid = JSONAPI::ResourceIdentity.new(linkage_field[:resource_klass], related_id)
            Severity: Minor
            Found in lib/jsonapi/active_relation_resource.rb and 1 other location - About 45 mins to fix
            lib/jsonapi/active_relation_resource.rb on lines 190..198

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

            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

                      linkage_fields.each do |linkage_field_details|
                        fragments[rid].initialize_related(linkage_field_details[:relationship_name])
                        related_id = row[attributes_offset]
                        if related_id
                          related_rid = JSONAPI::ResourceIdentity.new(linkage_field_details[:resource_klass], related_id)
            Severity: Minor
            Found in lib/jsonapi/active_relation_resource.rb and 1 other location - About 45 mins to fix
            lib/jsonapi/active_relation_resource.rb on lines 497..505

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

            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

            There are no issues that match your filters.

            Category
            Status