CartoDB/cartodb20

View on GitHub
app/controllers/application_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

Class ApplicationController has 52 methods (exceeds 20 allowed). Consider refactoring.
Open

class ApplicationController < ActionController::Base

  include UrlHelper
  include Carto::ControllerHelper
  include Carto::Common::ControllerHelper
Severity: Major
Found in app/controllers/application_controller.rb - About 7 hrs to fix

    File application_controller.rb has 423 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require_relative '../../lib/cartodb/profiler.rb'
    require_dependency 'carto/authentication_manager'
    require_dependency 'carto/http_header_authentication'
    
    class ApplicationController < ActionController::Base
    Severity: Minor
    Found in app/controllers/application_controller.rb - About 6 hrs to fix

      Method current_viewer has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
      Open

        def current_viewer
          if @current_viewer.nil?
            if current_user && env["warden"].authenticated?(current_user.username)
              @current_viewer = current_user if Carto::AuthenticationManager.validate_session(warden, request, current_user)
            else
      Severity: Minor
      Found in app/controllers/application_controller.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 check_user_state has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

        def check_user_state
          return if IGNORE_PATHS_FOR_CHECK_USER_STATE.any? { |path| request.path.end_with?("/" + path) }
          viewed_username = CartoDB.extract_subdomain(request)
          if current_user.nil? || current_user.username != viewed_username
            user = Carto::User.find_by_username(viewed_username)
      Severity: Minor
      Found in app/controllers/application_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

      Avoid deeply nested control flow statements.
      Open

                  Carto::AuthenticationManager.validate_session(warden, request, user) unless user.nil?
      Severity: Major
      Found in app/controllers/application_controller.rb - About 45 mins to fix

        Method http_header_authentication has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def http_header_authentication
            authenticate(:http_header_authentication, scope: CartoDB.extract_subdomain(request))
            if current_user
              Carto::AuthenticationManager.validate_session(warden, request, current_user)
            else
        Severity: Minor
        Found in app/controllers/application_controller.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 too many return statements within this method.
        Open

              return
        Severity: Major
        Found in app/controllers/application_controller.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                return
          Severity: Major
          Found in app/controllers/application_controller.rb - About 30 mins to fix

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

              def ensure_org_url_if_org_user
                return if CartoDB.subdomainless_urls?
            
                rewrite_url = !request.params[:dont_rewrite].present?
                if rewrite_url && !current_user.nil? && !current_user.organization.nil? &&
            Severity: Minor
            Found in app/controllers/application_controller.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 translate_error has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def translate_error(exception)
                return exception if exception.blank? || exception.is_a?(String)
            
                case exception
                  when CartoDB::EmptyFile
            Severity: Minor
            Found in app/controllers/application_controller.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 check_maintenance_mode has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
            Open

              def check_maintenance_mode
                return if IGNORE_PATHS_FOR_CHECK_USER_STATE.any? { |path| request.path.end_with?("/" + path) }
            
                viewed_username = CartoDB.extract_subdomain(request)
                if current_user.nil? || current_user.username != viewed_username
            Severity: Minor
            Found in app/controllers/application_controller.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