gregschmit/rails-rest-framework

View on GitHub

Showing 25 of 31 total issues

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

  def self.parse_extra_actions(extra_actions)
    return (extra_actions || {}).map do |k, v|
      kwargs = {action: k}
      path = k

Severity: Minor
Found in lib/rest_framework/utils.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 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 get_routes has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.get_routes(application_routes, request, current_route: nil)
        current_route ||= self.get_request_route(application_routes, request)
        current_path = current_route.path.spec.to_s.gsub("(.:format)", "")
        current_levels = current_path.count("/")
        current_comparable_path = self.comparable_path(current_path)
    Severity: Minor
    Found in lib/rest_framework/utils.rb - About 1 hr to fix

      Method _rest_resources has 36 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def _rest_resources(default_singular, name, skip_undefined: true, **kwargs, &block)
            controller = kwargs.delete(:controller) || name
            if controller.is_a?(Class)
              controller_class = controller
            else
      Severity: Minor
      Found in lib/rest_framework/routers.rb - About 1 hr to fix

        Method included has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.included(base)
            if base.is_a?(Class)
              RESTFramework::BaseControllerMixin.included(base)
        
              # Add class attributes (with defaults) unless they already exist.
        Severity: Minor
        Found in lib/rest_framework/controller_mixins/models.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 included has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

              def self.included(base)
                if base.is_a?(Class)
                  base.extend(ClassMethods)
            
                  # Add class attributes (with defaults) unless they already exist.
            Severity: Minor
            Found in lib/rest_framework/controller_mixins/base.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 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 _page_size has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def _page_size
                page_size = nil
            
                # Get from context, if allowed.
                if @controller.class.page_size_query_param
            Severity: Minor
            Found in lib/rest_framework/paginators.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 _get_controller_class has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                def _get_controller_class(name, pluralize: true, fallback_reverse_pluralization: true)
                  # Get class name.
                  name = name.to_s.camelize  # Camelize to leave plural names plural.
                  name = name.pluralize if pluralize
                  if name == name.pluralize
            Severity: Minor
            Found in lib/rest_framework/routers.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 get_record has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

              def get_record
                # Cache the result.
                return @record if instance_variable_defined?(:@record)
            
                recordset = self.get_recordset
            Severity: Minor
            Found in lib/rest_framework/controller_mixins/models.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_page has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def get_page(page_number=nil)
                    # If page number isn't provided, infer from the params or use 1 as a fallback value.
                    unless page_number
                      page_number = @controller&.params&.[](self._page_query_param)
                      if page_number.blank?
                Severity: Minor
                Found in lib/rest_framework/paginators.rb - About 45 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 get_body_params has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def get_body_params
                    # Filter the request body and map to strings. Return all params if we cannot resolve a list of
                    # allowed parameters or fields.
                    body_params = if allowed_params = self.get_allowed_parameters&.map(&:to_s)
                      request.request_parameters.select { |p| allowed_params.include?(p) }
                Severity: Minor
                Found in lib/rest_framework/controller_mixins/models.rb - About 45 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 get_routes has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                  def self.get_routes(application_routes, request, current_route: nil)
                    current_route ||= self.get_request_route(application_routes, request)
                    current_path = current_route.path.spec.to_s.gsub("(.:format)", "")
                    current_levels = current_path.count("/")
                    current_comparable_path = self.comparable_path(current_path)
                Severity: Minor
                Found in lib/rest_framework/utils.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 rest_route has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    def rest_route(name=nil, **kwargs, &block)
                      controller = kwargs.delete(:controller) || name
                      route_root_to = kwargs.delete(:route_root_to)
                      if controller.is_a?(Class)
                        controller_class = controller
                Severity: Minor
                Found in lib/rest_framework/routers.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

                Severity
                Category
                Status
                Source
                Language