ruby-grape/grape-swagger

View on GitHub
lib/grape-swagger/endpoint.rb

Summary

Maintainability
D
2 days
Test Coverage

Class Endpoint has 38 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Endpoint
    def content_types_for(target_class)
      content_types = (target_class.content_types || {}).values

      if content_types.empty?
Severity: Minor
Found in lib/grape-swagger/endpoint.rb - About 5 hrs to fix

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

        def response_object(route, options)
          codes(route).each_with_object({}) do |value, memo|
            value[:message] ||= ''
            memo[value[:code]] = { description: value[:message] ||= '' } unless memo[value[:code]].present?
            memo[value[:code]][:headers] = value[:headers] if value[:headers]
    Severity: Minor
    Found in lib/grape-swagger/endpoint.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

    File endpoint.rb has 329 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'active_support'
    require 'active_support/core_ext/string/inflections'
    require 'grape-swagger/endpoint/params_parser'
    
    module Grape
    Severity: Minor
    Found in lib/grape-swagger/endpoint.rb - About 3 hrs to fix

      Method success_code_from_entity has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          def success_code_from_entity(route, entity)
            default_code = GrapeSwagger::DocMethods::StatusCodes.get[route.request_method.downcase.to_sym]
            if entity.is_a?(Hash)
              default_code[:code] = entity[:code] if entity[:code].present?
              default_code[:model] = entity[:model] if entity[:model].present?
      Severity: Minor
      Found in lib/grape-swagger/endpoint.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 params_object has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def params_object(route, options, path)
            parameters = build_request_params(route, options).each_with_object([]) do |(param, value), memo|
              next if hidden_parameter?(value)
      
              value = { required: false }.merge(value) if value.is_a?(Hash)
      Severity: Minor
      Found in lib/grape-swagger/endpoint.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 build_memo_schema has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def build_memo_schema(memo, route, value, response_model, options)
      Severity: Minor
      Found in lib/grape-swagger/endpoint.rb - About 35 mins to fix

        Method build_reference has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def build_reference(route, value, response_model, settings)
              # TODO: proof that the definition exist, if model isn't specified
              reference = if value.key?(:as)
                            { value[:as] => build_reference_hash(response_model) }
                          else
        Severity: Minor
        Found in lib/grape-swagger/endpoint.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 path_item has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def path_item(routes, options)
              routes.each do |route|
                next if hidden?(route, options)
        
                @item, path = GrapeSwagger::DocMethods::PathString.build(route, options)
        Severity: Minor
        Found in lib/grape-swagger/endpoint.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 expose_params has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def expose_params(value)
              if value.is_a?(Class) && GrapeSwagger.model_parsers.find(value)
                expose_params_from_model(value)
              elsif value.is_a?(String)
                begin
        Severity: Minor
        Found in lib/grape-swagger/endpoint.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 produces_object has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def produces_object(route, format)
              return ['application/octet-stream'] if file_response?(route.attributes.success) &&
                                                     !route.attributes.produces.present?
        
              mime_types = GrapeSwagger::DocMethods::ProducesConsumes.call(format)
        Severity: Minor
        Found in lib/grape-swagger/endpoint.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