gregschmit/rails-rest-framework

View on GitHub

Showing 27 of 30 total issues

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

  def self.filter_subcfg(subcfg, except: nil, only: nil, additive: false)
    return subcfg unless except || only
    return subcfg unless subcfg || additive
    raise "Cannot pass `only` and `additive` to filter_subcfg." if only && additive

Severity: Minor
Found in lib/rest_framework/serializers.rb - About 6 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 19 (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 get_routes has a Cognitive Complexity of 15 (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
    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

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

    def self.get_version(skip_git: false)
      # First, attempt to get the version from git.
      unless skip_git
        version = `git describe --dirty 2>/dev/null`&.strip
        return version unless !version || version.empty?
Severity: Minor
Found in lib/rest_framework/version.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_subcfg has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.filter_subcfg(subcfg, except: nil, only: nil, additive: false)
    return subcfg unless except || only
    return subcfg unless subcfg || additive
    raise "Cannot pass `only` and `additive` to filter_subcfg." if only && additive

Severity: Minor
Found in lib/rest_framework/serializers.rb - About 1 hr to fix

    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 included has 39 lines of code (exceeds 25 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

      Method get_routes has 36 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
          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 filter_except has 33 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 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 _get_ordering has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                def _get_ordering
                  return nil if @controller.class.ordering_query_param.blank?
              
                  # Ensure ordering_fields are strings since the split param will be strings.
                  ordering_fields = @controller.get_ordering_fields.map(&:to_s)
              Severity: Minor
              Found in lib/rest_framework/filters.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 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 _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_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 _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 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

                    elsif only && !additive && !subcfg.in?(only)  # Protect only/additive data-leaking.
                      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

                Avoid deeply nested control flow statements.
                Open

                        if subcfg.in?(except)
                          subcfg = [] unless additive
                        elsif additive
                          subcfg = [subcfg, *except]
                        end
                Severity: Major
                Found in lib/rest_framework/serializers.rb - About 45 mins to fix
                  Severity
                  Category
                  Status
                  Source
                  Language