datamapper/dm-core

View on GitHub
lib/dm-core/property.rb

Summary

Maintainability
D
1 day
Test Coverage

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

  class Property
    include DataMapper::Assertions
    include Subject
    extend Equalizer

Severity: Minor
Found in lib/dm-core/property.rb - About 5 hrs to fix

    Method assert_valid_options has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.

        def assert_valid_options(options)
          keys = options.keys
    
          if (unknown_keys = keys - self.class.accepted_options).any?
            raise ArgumentError, "options #{unknown_keys.map { |key| key.inspect }.join(' and ')} are unknown"
    Severity: Minor
    Found in lib/dm-core/property.rb - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    File property.rb has 269 lines of code (exceeds 250 allowed). Consider refactoring.

    module DataMapper
      # = Properties
      # Properties for a model are not derived from a database structure, but
      # instead explicitly declared inside your model class definitions. These
      # properties then map (or, if using automigrate, generate) fields in your
    Severity: Minor
    Found in lib/dm-core/property.rb - About 2 hrs to fix

      Method assert_valid_options has 35 lines of code (exceeds 25 allowed). Consider refactoring.

          def assert_valid_options(options)
            keys = options.keys
      
            if (unknown_keys = keys - self.class.accepted_options).any?
              raise ArgumentError, "options #{unknown_keys.map { |key| key.inspect }.join(' and ')} are unknown"
      Severity: Minor
      Found in lib/dm-core/property.rb - About 1 hr to fix

        Method initialize has 27 lines of code (exceeds 25 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 1 hr to fix

          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

            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

            There are no issues that match your filters.

            Category