Showing 327 of 327 total issues

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

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

  def test_ssl_run_with_encrypted_pem
    skip_if :jruby

    config = <<~RUBY
      key_path  = '#{File.expand_path '../examples/puma/encrypted_puma_keypair.pem', __dir__}'
Severity: Major
Found in test/test_integration_ssl.rb and 1 other location - About 1 hr to fix
test/test_integration_ssl.rb on lines 256..285

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 68.

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

  def test_ssl_run_with_encrypted_key
    skip_if :jruby

    config = <<~RUBY
      key_path  = '#{File.expand_path '../examples/puma/encrypted_puma_keypair.pem', __dir__}'
Severity: Major
Found in test/test_integration_ssl.rb and 1 other location - About 1 hr to fix
test/test_integration_ssl.rb on lines 289..318

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 68.

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 test_verify_client_cert_roundtrip has 42 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def test_verify_client_cert_roundtrip(tls1_2 = nil)
    cert_path = File.expand_path '../examples/puma/client-certs', __dir__
    bind_port

    config = <<~CONFIG
Severity: Minor
Found in test/test_integration_ssl.rb - About 1 hr to fix

    Method aggregated_results has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def aggregated_results(io)
        is_github_actions = ENV['GITHUB_ACTIONS'] == 'true'
        filtered_results = results.dup
    
        if options[:verbose]
    Severity: Minor
    Found in test/helper.rb - About 1 hr to fix

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

          def initialize(app, events = nil, options = {})
            @app = app
            @events = events || Events.new
      
            @check, @notify = nil
      Severity: Minor
      Found in lib/puma/server.rb - About 1 hr to fix

        Method call has 41 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

              def call(env)
                unless authenticate(env)
                  return rack_response(403, 'Invalid auth token', 'text/plain')
                end
        
        
        Severity: Minor
        Found in lib/puma/app/status.rb - About 1 hr to fix

          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 str_early_hints has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def str_early_hints(headers)
                  eh_str = +""
                  headers.each_pair do |k, vs|
                    next if illegal_header_key?(k)
            
            
            Severity: Minor
            Found in lib/puma/request.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 aggregated_results has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

              def aggregated_results(io)
                is_github_actions = ENV['GITHUB_ACTIONS'] == 'true'
                filtered_results = results.dup
            
                if options[:verbose]
            Severity: Minor
            Found in test/helper.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 ci_test_rps has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def ci_test_rps
                  host = ENV['HOST']
                  port = ENV['PORT'].to_i
            
                  str = 'a' * 65_500
            Severity: Minor
            Found in benchmarks/local/response_time_wrk.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 oob_server has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

              def oob_server(**options)
                @request_count = 0
                @oob_count = 0
                in_oob = Mutex.new
                @mutex = Mutex.new
            Severity: Minor
            Found in test/test_out_of_band_server.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 call has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def call(env)
                    unless authenticate(env)
                      return rack_response(403, 'Invalid auth token', 'text/plain')
                    end
            
            
            Severity: Minor
            Found in lib/puma/app/status.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 generate_restart_data has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def generate_restart_data
                  if dir = @options[:directory]
                    @restart_dir = dir
            
                  elsif Puma.windows?
            Severity: Minor
            Found in lib/puma/launcher.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 config has 39 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def config(app, options = {})
                  require_relative '../../puma'
                  require_relative '../../puma/configuration'
                  require_relative '../../puma/log_writer'
                  require_relative '../../puma/launcher'
            Severity: Minor
            Found in lib/rack/handler/puma.rb - About 1 hr to fix

              Method read_response_array has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def read_response_array(skts, resp_count: nil, body_only: nil)
                    results = Array.new skts.length
                    Thread.new do
                      until skts.compact.empty?
                        skts.each_with_index do |skt, idx|
              Severity: Minor
              Found in test/helpers/test_puma/puma_socket.rb - About 1 hr to fix

                Method setup_signals has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    def setup_signals
                      if @options[:fork_worker]
                        Signal.trap "SIGURG" do
                          fork_worker!
                        end
                Severity: Minor
                Found in lib/puma/cluster.rb - About 1 hr to fix

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

                      def initialize
                        sleep 5 # wait for server to boot
                  
                        @thread_loops       = nil
                        @clients_per_thread = nil
                  Severity: Minor
                  Found in benchmarks/local/bench_base.rb - About 1 hr to fix

                    Method req_env_post_parse has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def req_env_post_parse(env)
                          to_delete = nil
                          to_add = nil
                    
                          env.each do |k,v|
                    Severity: Minor
                    Found in lib/puma/request.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

                    Severity
                    Category
                    Status
                    Source
                    Language