Dynamoid/dynamoid

View on GitHub

Showing 81 of 81 total issues

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

      def update_fields(hash_key_value, range_key_value = nil, attrs = {}, conditions = {})
        optional_params = [range_key_value, attrs, conditions].compact
        if optional_params.first.is_a?(Hash)
          range_key_value = nil
          attrs, conditions = optional_params[0..1]
Severity: Major
Found in lib/dynamoid/persistence.rb and 1 other location - About 1 hr to fix
lib/dynamoid/persistence.rb on lines 359..373

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

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 upsert(hash_key_value, range_key_value = nil, attrs = {}, conditions = {})
        optional_params = [range_key_value, attrs, conditions].compact
        if optional_params.first.is_a?(Hash)
          range_key_value = nil
          attrs, conditions = optional_params[0..1]
Severity: Major
Found in lib/dynamoid/persistence.rb and 1 other location - About 1 hr to fix
lib/dynamoid/persistence.rb on lines 301..315

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

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

      def call
        @model.hash_key = SecureRandom.uuid if @model.hash_key.blank?

        return true unless @model.changed?

Severity: Minor
Found in lib/dynamoid/persistence/save.rb - About 1 hr to fix

    Method build_request has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

            def build_request
              # expressions
              name_placeholder = +'#_a0'
              value_placeholder = +':_a0'
    
    
    Severity: Minor
    Found in lib/dynamoid/adapter_plugin/aws_sdk_v3/scan.rb - About 1 hr to fix

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

            def find_from_attributes(model_or_model_class, attributes)
              model_class = model_or_model_class.is_a?(Dynamoid::Document) ? model_or_model_class.class : model_or_model_class
              if attributes.is_a?(Hash)
                raise Dynamoid::Errors::MissingHashKey unless attributes[model_class.hash_key].present?
      
      
      Severity: Minor
      Found in lib/dynamoid/transaction_write/action.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 field_condition has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

            def field_condition(key, value_before_type_casting)
              name, operator = key.to_s.split('.')
              value = type_cast_condition_parameter(name, value_before_type_casting)
              operator ||= 'eq'
      
      
      Severity: Minor
      Found in lib/dynamoid/criteria/chain.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 delete has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def delete
            options = range_key ? { range_key: Dumping.dump_field(read_attribute(range_key), self.class.attributes[range_key]) } : {}
      
            # Add an optimistic locking check if the lock_version column exists
            if self.class.attributes[:lock_version]
      Severity: Minor
      Found in lib/dynamoid/persistence.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 update! has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def update!(conditions = {})
            run_callbacks(:update) do
              options = {}
              if range_key
                value = read_attribute(range_key)
      Severity: Minor
      Found in lib/dynamoid/persistence.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 find_all_by_secondary_index has 27 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def find_all_by_secondary_index(hash, options = {})
              ActiveSupport::Deprecation.warn('[Dynamoid] .find_all_by_secondary_index is deprecated! Call .where instead of')
      
              range = options[:range] || {}
              hash_key_field, hash_key_value = hash.first
      Severity: Minor
      Found in lib/dynamoid/finders.rb - About 1 hr to fix

        Method build_all_attribute_definitions has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def build_all_attribute_definitions(key_schema, secondary_indexes = {})
                  ls_indexes = secondary_indexes[:local_secondary_indexes]
                  gs_indexes = secondary_indexes[:global_secondary_indexes]
        
                  attribute_definitions = []
        Severity: Minor
        Found in lib/dynamoid/adapter_plugin/aws_sdk_v3/create_table.rb - About 1 hr to fix

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

                  def call
                    request = build_request
          
                    Enumerator.new do |yielder|
                      api_call = lambda do |req|
          Severity: Minor
          Found in lib/dynamoid/adapter_plugin/aws_sdk_v3/query.rb and 1 other location - About 55 mins to fix
          lib/dynamoid/adapter_plugin/aws_sdk_v3/scan.rb on lines 23..41

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

          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 call
                    request = build_request
          
                    Enumerator.new do |yielder|
                      api_call = lambda do |req|
          Severity: Minor
          Found in lib/dynamoid/adapter_plugin/aws_sdk_v3/scan.rb and 1 other location - About 55 mins to fix
          lib/dynamoid/adapter_plugin/aws_sdk_v3/query.rb on lines 30..48

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

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

                def batch_write_item(table_name, objects, options = {})
                  items = objects.map { |o| sanitize_item(o) }
          
                  while items.present?
                    batch = items.shift(BATCH_WRITE_ITEM_REQUESTS_LIMIT)
          Severity: Minor
          Found in lib/dynamoid/adapter_plugin/aws_sdk_v3.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 sanitize_item has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                def sanitize_item(attributes)
                  config_value = Dynamoid.config.store_attribute_with_nil_value
                  store_attribute_with_nil_value = config_value.nil? ? false : !!config_value
          
                  attributes.reject do |_, v|
          Severity: Minor
          Found in lib/dynamoid/adapter_plugin/aws_sdk_v3.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 to_h has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                def to_h
                  if model
                    # model.hash_key = SecureRandom.uuid if model.hash_key.blank?
                    touch_model_timestamps(skip_created_at: true)
                    changes = model.changes.map { |k, v| [k.to_sym, v[1]] }.to_h # hash of dirty attributes
          Severity: Minor
          Found in lib/dynamoid/transaction_write/update_upsert.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 call has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                  def call
                    counter = 0
                    resp = nil
                    begin
                      check = { again: true }
          Severity: Minor
          Found in lib/dynamoid/adapter_plugin/aws_sdk_v3/until_past_table_status.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 initialize has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def initialize(attrs = {}, &block)
                run_callbacks :initialize do
                  @new_record = true
                  @attributes ||= {}
                  @associations ||= {}
          Severity: Minor
          Found in lib/dynamoid/document.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 set_deletions has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                def set_deletions(expression_attribute_values, update_expression)
                  return update_expression unless deletions.present?
          
                  delete_keys = deletions.keys
                  update_expression += " DELETE #{delete_keys.each_with_index.map { |k, i| "#{k} :_d#{i}" }.join(', ')}"
          Severity: Minor
          Found in lib/dynamoid/transaction_write/update_upsert.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 sanitize_item has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                def sanitize_item(attributes)
                  config_value = Dynamoid.config.store_attribute_with_nil_value
                  store_attribute_with_nil_value = config_value.nil? ? false : !!config_value
          
                  attributes.reject do |_, v|
          Severity: Minor
          Found in lib/dynamoid/transaction_write/action.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

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

                def sanitize_item(attributes)
                  config_value = Dynamoid.config.store_attribute_with_nil_value
                  store_attribute_with_nil_value = config_value.nil? ? false : !!config_value
          
                  attributes.reject do |_, v|
          Severity: Minor
          Found in lib/dynamoid/transaction_write/action.rb and 1 other location - About 55 mins to fix
          lib/dynamoid/adapter_plugin/aws_sdk_v3.rb on lines 665..674

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

          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

          Severity
          Category
          Status
          Source
          Language