mepatterson/grape_ape_rails

View on GitHub

Showing 21 of 21 total issues

Method setup has a Cognitive Complexity of 90 (exceeds 5 allowed). Consider refactoring.
Open

          def self.setup(options)
            defaults = {
              target_class: nil,
              mount_path: '/swagger_doc',
              mount_with_version: false,
Severity: Minor
Found in lib/swagger/grape_swagger_modified.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 parse_params has a Cognitive Complexity of 89 (exceeds 5 allowed). Consider refactoring.
Open

            def parse_params(params, path, method)
              params ||= []
              params.map do |param, value|
                value[:type] = 'File' if value.is_a?(Hash) && value[:type] == 'Rack::Multipart::UploadedFile'
                items = {}
Severity: Minor
Found in lib/swagger/grape_swagger_modified.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 create_documentation_class has 348 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def create_documentation_class
        Class.new(Grape::API) do
          class << self
            def name
              @@class_name
Severity: Major
Found in lib/swagger/grape_swagger_modified.rb - About 1 day to fix

    File grape_swagger_modified.rb has 388 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'kramdown'
    module Grape
      class API
        class << self
          attr_reader :combined_routes, :combined_namespaces
    Severity: Minor
    Found in lib/swagger/grape_swagger_modified.rb - About 5 hrs to fix

      Method parse_entity_models has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

                  def parse_entity_models(models)
                    result = {}
                    models.each do |model|
                      name       = parse_entity_name(model)
                      properties = {}
      Severity: Minor
      Found in lib/swagger/grape_swagger_modified.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 parse_header_params has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

                  def parse_header_params(params)
                    params ||= []
      
                    params.map do |param, value|
                      data_type     = 'String'
      Severity: Minor
      Found in lib/swagger/grape_swagger_modified.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 add_swagger_documentation has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

            def add_swagger_documentation(options = {})
              documentation_class = create_documentation_class
              documentation_class.setup({ target_class: self }.merge(options))
              mount(documentation_class)
      
      
      Severity: Minor
      Found in lib/swagger/grape_swagger_modified.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 parse_base_path has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

                  def parse_base_path(base_path, request)
                    if base_path.is_a?(Proc)
                      base_path.call(request)
                    elsif base_path.is_a?(String)
                      URI(base_path).relative? ? URI.join(request.base_url, base_path).to_s : base_path
      Severity: Minor
      Found in lib/swagger/grape_swagger_modified.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 parse_http_codes has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

                  def parse_http_codes(codes, models)
                    codes ||= {}
                    codes.map do |k, v, m|
                      models << m if m
                      http_code_hash = {
      Severity: Minor
      Found in lib/swagger/grape_swagger_modified.rb - About 55 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 combine_namespaces has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

            def combine_namespaces(app)
              app.endpoints.each do |endpoint|
                ns = if endpoint.respond_to?(:namespace_stackable)
                       endpoint.namespace_stackable(:namespace).last
                     else
      Severity: Minor
      Found in lib/swagger/grape_swagger_modified.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 parse_path has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

                  def parse_path(path, version)
                    # adapt format to swagger format
                    parsed_path = path.gsub('(.:format)', @@hide_format ? '' : '.{format}')
                    # This is attempting to emulate the behavior of
                    # Rack::Mount::Strexp. We cannot use Strexp directly because
      Severity: Minor
      Found in lib/swagger/grape_swagger_modified.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 content_types_for has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

                  def content_types_for(target_class)
                    content_types = (target_class.settings[:content_types] || {}).values
      
                    if content_types.empty?
                      formats       = [target_class.settings[:format], target_class.settings[:default_format]].compact.uniq
      Severity: Minor
      Found in lib/swagger/grape_swagger_modified.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 layout_template has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

              def layout_template
                set_layouts_base unless env['api.tilt.layouts_base']
                ver = env['rack.routing_args'][:route_info].route_version
                layout_path = "#{env['api.tilt.layouts_base']}/#{ver}.json.haml"
                if File.exist?(layout_path)
      Severity: Minor
      Found in lib/grape_ape_rails/handlers/formatters.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

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

                if defined?(::Rails) && Rails.respond_to?(:logger)
                  api_version = "[#{env['rack.routing_args'][:route_info].route_version}]" rescue nil
                  Rails.logger.warn "[API]#{api_version} Responding with #{status} #{log_msg}"
                end
      Severity: Minor
      Found in lib/grape_ape_rails/handlers/responses.rb and 1 other location - About 35 mins to fix
      lib/grape_ape_rails/api.rb on lines 102..105

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 34.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          if defined?(::Rails) && Rails.respond_to?(:logger)
            api_version = "[#{env['rack.routing_args'][:route_info].route_version}]" rescue nil
            Rails.logger.warn "[API]#{api_version} Responding with #{status} #{message}"
          end
      Severity: Minor
      Found in lib/grape_ape_rails/api.rb and 1 other location - About 35 mins to fix
      lib/grape_ape_rails/handlers/responses.rb on lines 23..26

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 34.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              before do
                req = Rack::Request.new(env)
                api_key = version ? GrapeApeRails::API.api_keys_map[version] : nil
                if api_key.nil?
                  msg = "Cannot determine API version from header info."
      Severity: Minor
      Found in lib/grape_ape_rails/handlers/path_versioning.rb and 1 other location - About 25 mins to fix
      lib/grape_ape_rails/handlers/header_versioning.rb on lines 15..20

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 30.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

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

            def configure_tilt_root
              say "\n\nConfiguring Tilt for RABL templates..."
              say ("-"*80)
      
              if yes?("Will you be using RABL templates? (y/n)")
      Severity: Minor
      Found in lib/generators/grape_ape_rails/setup_generator.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

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              before do
                req = Rack::Request.new(env)
                api_key = version ? GrapeApeRails::API.api_keys_map[version] : nil
                if api_key.nil?
                  msg = "Cannot determine API version from header info."
      Severity: Minor
      Found in lib/grape_ape_rails/handlers/header_versioning.rb and 1 other location - About 25 mins to fix
      lib/grape_ape_rails/handlers/path_versioning.rb on lines 15..20

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 30.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

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

        def error!(message, status = nil, headers = nil)
          if defined?(::Rails) && Rails.respond_to?(:logger)
            api_version = "[#{env['rack.routing_args'][:route_info].route_version}]" rescue nil
            Rails.logger.warn "[API]#{api_version} Responding with #{status} #{message}"
          end
      Severity: Minor
      Found in lib/grape_ape_rails/api.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 call has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

            def self.call(message, backtrace, options, env)
              err = { error: { code: 'ERROR', message: message } }
              if message.is_a?(Hash) && message[:code].present? && message[:message].present?
                full_msg = "[#{message[:code]}] #{message[:message]}"
                err = { error: { code: message[:code], message: full_msg } }
      Severity: Minor
      Found in lib/grape_ape_rails/handlers/formatters.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

      Severity
      Category
      Status
      Source
      Language