charliesome/better_errors

View on GitHub
lib/better_errors/middleware.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Method show_error_page has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def show_error_page(env, exception=nil)
      request = Rack::Request.new(env)
      csrf_token = request.cookies[CSRF_TOKEN_COOKIE_NAME] || SecureRandom.uuid
      csp_nonce = SecureRandom.base64(12)

Severity: Minor
Found in lib/better_errors/middleware.rb - About 1 hr to fix

    Method internal_call has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def internal_call(env, id, method)
          return not_found_json_response unless %w[variables eval].include?(method)
          return no_errors_json_response unless @error_page
          return invalid_error_json_response if id != @error_page.id
    
    
    Severity: Minor
    Found in lib/better_errors/middleware.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 show_error_page has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def show_error_page(env, exception=nil)
          request = Rack::Request.new(env)
          csrf_token = request.cookies[CSRF_TOKEN_COOKIE_NAME] || SecureRandom.uuid
          csp_nonce = SecureRandom.base64(12)
    
    
    Severity: Minor
    Found in lib/better_errors/middleware.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 too many return statements within this method.
    Open

          return not_acceptable_json_response unless request.content_type == 'application/json'
    Severity: Major
    Found in lib/better_errors/middleware.rb - About 30 mins to fix

      Avoid too many return statements within this method.
      Open

            return invalid_csrf_token_json_response unless request.cookies[CSRF_TOKEN_COOKIE_NAME] == body['csrfToken']
      Severity: Major
      Found in lib/better_errors/middleware.rb - About 30 mins to fix

        There are no issues that match your filters.

        Category
        Status