MiniProfiler/rack-mini-profiler

View on GitHub
lib/mini_profiler.rb

Summary

Maintainability
F
6 days
Test Coverage

Method call has a Cognitive Complexity of 87 (exceeds 5 allowed). Consider refactoring.
Open

    def call(env)
      start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
      client_settings = ClientSettings.new(env, @storage, start)
      MiniProfiler.deauthorize_request if @config.authorization_mode == :allow_authorized

Severity: Minor
Found in lib/mini_profiler.rb - About 1 day 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

File mini_profiler.rb has 517 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'cgi'
require 'json'
require 'erb'

require 'mini_profiler/timer_struct'
Severity: Major
Found in lib/mini_profiler.rb - About 1 day to fix

    Method call has 194 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def call(env)
          start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
          client_settings = ClientSettings.new(env, @storage, start)
          MiniProfiler.deauthorize_request if @config.authorization_mode == :allow_authorized
    
    
    Severity: Major
    Found in lib/mini_profiler.rb - About 7 hrs to fix

      Class MiniProfiler has 42 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class MiniProfiler
          include Actions
          include Views
      
          class << self
      Severity: Minor
      Found in lib/mini_profiler.rb - About 5 hrs to fix

        Method inject_profiler has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            def inject_profiler(env, status, headers, body)
              # mini profiler is meddling with stuff, we can not cache cause we will get incorrect data
              # Rack::ETag has already inserted some nonesense in the chain
              content_type = headers['Content-Type']
        
        
        Severity: Minor
        Found in lib/mini_profiler.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 analyze_memory has 45 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def analyze_memory
              require 'objspace'
        
              utf8 = "utf-8"
        
        
        Severity: Minor
        Found in lib/mini_profiler.rb - About 1 hr to fix

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

              def analyze_memory
                require 'objspace'
          
                utf8 = "utf-8"
          
          
          Severity: Minor
          Found in lib/mini_profiler.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 binds_to_params has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

                def binds_to_params(binds)
                  return if binds.nil? || config.max_sql_param_length == 0
                  # map ActiveRecord::Relation::QueryAttribute to [name, value]
                  params = binds.map { |c| c.kind_of?(Array) ? [c.first, c.last] : [c.name, c.value] }
                  if (skip = config.skip_sql_param_names)
          Severity: Minor
          Found in lib/mini_profiler.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 take_snapshot has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def take_snapshot(env, start)
                MiniProfiler.create_current(env, @config)
                Thread.current[:mp_ongoing_snapshot] = true
                results = @app.call(env)
                status = results[0].to_i
          Severity: Minor
          Found in lib/mini_profiler.rb - About 1 hr to fix

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

                def inject(fragment, script)
                  # find explicit or implicit body
                  index = fragment.rindex(/<\/body>/i) || fragment.rindex(/<\/html>/i)
                  if index
                    # if for whatever crazy reason we dont get a utf string,
            Severity: Minor
            Found in lib/mini_profiler.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 take_snapshot has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                def take_snapshot(env, start)
                  MiniProfiler.create_current(env, @config)
                  Thread.current[:mp_ongoing_snapshot] = true
                  results = @app.call(env)
                  status = results[0].to_i
            Severity: Minor
            Found in lib/mini_profiler.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 rails_route_from_path has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def rails_route_from_path(path, method)
                  if defined?(Rails) && defined?(ActionController::RoutingError)
                    hash = Rails.application.routes.recognize_path(path, method: method)
                    if hash && hash[:controller] && hash[:action]
                      "#{hash[:controller]}##{hash[:action]}"
            Severity: Minor
            Found in lib/mini_profiler.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

            Avoid too many return statements within this method.
            Open

                    return client_settings.handle_cookie(dump_exceptions exceptions)
            Severity: Major
            Found in lib/mini_profiler.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return client_settings.handle_cookie(self.flamegraph(flamegraph, path, env))
              Severity: Major
              Found in lib/mini_profiler.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return tool_disabled_message(client_settings) if !advanced_debugging_enabled?
                Severity: Major
                Found in lib/mini_profiler.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return client_settings.handle_cookie(
                                text_result(message, status: status, headers: headers)
                              )
                  Severity: Major
                  Found in lib/mini_profiler.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return client_settings.handle_cookie(analyze_memory)
                    Severity: Major
                    Found in lib/mini_profiler.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return client_settings.handle_cookie(dump_env env)
                      Severity: Major
                      Found in lib/mini_profiler.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return client_settings.handle_cookie(help(client_settings, env))
                        Severity: Major
                        Found in lib/mini_profiler.rb - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                  return client_settings.handle_cookie(serve_file(env, file_name: file_name))
                          Severity: Major
                          Found in lib/mini_profiler.rb - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                    return client_settings.handle_cookie([status, headers, body])
                            Severity: Major
                            Found in lib/mini_profiler.rb - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return serve_profile_gc(env, client_settings)
                              Severity: Major
                              Found in lib/mini_profiler.rb - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                        return tool_disabled_message(client_settings) if !advanced_debugging_enabled?
                                Severity: Major
                                Found in lib/mini_profiler.rb - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                            return serve_flamegraph(env)
                                  Severity: Major
                                  Found in lib/mini_profiler.rb - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                          return client_settings.handle_cookie([status, headers, body]) if skip_it
                                    Severity: Major
                                    Found in lib/mini_profiler.rb - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                return serve_snapshot(env)
                                      Severity: Major
                                      Found in lib/mini_profiler.rb - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                return serve_profile_memory(env, client_settings)
                                        Severity: Major
                                        Found in lib/mini_profiler.rb - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                    return client_settings.handle_cookie(result) if result
                                          Severity: Major
                                          Found in lib/mini_profiler.rb - About 30 mins to fix

                                            There are no issues that match your filters.

                                            Category
                                            Status