app/controllers/avo/base_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

Class BaseController has 49 methods (exceeds 20 allowed). Consider refactoring.
Open

  class BaseController < ApplicationController
    include Avo::Concerns::FiltersSessionHandler

    before_action :set_resource_name
    before_action :set_resource
Severity: Minor
Found in app/controllers/avo/base_controller.rb - About 6 hrs to fix

    File base_controller.rb has 440 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require_dependency "avo/application_controller"
    
    module Avo
      class BaseController < ApplicationController
        include Avo::Concerns::FiltersSessionHandler
    Severity: Minor
    Found in app/controllers/avo/base_controller.rb - About 6 hrs to fix

      Method create has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          def create
            # This means that the record has been created through another parent record and we need to attach it somehow.
            if params[:via_record_id].present? && params[:via_belongs_to_resource_class].nil?
              @reflection = @record._reflections[params[:via_relation]]
              # Figure out what kind of association does the record have with the parent record
      Severity: Minor
      Found in app/controllers/avo/base_controller.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 set_index_params has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def set_index_params
            @index_params = {}
      
            # Pagination
            @index_params[:page] = params[:page] || 1
      Severity: Minor
      Found in app/controllers/avo/base_controller.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 set_index_params has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def set_index_params
            @index_params = {}
      
            # Pagination
            @index_params[:page] = params[:page] || 1
      Severity: Minor
      Found in app/controllers/avo/base_controller.rb - About 1 hr to fix

        Method create has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def create
              # This means that the record has been created through another parent record and we need to attach it somehow.
              if params[:via_record_id].present? && params[:via_belongs_to_resource_class].nil?
                @reflection = @record._reflections[params[:via_relation]]
                # Figure out what kind of association does the record have with the parent record
        Severity: Minor
        Found in app/controllers/avo/base_controller.rb - About 1 hr to fix

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

              def apply_sorting
                return if @index_params[:sort_by].nil?
          
                sort_by = @index_params[:sort_by].to_sym
                if sort_by != :created_at
          Severity: Minor
          Found in app/controllers/avo/base_controller.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

          There are no issues that match your filters.

          Category
          Status