gregschmit/rails-rest-framework

View on GitHub
lib/rest_framework/serializers.rb

Summary

Maintainability
D
1 day
Test Coverage

Method filter_subcfg has a Cognitive Complexity of 31 (exceeds 5 allowed). Consider refactoring.
Open

  def self.filter_subcfg(subcfg, fields:, add: false, only: false)
    raise "`add` and `only` conflict with one another" if add && only

    # Don't process nil `subcfg`s.
    return subcfg unless subcfg
Severity: Minor
Found in lib/rest_framework/serializers.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

Method filter_except has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

  def filter_except(cfg)
    return cfg unless @controller

    except_param = @controller.class.try(:native_serializer_except_query_param)
    only_param = @controller.class.try(:native_serializer_only_query_param)
Severity: Minor
Found in lib/rest_framework/serializers.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 filter_except has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def filter_except(cfg)
    return cfg unless @controller

    except_param = @controller.class.try(:native_serializer_except_query_param)
    only_param = @controller.class.try(:native_serializer_only_query_param)
Severity: Minor
Found in lib/rest_framework/serializers.rb - About 1 hr to fix

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

      def self.filter_subcfg(subcfg, fields:, add: false, only: false)
        raise "`add` and `only` conflict with one another" if add && only
    
        # Don't process nil `subcfg`s.
        return subcfg unless subcfg
    Severity: Minor
    Found in lib/rest_framework/serializers.rb - About 1 hr to fix

      Method get_local_native_serializer_config has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def get_local_native_serializer_config
          action = self.get_action
      
          if action && self.action_config
            # Index action should use :list serializer config if :index is not provided.
      Severity: Minor
      Found in lib/rest_framework/serializers.rb - About 55 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 initialize has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def initialize(object=nil, *args, many: nil, model: nil, **kwargs)
          super(object, *args, **kwargs)
      
          if many.nil?
            # Determine if we are dealing with many objects or just one.
      Severity: Minor
      Found in lib/rest_framework/serializers.rb - About 55 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

      Avoid deeply nested control flow statements.
      Open

              subcfg = subcfg.in?(fields) ? subcfg : []
      Severity: Major
      Found in lib/rest_framework/serializers.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                subcfg = subcfg.in?(fields) ? [] : subcfg
        Severity: Major
        Found in lib/rest_framework/serializers.rb - About 45 mins to fix

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

            def _get_raw_serializer_config
              # Return a locally defined serializer config if one is defined.
              if local_config = self.get_local_native_serializer_config
                return local_config.deep_dup
              end
          Severity: Minor
          Found in lib/rest_framework/serializers.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