moneta-rb/moneta

View on GitHub

Showing 112 of 112 total issues

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

      def merge!(pairs, options = {})
        transaction = @backend.transaction if block_given?

        if block_given?
          existing = Hash[slice(*pairs.map { |k, _| k }.to_a)]
Severity: Minor
Found in lib/moneta/adapters/sqlite.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 fetch_values has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def fetch_values(*keys, **options)
      return super if options.include?(:raw)
      new_expires = expires_at(options, nil)
      options = Utils.without(options, :expires)
      substituted = {}
Severity: Minor
Found in lib/moneta/expires.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 initialize has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    def initialize(adapter, options = {})
      super(adapter, options)

      @default_options = adapter.respond_to?(:default_options) ? adapter.default_options.dup : {}

Severity: Minor
Found in lib/moneta/optionmerger.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 merge! has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

      def merge!(pairs, options = {})
        hard = options.key?(:hard) ? options[:hard] : false
        atomic = options.key?(:atomic) ? options[:atomic] : true

        success =
Severity: Minor
Found in lib/moneta/adapters/kyotocabinet.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 handle has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def handle(io, buffer)
      return if buffer.bytesize < 8 # At least 4 bytes for the marshalled array
      size = buffer[0, 4].unpack('N').first
      if size > MAXSIZE
        delete_client(io)
Severity: Minor
Found in lib/moneta/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 store has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

      def store(key, value, options = {})
        if @max_value && value.bytesize > @max_value
          delete(key)
        else
          if @max_size
Severity: Minor
Found in lib/moneta/adapters/lruhash.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 increment has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

      def increment(key, amount = 1, options = {})
        result = if amount >= 0
                   @backend.increment(key, amount)
                 else
                   @backend.decrement(key, -amount)
Severity: Minor
Found in lib/moneta/adapters/memcached/native.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 initialize has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def initialize(options = {})
        @key_column = options.delete(:key_column) || :k
        @value_column = options.delete(:value_column) || :v

        if backend = options.delete(:backend)
Severity: Minor
Found in lib/moneta/adapters/activerecord.rb - About 1 hr to fix

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

      def self.new(name, options = {})
        expires = options[:expires]
        options.delete(:expires) unless Numeric === expires
        logger = options.delete(:logger)
        threadsafe = options.delete(:threadsafe)
    Severity: Minor
    Found in lib/moneta.rb - About 1 hr to fix

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

          def call(env)
            key = env['PATH_INFO'][1..-1].to_s
            case env['REQUEST_METHOD']
            when 'HEAD'
              if key.empty?
      Severity: Minor
      Found in lib/rack/moneta_rest.rb - About 1 hr to fix

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

              def self.new(options = {})
                extensions = options.delete(:extensions)
                connection_validation_timeout = options.delete(:connection_validation_timeout)
                optimize = options.delete(:optimize)
                backend = options.delete(:backend) ||
        Severity: Minor
        Found in lib/moneta/adapters/sequel.rb - About 1 hr to fix

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

                def clear(options = {})
                  loop do
                    docs = all_docs(limit: 10_000)
                    break if docs['rows'].empty?
                    deletions = docs['rows'].map do |row|
          Severity: Minor
          Found in lib/moneta/adapters/couch.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 store has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                def store(key, value, options = {})
                  put(key, value_to_doc(value, rev(key)),
                      headers: full_commit_header(options[:full_commit]),
                      query: options[:batch] ? { batch: 'ok' } : {},
                      cache_rev: options[:cache_rev] != false,
          Severity: Minor
          Found in lib/moneta/adapters/couch.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 merge! has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

                def merge!(pairs, options = {})
                  keys = pairs.map { |key, _| key }.to_a
                  cache_revs(*keys.reject { |key| @rev_cache[key] })
          
                  if block_given?
          Severity: Minor
          Found in lib/moneta/adapters/couch.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 fetch has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def fetch(key, default = nil, options = nil)
                if block_given?
                  raise ArgumentError, 'Only one argument accepted if block is given' if options
                  result = load(key, default || {})
                  result == nil ? yield(key) : result
          Severity: Minor
          Found in lib/moneta/mixins.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 merge! has 33 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def merge!(pairs, options = {})
                  keys = pairs.map { |key, _| key }.to_a
                  cache_revs(*keys.reject { |key| @rev_cache[key] })
          
                  if block_given?
          Severity: Minor
          Found in lib/moneta/adapters/couch.rb - About 1 hr to fix

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

                  def slice(*keys, **options)
                    query = @collection.find(_id: { :$in => keys.map(&method(:to_binary)) })
                    pairs = query.map do |doc|
                      next if doc[@expires_field] && doc[@expires_field] < Time.now
                      [from_binary(doc[:_id]), doc_to_value(doc)]
            Severity: Major
            Found in lib/moneta/adapters/mongo/moped.rb and 1 other location - About 1 hr to fix
            lib/moneta/adapters/mongo/official.rb on lines 123..134

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

            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 slice(*keys, **options)
                    query = @collection.find(_id: { :$in => keys.map(&method(:to_binary)) })
                    pairs = query.map do |doc|
                      next if doc[@expires_field] && doc[@expires_field] < Time.now
                      [from_binary(doc[:_id]), doc_to_value(doc)]
            Severity: Major
            Found in lib/moneta/adapters/mongo/official.rb and 1 other location - About 1 hr to fix
            lib/moneta/adapters/mongo/moped.rb on lines 121..132

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

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

                  def initialize(app, options = {}, &block)
                    super
                    if block
                      raise ArgumentError, 'Use either block or option :store' if options[:store]
                      @pool = ::Moneta.build(&block)
            Severity: Minor
            Found in lib/rack/session/moneta.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 start_server has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
            Open

                def start_server
                  @connect_lock.synchronize do
                    begin
                      raise "Adapter already set" if @adapter
                      @adapter = Lock.new(@builder.build.last)
            Severity: Minor
            Found in lib/moneta/shared.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