padrino/padrino-framework

View on GitHub
padrino-core/lib/padrino-core/application/routing.rb

Summary

Maintainability
F
5 days
Test Coverage

File routing.rb has 514 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'padrino-support'
require 'padrino-core/path_router' unless defined?(PathRouter)
require 'padrino-core/ext/sinatra'
require 'padrino-core/filter'

Severity: Major
Found in padrino-core/lib/padrino-core/application/routing.rb - About 1 day to fix

    Method parse_route has a Cognitive Complexity of 53 (exceeds 5 allowed). Consider refactoring.
    Open

          def parse_route(path, options, verb)
            path = path.dup if path.kind_of?(String)
            route_options = {}
    
            if options[:params] == true
    Severity: Minor
    Found in padrino-core/lib/padrino-core/application/routing.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

    Method route has a Cognitive Complexity of 51 (exceeds 5 allowed). Consider refactoring.
    Open

          def route(verb, path, *args, &block)
            options = case args.size
              when 2
                args.last.merge(:map => args.first)
              when 1
    Severity: Minor
    Found in padrino-core/lib/padrino-core/application/routing.rb - About 7 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 route has 76 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def route(verb, path, *args, &block)
            options = case args.size
              when 2
                args.last.merge(:map => args.first)
              when 1
    Severity: Major
    Found in padrino-core/lib/padrino-core/application/routing.rb - About 3 hrs to fix

      Method invoke_route has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

            def invoke_route(route, params, first_time)
              @_response_buffer = nil
              @route = request.route_obj = route
              captured_params = captures_from_params(params)
      
      
      Severity: Minor
      Found in padrino-core/lib/padrino-core/application/routing.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 dispatch! has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

            def dispatch!
              @params = defined?(Sinatra::IndifferentHash) ? Sinatra::IndifferentHash[@request.params] : indifferent_params(@request.params)
              force_encoding(@params)
              invoke do
                static! if settings.static? && (request.get? || request.head?)
      Severity: Minor
      Found in padrino-core/lib/padrino-core/application/routing.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 parse_route has 54 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def parse_route(path, options, verb)
              path = path.dup if path.kind_of?(String)
              route_options = {}
      
              if options[:params] == true
      Severity: Major
      Found in padrino-core/lib/padrino-core/application/routing.rb - About 2 hrs to fix

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

              def provides_format(*types)
                mime_types = types.map{ |type| mime_type(CONTENT_TYPE_ALIASES[type] || type) }
                condition do
                  return provides_format?(types, params[:format].to_sym) if params[:format]
        
        
        Severity: Minor
        Found in padrino-core/lib/padrino-core/application/routing.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 route! has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

              def route!(base = settings, pass_block = nil)
                Thread.current['padrino.instance'] = self
                first_time = true
        
                routes = base.compiled_router.call(@request) do |route, params|
        Severity: Minor
        Found in padrino-core/lib/padrino-core/application/routing.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 construct_filter has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

              def construct_filter(*args, &block)
                options = args.last.is_a?(Hash) ? args.pop : {}
                if except = options.delete(:except)
                  fail "You cannot use :except with other options specified" unless args.empty? && options.empty?
                  except = Array(except)
        Severity: Minor
        Found in padrino-core/lib/padrino-core/application/routing.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 value_to_param has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

              def value_to_param(object)
                case object
                when Array
                  object.map { |item| value_to_param(item) }.compact
                when Hash
        Severity: Minor
        Found in padrino-core/lib/padrino-core/application/routing.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 rebase_url has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

              def rebase_url(url)
                if url.start_with?('/')
                  new_url = ''
                  new_url << conform_uri(ENV['RACK_BASE_URI']) if ENV['RACK_BASE_URI']
                  new_url << conform_uri(uri_root) if defined?(uri_root)
        Severity: Minor
        Found in padrino-core/lib/padrino-core/application/routing.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

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

              def provides_format?(types, format)
                if ([:any, format] & types).empty?
                  # Per rfc2616-sec14:
                  # Answer with 406 if accept is given but types to not match any provided type.
                  halt 406 if settings.respond_to?(:treat_format_as_accept) && settings.treat_format_as_accept
        Severity: Minor
        Found in padrino-core/lib/padrino-core/application/routing.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 csrf_protection has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def csrf_protection(enabled)
                return unless enabled
                condition do
                  if request.env['protection.csrf.failed']
                    message = settings.protect_from_csrf.kind_of?(Hash) && settings.protect_from_csrf[:message] || 'Forbidden'
        Severity: Minor
        Found in padrino-core/lib/padrino-core/application/routing.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 process_path_for_parent_params has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def process_path_for_parent_params(path, parent_params)
                parent_prefix = parent_params.flatten.compact.uniq.map do |param|
                  map  = (param.respond_to?(:map) && param.map ? param.map : param.to_s)
                  part = "#{map}/:#{Inflections.singularize(param)}_id/"
                  part = "(#{part})?" if param.respond_to?(:optional) && param.optional?
        Severity: Minor
        Found in padrino-core/lib/padrino-core/application/routing.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 static_file? has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

              def static_file?(path_info)
                return unless public_dir = settings.public_folder
                public_dir = File.expand_path(public_dir)
                path = File.expand_path(public_dir + unescape(path_info))
                return unless path.start_with?(public_dir)
        Severity: Minor
        Found in padrino-core/lib/padrino-core/application/routing.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