petergoldstein/dalli

View on GitHub

Showing 40 of 40 total issues

File server.rb has 600 lines of code (exceeds 250 allowed). Consider refactoring.
Open

require 'socket'
require 'timeout'

module Dalli
  class Server
Severity: Major
Found in lib/dalli/server.rb - About 1 day to fix

    Class Server has 59 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Server
        attr_accessor :hostname
        attr_accessor :port
        attr_accessor :weight
        attr_accessor :options
    Severity: Major
    Found in lib/dalli/server.rb - About 1 day to fix

      Method get_multi_yielder has a Cognitive Complexity of 39 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_multi_yielder(keys)
            perform do
              return {} if keys.empty?
              ring.lock do
                begin
      Severity: Minor
      Found in lib/dalli/client.rb - About 5 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

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

        class Client
      
          ##
          # Dalli::Client is the main class which developers will use to interact with
          # the memcached server.  Usage:
      Severity: Minor
      Found in lib/dalli/client.rb - About 5 hrs to fix

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

        require 'digest/md5'
        require 'set'
        
        # encoding: ascii
        module Dalli
        Severity: Minor
        Found in lib/dalli/client.rb - About 3 hrs to fix

          Method multi_response_nonblock has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
          Open

              def multi_response_nonblock
                raise 'multi_response has completed' if @multi_buffer.nil?
          
                @multi_buffer << @sock.read_available
                buf = @multi_buffer
          Severity: Minor
          Found in lib/dalli/server.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 get_multi_yielder has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def get_multi_yielder(keys)
                perform do
                  return {} if keys.empty?
                  ring.lock do
                    begin
          Severity: Minor
          Found in lib/dalli/client.rb - About 1 hr to fix

            Method readfull has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                  def readfull(count)
                    value = String.new('')
                    begin
                      while true
                        value << read_nonblock(count - value.bytesize)
            Severity: Minor
            Found in lib/dalli/socket.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 server_for_key has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def server_for_key(key)
                  if @continuum
                    hkey = hash_for(key)
                    20.times do |try|
                      entryidx = binary_search(@continuum, hkey)
            Severity: Minor
            Found in lib/dalli/ring.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 generic_response has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                def generic_response(unpack=false, cache_nils=false)
                  (extras, _, status, count) = read_header.unpack(NORMAL_HEADER)
                  data = read(count) if count > 0
                  if status == 1
                    cache_nils ? NOT_FOUND : nil
            Severity: Minor
            Found in lib/dalli/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 serialize has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
            Open

                def serialize(key, value, options=nil)
                  marshalled = false
                  value = unless options && options[:raw]
                    marshalled = true
                    begin
            Severity: Minor
            Found in lib/dalli/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 deserialize has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                def deserialize(value, flags)
                  value = self.compressor.decompress(value) if (flags & FLAG_COMPRESSED) != 0
                  value = self.serializer.load(value) if (flags & FLAG_SERIALIZED) != 0
                  value
                rescue TypeError
            Severity: Minor
            Found in lib/dalli/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

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

                def set(key, value, ttl, cas, options)
                  (value, flags) = serialize(key, value, options)
                  ttl = sanitize_ttl(ttl)
            
                  guard_max_value(key, value) do
            Severity: Major
            Found in lib/dalli/server.rb and 1 other location - About 1 hr to fix
            lib/dalli/server.rb on lines 306..314

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

            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 replace(key, value, ttl, cas, options)
                  (value, flags) = serialize(key, value, options)
                  ttl = sanitize_ttl(ttl)
            
                  guard_max_value(key, value) do
            Severity: Major
            Found in lib/dalli/server.rb and 1 other location - About 1 hr to fix
            lib/dalli/server.rb on lines 284..292

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

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

                def multi_response_nonblock
                  raise 'multi_response has completed' if @multi_buffer.nil?
            
                  @multi_buffer << @sock.read_available
                  buf = @multi_buffer
            Severity: Minor
            Found in lib/dalli/server.rb - About 1 hr to fix

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

                    def extract_dalli_options(options)
                      return [options[:cache]] if options[:cache]
              
                      # Filter out Rack::Session-specific options and apply our defaults
                      mopts = DEFAULT_DALLI_OPTIONS.merge \
              Severity: Minor
              Found in lib/rack/session/dalli.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 sasl_authentication has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  def sasl_authentication
                    Dalli.logger.info { "Dalli/SASL authenticating as #{username}" }
              
                    # negotiate
                    req = [REQUEST, OPCODES[:auth_negotiation], 0, 0, 0, 0, 0, 0, 0].pack(FORMAT[:noop])
              Severity: Minor
              Found in lib/dalli/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 serialize has 26 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  def serialize(key, value, options=nil)
                    marshalled = false
                    value = unless options && options[:raw]
                      marshalled = true
                      begin
              Severity: Minor
              Found in lib/dalli/server.rb - About 1 hr to fix

                Method with_block has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                      def with_block(env, default=nil, &block)
                        @mutex.lock if @mutex and env['rack.multithread']
                        @pool.with(&block)
                      rescue ::Dalli::DalliError, Errno::ECONNREFUSED
                        raise if $!.message =~ /undefined class/
                Severity: Minor
                Found in lib/rack/session/dalli.rb - About 55 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 get_session has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                      def get_session(env, sid)
                        with_block(env, [nil, {}]) do |dc|
                          unless sid and !sid.empty? and session = dc.get(sid)
                            old_sid, sid, session = sid, generate_sid_with(dc), {}
                            unless dc.add(sid, session, @default_ttl)
                Severity: Minor
                Found in lib/rack/session/dalli.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

                Severity
                Category
                Status
                Source
                Language