cerebris/jsonapi-resources

View on GitHub
lib/jsonapi/resource_serializer.rb

Summary

Maintainability
D
2 days
Test Coverage

Method object_hash has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

    def object_hash(source, relationship_data)
      obj_hash = {}

      return obj_hash if source.nil?

Severity: Minor
Found in lib/jsonapi/resource_serializer.rb - About 4 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 ResourceSerializer has 30 methods (exceeds 20 allowed). Consider refactoring.
Open

  class ResourceSerializer

    attr_reader :link_builder, :key_formatter, :serialization_options,
                :fields, :include_directives, :always_include_to_one_linkage_data,
                :always_include_to_many_linkage_data, :options
Severity: Minor
Found in lib/jsonapi/resource_serializer.rb - About 3 hrs to fix

    File resource_serializer.rb has 308 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    module JSONAPI
      class ResourceSerializer
    
        attr_reader :link_builder, :key_formatter, :serialization_options,
                    :fields, :include_directives, :always_include_to_one_linkage_data,
    Severity: Minor
    Found in lib/jsonapi/resource_serializer.rb - About 3 hrs 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 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 object_hash has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def object_hash(source, relationship_data)
            obj_hash = {}
      
            return obj_hash if source.nil?
      
      
      Severity: Minor
      Found in lib/jsonapi/resource_serializer.rb - About 1 hr to fix

        Method supplying_relationship_fields has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def supplying_relationship_fields(resource_klass)
              @_supplying_relationship_fields.fetch resource_klass do
                relationships = Set.new(resource_klass._relationships.keys.map(&:to_sym))
                cur = resource_klass
                while !cur.root? # do not traverse beyond the first root resource
        Severity: Minor
        Found in lib/jsonapi/resource_serializer.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 supplying_attribute_fields has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def supplying_attribute_fields(resource_klass)
              @_supplying_attribute_fields.fetch resource_klass do
                attrs = Set.new(resource_klass._attributes.keys.map(&:to_sym))
                cur = resource_klass
                while !cur.root? # do not traverse beyond the first root resource
        Severity: Minor
        Found in lib/jsonapi/resource_serializer.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 serialize_resource_set_to_hash_single has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def serialize_resource_set_to_hash_single(resource_set)
        
              primary_objects = []
              included_objects = []
        
        
        Severity: Minor
        Found in lib/jsonapi/resource_serializer.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

            def supplying_relationship_fields(resource_klass)
              @_supplying_relationship_fields.fetch resource_klass do
                relationships = Set.new(resource_klass._relationships.keys.map(&:to_sym))
                cur = resource_klass
                while !cur.root? # do not traverse beyond the first root resource
        Severity: Minor
        Found in lib/jsonapi/resource_serializer.rb and 1 other location - About 55 mins to fix
        lib/jsonapi/resource_serializer.rb on lines 208..219

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

        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

            def supplying_attribute_fields(resource_klass)
              @_supplying_attribute_fields.fetch resource_klass do
                attrs = Set.new(resource_klass._attributes.keys.map(&:to_sym))
                cur = resource_klass
                while !cur.root? # do not traverse beyond the first root resource
        Severity: Minor
        Found in lib/jsonapi/resource_serializer.rb and 1 other location - About 55 mins to fix
        lib/jsonapi/resource_serializer.rb on lines 223..234

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

        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

              resource_set.resource_klasses.each_value do |resource_klass|
                resource_klass.each_value do |resource|
                  serialized_resource = object_hash(resource[:resource], resource[:relationships])
        
                  if resource[:primary]
        Severity: Minor
        Found in lib/jsonapi/resource_serializer.rb and 1 other location - About 20 mins to fix
        lib/jsonapi/resource_serializer.rb on lines 66..73

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

        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

              resource_set.resource_klasses.each_value do |resource_klass|
                resource_klass.each_value do |resource|
                  serialized_resource = object_hash(resource[:resource], resource[:relationships])
        
                  if resource[:primary]
        Severity: Minor
        Found in lib/jsonapi/resource_serializer.rb and 1 other location - About 20 mins to fix
        lib/jsonapi/resource_serializer.rb on lines 90..97

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

        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