ruby-grape/grape

View on GitHub
lib/grape/middleware/formatter.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Method read_rack_input has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

      def read_rack_input(body)
        fmt = request.media_type ? mime_types[request.media_type] : options[:default_format]

        throw :error, status: 415, message: "The provided content-type '#{request.media_type}' is not supported." unless content_type_for(fmt)
        parser = Grape::Parser.parser_for fmt, **options
Severity: Minor
Found in lib/grape/middleware/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

Consider simplifying this complex logical expression.
Open

        return unless
          (request.post? || request.put? || request.patch? || request.delete?) &&
          (!request.form_data? || !request.media_type) &&
          !request.parseable_data? &&
          (request.content_length.to_i.positive? || request.env[Grape::Http::Headers::HTTP_TRANSFER_ENCODING] == CHUNKED)
Severity: Critical
Found in lib/grape/middleware/formatter.rb - About 1 hr to fix

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

          def read_body_input
            return unless
              (request.post? || request.put? || request.patch? || request.delete?) &&
              (!request.form_data? || !request.media_type) &&
              !request.parseable_data? &&
    Severity: Minor
    Found in lib/grape/middleware/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 mime_array has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def mime_array
            accept = env[Grape::Http::Headers::HTTP_ACCEPT]
            return [] unless accept
    
            accept_into_mime_and_quality = %r{
    Severity: Minor
    Found in lib/grape/middleware/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