datamapper/dm-core

View on GitHub

Showing 115 of 115 total issues

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

        def create_intermediary(execute_hooks, resource = nil)
          intermediary_for = self.intermediary_for

          intermediary_resource = intermediary_for[resource]
          return intermediary_resource if intermediary_resource
Severity: Minor
Found in lib/dm-core/associations/many_to_many.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 last has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

    def last(*args)
      first_arg = args.first
      last_arg  = args.last

      limit_specified = first_arg.kind_of?(Integer)
Severity: Minor
Found in lib/dm-core/model.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 new has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

        def new(*args, &block)
          if args.size == 1 && args.first.kind_of?(Hash)
            discriminator = properties(repository_name).discriminator

            if discriminator_value = args.first[discriminator.name]
Severity: Minor
Found in lib/dm-core/property/discriminator.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 lazy_load has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

    def lazy_load
      if loaded?
        return self
      end

Severity: Minor
Found in lib/dm-core/collection.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 child_relationships has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

    def child_relationships
      child_relationships = []

      relationships.each do |relationship|
        next unless relationship.respond_to?(:collection_for)
Severity: Minor
Found in lib/dm-core/resource.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 has has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.

      def has(cardinality, name, *args)
        name    = name.to_sym
        model   = extract_model(args)
        options = extract_options(args)

Severity: Minor
Found in lib/dm-core/model/relationship.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

Consider simplifying this complex logical expression.

      if required? && dumped_value.nil?
        negated || false
      else
        value_dumped?(dumped_value) || (dumped_value.nil? && (allow_nil? || negated))
      end
Severity: Major
Found in lib/dm-core/property.rb - About 40 mins to fix

    Similar blocks of code found in 3 locations. Consider refactoring.

        if index >= 0 && lazy_possible?(@head, index + length)
          @head.slice!(*args)
        elsif index < 0 && lazy_possible?(@tail, index.abs - 1 + length)
          @tail.slice!(*args)
        else
    Severity: Minor
    Found in lib/dm-core/support/lazy_array.rb and 2 other locations - About 40 mins to fix
    lib/dm-core/support/lazy_array.rb on lines 107..114
    lib/dm-core/support/lazy_array.rb on lines 135..142

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

    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 3 locations. Consider refactoring.

        if index >= 0 && lazy_possible?(@head, index + length)
          @head.[]=(*args)
        elsif index < 0 && lazy_possible?(@tail, index.abs - 1 + length)
          @tail.[]=(*args)
        else
    Severity: Minor
    Found in lib/dm-core/support/lazy_array.rb and 2 other locations - About 40 mins to fix
    lib/dm-core/support/lazy_array.rb on lines 107..114
    lib/dm-core/support/lazy_array.rb on lines 122..129

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

    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 3 locations. Consider refactoring.

        if index >= 0 && lazy_possible?(@head, index + length)
          @head[*args]
        elsif index < 0 && lazy_possible?(@tail, index.abs - 1 + length)
          @tail[*args]
        else
    Severity: Minor
    Found in lib/dm-core/support/lazy_array.rb and 2 other locations - About 40 mins to fix
    lib/dm-core/support/lazy_array.rb on lines 122..129
    lib/dm-core/support/lazy_array.rb on lines 135..142

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

    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 install_hook has 5 arguments (exceeds 4 allowed). Consider refactoring.

          def install_hook(type, target_method, method_sym, scope, &block)
    Severity: Minor
    Found in lib/dm-core/support/hook.rb - About 35 mins to fix

      Method pluralize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

          def pluralize(word)
            result = word.to_s.dup
      
            if word.empty? || inflections.uncountables.include?(result.downcase)
              result
      Severity: Minor
      Found in lib/dm-core/support/inflector/inflections.rb - About 35 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 update! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

          def update!(attributes)
            assert_update_clean_only(:update!)
      
            model = self.model
      
      
      Severity: Minor
      Found in lib/dm-core/collection.rb - About 35 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 assert_valid_links has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

          def assert_valid_links(links)
            if links.empty?
              raise ArgumentError, '+options[:links]+ should not be empty'
            end
      
      
      Severity: Minor
      Found in lib/dm-core/query.rb - About 35 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 valid_target_collection? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

            def valid_target_collection?(collection, negated)
              if collection.kind_of?(Collection)
                # TODO: move the check for model_key into Collection#reloadable?
                # since what we're really checking is a Collection's ability
                # to reload itself, which is (currently) only possible if the
      Severity: Minor
      Found in lib/dm-core/associations/relationship.rb - About 35 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 7 (exceeds 5 allowed). Consider refactoring.

          def initialize(model, name, options = {})
            options = options.to_hash.dup
      
            if INVALID_NAMES.include?(name.to_s) || (kind_of?(Boolean) && INVALID_NAMES.include?("#{name}?"))
              raise ArgumentError,
      Severity: Minor
      Found in lib/dm-core/property.rb - About 35 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 valid? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

          def valid?(value, negated = false)
            dumped_value = dump(value)
      
            if required? && dumped_value.nil?
              negated || false
      Severity: Minor
      Found in lib/dm-core/property.rb - About 35 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 merge_conditions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

          def merge_conditions(conditions)
            @conditions = Conditions::Operation.new(:and) << @conditions unless @conditions.nil?
      
            conditions.compact!
            conditions.each do |condition|
      Severity: Minor
      Found in lib/dm-core/query.rb - About 35 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 conditions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

          def conditions
            key = self.key
            if key
              model.key_conditions(repository, key)
            else
      Severity: Minor
      Found in lib/dm-core/resource.rb - About 35 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 constantize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

            def constantize(camel_cased_word) #:nodoc:
              names = camel_cased_word.split('::')
              names.shift if names.empty? || names.first.empty?
      
              constant = Object
      Severity: Minor
      Found in lib/dm-core/support/inflector/methods.rb - About 35 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 normalize_order has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

          def normalize_order
            return if @order.nil?
      
            @order = Array(@order).map do |order|
              case order
      Severity: Minor
      Found in lib/dm-core/query.rb - About 35 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 constantize has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

            def constantize(camel_cased_word)
              names = camel_cased_word.split('::')
              names.shift if names.empty? || names.first.empty?
      
              constant = Object
      Severity: Minor
      Found in lib/dm-core/support/inflector/methods.rb - About 35 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_log has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.

          def initialize_log(log)
            close if @log # be sure that we don't leave open files laying around.
      
            if log.respond_to?(:write)
              @log = log
      Severity: Minor
      Found in lib/dm-core/support/logger.rb - About 35 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 7 (exceeds 5 allowed). Consider refactoring.

            def initialize(model, name, options = {})
              super
      
              [ :scale, :precision ].each do |key|
                unless @options.key?(key)
      Severity: Minor
      Found in lib/dm-core/property/decimal.rb - About 35 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

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

            def child_model
              return @child_model if defined?(@child_model)
              child_model_name = self.child_model_name
              @child_model = DataMapper::Ext::Module.find_const(@parent_model || Object, child_model_name)
            rescue NameError
      Severity: Minor
      Found in lib/dm-core/associations/relationship.rb and 1 other location - About 35 mins to fix
      lib/dm-core/associations/relationship.rb on lines 221..226

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

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

          def save_self(execute_hooks = true)
            # short-circuit if the resource is not dirty
            return saved? unless dirty_self?
      
            if execute_hooks
      Severity: Minor
      Found in lib/dm-core/resource.rb - About 35 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

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

            def parent_model
              return @parent_model if defined?(@parent_model)
              parent_model_name = self.parent_model_name
              @parent_model = DataMapper::Ext::Module.find_const(@child_model || Object, parent_model_name)
            rescue NameError
      Severity: Minor
      Found in lib/dm-core/associations/relationship.rb and 1 other location - About 35 mins to fix
      lib/dm-core/associations/relationship.rb on lines 168..173

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

      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.

        def delete_at(index)
          if index >= 0 && lazy_possible?(@head, index + 1)
            @head.delete_at(index)
          elsif index < 0 && lazy_possible?(@tail, index.abs)
            @tail.delete_at(index)
      Severity: Minor
      Found in lib/dm-core/support/lazy_array.rb and 1 other location - About 30 mins to fix
      lib/dm-core/support/lazy_array.rb on lines 24..32

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

      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.

        def at(index)
          if index >= 0 && lazy_possible?(@head, index + 1)
            @head.at(index)
          elsif index < 0 && lazy_possible?(@tail, index.abs)
            @tail.at(index)
      Severity: Minor
      Found in lib/dm-core/support/lazy_array.rb and 1 other location - About 30 mins to fix
      lib/dm-core/support/lazy_array.rb on lines 239..247

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

      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 3 locations. Consider refactoring.

            def child_key
              return @child_key if defined?(@child_key)
      
              repository_name = child_repository_name || parent_repository_name
              properties      = child_model.properties(repository_name)
      Severity: Minor
      Found in lib/dm-core/associations/relationship.rb and 2 other locations - About 25 mins to fix
      lib/dm-core/associations/many_to_many.rb on lines 15..25
      lib/dm-core/associations/relationship.rb on lines 248..258

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

      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 3 locations. Consider refactoring.

            def parent_key
              return @parent_key if defined?(@parent_key)
      
              repository_name = parent_repository_name || child_repository_name
              properties      = parent_model.properties(repository_name)
      Severity: Minor
      Found in lib/dm-core/associations/relationship.rb and 2 other locations - About 25 mins to fix
      lib/dm-core/associations/many_to_many.rb on lines 15..25
      lib/dm-core/associations/relationship.rb on lines 195..205

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

      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 3 locations. Consider refactoring.

              def child_key
                return @child_key if defined?(@child_key)
      
                repository_name = child_repository_name || parent_repository_name
                properties      = child_model.properties(repository_name)
      Severity: Minor
      Found in lib/dm-core/associations/many_to_many.rb and 2 other locations - About 25 mins to fix
      lib/dm-core/associations/relationship.rb on lines 195..205
      lib/dm-core/associations/relationship.rb on lines 248..258

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

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

          def assert_valid_fields(fields, unique)
            valid_properties = model.properties
      
            model.descendants.each do |descendant|
              valid_properties += descendant.properties
      Severity: Minor
      Found in lib/dm-core/query.rb - About 25 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 assert_valid_order has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

          def assert_valid_order(order, fields)
            Array(order).each do |order_entry|
              case order_entry
                when Symbol, String
                  unless @properties.named?(order_entry)
      Severity: Minor
      Found in lib/dm-core/query.rb - About 25 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 normalize_links has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

          def normalize_links
            stack = @links.dup
      
            @links.clear
      
      
      Severity: Minor
      Found in lib/dm-core/query.rb - About 25 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 typecast_to_primitive has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

            def typecast_to_primitive(value)
              if value.respond_to?(:to_date)
                value.to_date
              elsif value.is_a?(::Hash) || value.respond_to?(:to_mash)
                typecast_hash_to_date(value)
      Severity: Minor
      Found in lib/dm-core/property/date.rb - About 25 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 at has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

          def at(offset)
            if loaded? || partially_loaded?(offset)
              super
            elsif offset == 0
              first
      Severity: Minor
      Found in lib/dm-core/collection.rb - About 25 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 define_hook_stack_execution_methods has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

            def define_hook_stack_execution_methods(target_method, scope)
              unless registered_as_hook?(target_method, scope)
                raise ArgumentError, "#{target_method} has not be registered as a hookable #{scope} method"
              end
      
      
      Severity: Minor
      Found in lib/dm-core/support/hook.rb - About 25 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 setup_hook has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

              def setup_hook(type, name, method, proc)
                types = hooks[name]
                if types && types[type]
                  types[type] << if proc
                    ProcCommand.new(proc)
      Severity: Minor
      Found in lib/dm-core/model/hook.rb - About 25 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 full_const_set has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

          def self.full_const_set(obj, name, value = nil)
            obj, name, value = ::Object, obj, name if value.nil?
      
            list = name.split("::")
            toplevel = DataMapper::Ext.blank?(list.first)
      Severity: Minor
      Found in lib/dm-core/support/ext/object.rb - About 25 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 typecast_to_numeric has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

              def typecast_to_numeric(value, method)
                if value.respond_to?(:to_str)
                  if value.to_str =~ /\A(-?(?:0|[1-9]\d*)(?:\.\d+)?|(?:\.\d+))\z/
                    $1.send(method)
                  else
      Severity: Minor
      Found in lib/dm-core/property/typecast/numeric.rb - About 25 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 dump has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

              def dump(value)
                value.dup.force_encoding("BINARY") unless value.nil?
              rescue
                value
              end
      Severity: Minor
      Found in lib/dm-core/property/binary.rb - About 25 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 load_adapter has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

            def load_adapter(name)
              require "dm-#{name}-adapter"
            rescue LoadError => original_error
              begin
                require in_memory_adapter?(name) ? in_memory_adapter_path : legacy_path(name)
      Severity: Minor
      Found in lib/dm-core/adapters.rb - About 25 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 values_at has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

        def values_at(*args)
          accumulator = []
      
          lazy_possible = args.all? do |arg|
            index, length = extract_slice_arguments(arg)
      Severity: Minor
      Found in lib/dm-core/support/lazy_array.rb - About 25 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 update has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

          def update(other)
            other_options = if kind_of?(other.class)
              return self if self.eql?(other)
              assert_valid_other(other)
              other.options
      Severity: Minor
      Found in lib/dm-core/query.rb - About 25 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 singularize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

          def singularize(word)
            result = word.to_s.dup
      
            if inflections.uncountables.any? { |inflection| result =~ /\b(#{inflection})\Z/i }
              result
      Severity: Minor
      Found in lib/dm-core/support/inflector/inflections.rb - About 25 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 <=> has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

            def <=>(other)
              other_value = other.value
              value_nil   = @value.nil?
              other_nil   = other_value.nil?
      
      
      Severity: Minor
      Found in lib/dm-core/query/sort.rb - About 25 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 append_property_condition has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

          def append_property_condition(subject, bind_value, operator)
            negated = operator == :not
      
            if operator == :eql || negated
              # transform :relationship => nil into :relationship.not => association
      Severity: Minor
      Found in lib/dm-core/query.rb - About 25 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 typecast_to_primitive has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

            def typecast_to_primitive(value)
              if value.respond_to?(:to_time)
                value.to_time
              elsif value.is_a?(::Hash) || value.respond_to?(:to_mash)
                typecast_hash_to_time(value)
      Severity: Minor
      Found in lib/dm-core/property/time.rb - About 25 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 condition_properties has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.

          def condition_properties
            properties = Set.new
      
            each_comparison do |comparison|
              next unless comparison.respond_to?(:subject)
      Severity: Minor
      Found in lib/dm-core/query.rb - About 25 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