Dynamoid/dynamoid

View on GitHub

Showing 85 of 85 total issues

Method build_request has 34 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/query.rb - About 1 hr to fix

    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 319..333

    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 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 377..391

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

          def action_request
            # changed attributes to persist
            changes = @attributes.dup
            changes = add_timestamps(changes, skip_created_at: true)
            changes_dumped = Dynamoid::Dumping.dump_attributes(changes, @model_class.attributes)
    Severity: Minor
    Found in lib/dynamoid/transaction_write/update_fields.rb - About 1 hr to fix

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

                def on_registration
                  validate_model!
          
                  if @options[:validate] != false && !(@valid = @model.valid?)
                    if @options[:raise_error]
          Severity: Minor
          Found in lib/dynamoid/transaction_write/save.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 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 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 = {})
                  Dynamoid.deprecator.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 dup_attribute has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                    def self.dup_attribute(value, type_options)
                      type, of = type_options.values_at(:type, :of)
              
                      case value
                      when NilClass, TrueClass, FalseClass, Numeric, Symbol, IO
              Severity: Minor
              Found in lib/dynamoid/dirty.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 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 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 touch_model_timestamps has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                    def touch_model_timestamps(skip_created_at:)
                      return unless @model_class.timestamps_enabled?
              
                      timestamp = DateTime.now.in_time_zone(Time.zone)
                      @model.updated_at = timestamp unless @options[:touch] == false && !@was_new_record
              Severity: Minor
              Found in lib/dynamoid/transaction_write/save.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

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

                    def _find_by_id(id, options = {})
                      raise Errors::MissingRangeKey if range_key && options[:range_key].nil?
              
                      if range_key
                        key = options[:range_key]
              Severity: Minor
              Found in lib/dynamoid/finders.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