lib/puma/client.rb

Summary

Maintainability
F
5 days
Test Coverage

Method decode_chunk has a Cognitive Complexity of 64 (exceeds 5 allowed). Consider refactoring.
Open

    def decode_chunk(chunk)
      if @partial_part_left > 0
        if @partial_part_left <= chunk.size
          if @partial_part_left > 2
            write_chunk(chunk[0..(@partial_part_left-3)]) # skip the \r\n
Severity: Minor
Found in lib/puma/client.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

File client.rb has 484 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class IO
  # We need to use this for a jruby work around on both 1.8 and 1.9.
  # So this either creates the constant (on 1.8), or harmlessly
  # reopens it (on 1.9).
  module WaitReadable
Severity: Minor
Found in lib/puma/client.rb - About 7 hrs to fix

    Method setup_body has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

        def setup_body
          @body_read_start = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
    
          if @env[HTTP_EXPECT] == CONTINUE
            # TODO allow a hook here to check the headers before
    Severity: Minor
    Found in lib/puma/client.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 decode_chunk has 92 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def decode_chunk(chunk)
          if @partial_part_left > 0
            if @partial_part_left <= chunk.size
              if @partial_part_left > 2
                write_chunk(chunk[0..(@partial_part_left-3)]) # skip the \r\n
    Severity: Major
    Found in lib/puma/client.rb - About 3 hrs to fix

      Class Client has 28 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class Client # :nodoc:
      
          # this tests all values but the last, which must be chunked
          ALLOWED_TRANSFER_ENCODING = %w[compress deflate gzip].freeze
      
      
      Severity: Minor
      Found in lib/puma/client.rb - About 3 hrs to fix

        Method setup_body has 74 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def setup_body
              @body_read_start = Process.clock_gettime(Process::CLOCK_MONOTONIC, :float_millisecond)
        
              if @env[HTTP_EXPECT] == CONTINUE
                # TODO allow a hook here to check the headers before
        Severity: Major
        Found in lib/puma/client.rb - About 2 hrs to fix

          Method try_to_parse_proxy_protocol has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
          Open

              def try_to_parse_proxy_protocol
                if @read_proxy
                  if @expect_proxy_proto == :v1
                    if @buffer.include? "\r\n"
                      if md = PROXY_PROTOCOL_V1_REGEX.match(@buffer)
          Severity: Minor
          Found in lib/puma/client.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 reset has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def reset(fast_check=true)
                @parser.reset
                @io_buffer.reset
                @read_header = true
                @read_proxy = !!@expect_proxy_proto
          Severity: Minor
          Found in lib/puma/client.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 try_to_finish has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def try_to_finish
                if env[CONTENT_LENGTH] && above_http_content_limit(env[CONTENT_LENGTH].to_i)
                  @http_content_length_limit_exceeded = true
                end
          
          
          Severity: Minor
          Found in lib/puma/client.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 try_to_finish has 40 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def try_to_finish
                if env[CONTENT_LENGTH] && above_http_content_limit(env[CONTENT_LENGTH].to_i)
                  @http_content_length_limit_exceeded = true
                end
          
          
          Severity: Minor
          Found in lib/puma/client.rb - About 1 hr to fix

            Method reset has 31 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def reset(fast_check=true)
                  @parser.reset
                  @io_buffer.reset
                  @read_header = true
                  @read_proxy = !!@expect_proxy_proto
            Severity: Minor
            Found in lib/puma/client.rb - About 1 hr to fix

              Method read_body has 31 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def read_body
                    if @chunked_body
                      return read_chunked_body
                    end
              
              
              Severity: Minor
              Found in lib/puma/client.rb - About 1 hr to fix

                Method initialize has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def initialize(io, env=nil)
                      @io = io
                      @to_io = io.to_io
                      @io_buffer = IOBuffer.new
                      @proto_env = env
                Severity: Minor
                Found in lib/puma/client.rb - About 1 hr to fix

                  Method read_chunked_body has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def read_chunked_body
                        while true
                          begin
                            chunk = @io.read_nonblock(4096, @read_buffer)
                          rescue IO::WaitReadable
                  Severity: Minor
                  Found in lib/puma/client.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

                  Avoid deeply nested control flow statements.
                  Open

                                start_of_rest = if rest.start_with?(CHUNK_VALID_ENDING)
                                  CHUNK_VALID_ENDING_SIZE
                                else # we have started a trailer section, which we do not support. skip it!
                                  rest.index(CHUNK_VALID_ENDING*2) + CHUNK_VALID_ENDING_SIZE*2
                                end
                  Severity: Major
                  Found in lib/puma/client.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                  @buffer = nil if @buffer.empty?
                    Severity: Major
                    Found in lib/puma/client.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                    if md[1]
                                      @peerip = md[1].split(" ")[0]
                                    end
                      Severity: Major
                      Found in lib/puma/client.rb - About 45 mins to fix

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

                            def read_body
                              if @chunked_body
                                return read_chunked_body
                              end
                        
                        
                        Severity: Minor
                        Found in lib/puma/client.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

                        Avoid too many return statements within this method.
                        Open

                                return setup_body
                        Severity: Major
                        Found in lib/puma/client.rb - About 30 mins to fix

                          There are no issues that match your filters.

                          Category
                          Status