rswag-specs/lib/rswag/specs/swagger_formatter.rb

Summary

Maintainability
C
1 day
Test Coverage

Method stop has a Cognitive Complexity of 54 (exceeds 5 allowed). Consider refactoring.
Open

      def stop(_notification = nil)
        @config.openapi_specs.each do |url_path, doc|
          unless doc_version(doc).start_with?('2')
            doc[:paths]&.each_pair do |_k, v|
              v.each_pair do |_verb, value|
Severity: Minor
Found in rswag-specs/lib/rswag/specs/swagger_formatter.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 stop has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def stop(_notification = nil)
        @config.openapi_specs.each do |url_path, doc|
          unless doc_version(doc).start_with?('2')
            doc[:paths]&.each_pair do |_k, v|
              v.each_pair do |_verb, value|
Severity: Minor
Found in rswag-specs/lib/rswag/specs/swagger_formatter.rb - About 1 hr to fix

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

          def upgrade_oauth!(swagger_doc)
            # find flow in securitySchemes (securityDefinitions will have been re-written)
            schemes = swagger_doc.dig(:components, :securitySchemes)
            return unless schemes&.any? { |_k, v| v.key?(:flow) }
    
    
    Severity: Minor
    Found in rswag-specs/lib/rswag/specs/swagger_formatter.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 example_group_finished has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

          def example_group_finished(notification)
            metadata = if RSPEC_VERSION > 2
              notification.group.metadata
            else
              notification.metadata
    Severity: Minor
    Found in rswag-specs/lib/rswag/specs/swagger_formatter.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

    Consider simplifying this complex logical expression.
    Open

                    if is_hash && value[:parameters]
                      schema_param = value[:parameters]&.find { |p| (p[:in] == :body || p[:in] == :formData) && p[:schema] }
                      mime_list = value[:consumes] || doc[:consumes]
    
                      if value && schema_param && mime_list
    Severity: Major
    Found in rswag-specs/lib/rswag/specs/swagger_formatter.rb - About 40 mins to fix

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

            def remove_invalid_operation_keys!(value)
              return unless value.is_a?(Hash)
      
              value.delete(:consumes) if value[:consumes]
              value.delete(:produces) if value[:produces]
      Severity: Minor
      Found in rswag-specs/lib/rswag/specs/swagger_formatter.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