dry-rb/dry-types

View on GitHub

Showing 32 of 32 total issues

Class Schema has 24 methods (exceeds 20 allowed). Consider refactoring.
Open

    class Schema < Hash
      NO_TRANSFORM = Dry::Types::FnContainer.register { |x| x }
      SYMBOLIZE_KEY = Dry::Types::FnContainer.register(:to_sym.to_proc)

      include ::Enumerable
Severity: Minor
Found in lib/dry/types/schema.rb - About 2 hrs to fix

    Class Compiler has 21 methods (exceeds 20 allowed). Consider refactoring.
    Open

        class Compiler
          extend ::Dry::Core::Deprecations[:"dry-types"]
    
          attr_reader :registry
    
    
    Severity: Minor
    Found in lib/dry/types/compiler.rb - About 2 hrs to fix

      Method try has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

            def try(input)
              if primitive?(input)
                success = true
                output = {}
                result = {}
      Severity: Minor
      Found in lib/dry/types/schema.rb - About 2 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

      Method try has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
      Open

              def try(input, &block) # rubocop:disable Metrics/PerceivedComplexity
                if primitive?(input)
                  output = []
      
                  result = input.map { |el| member.try(el) }
      Severity: Minor
      Found in lib/dry/types/array/member.rb - About 2 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

      Method infer_predicate has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

              def infer_predicate(type) # rubocop:disable Metrics/PerceivedComplexity
                pred = TYPE_TO_PREDICATE.fetch(type) do
                  if type.name.nil? || self.class.infer_predicate_by_class_name.equal?(false)
                    nil
                  else
      Severity: Minor
      Found in lib/dry/types/predicate_inferrer.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 try has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

            def try(input)
              if primitive?(input)
                success = true
                output = {}
                result = {}
      Severity: Minor
      Found in lib/dry/types/schema.rb - About 1 hr to fix

        Method type_constants has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

              def type_constants(*namespaces, default: Undefined, **aliases)
                if namespaces.empty? && aliases.empty? && Undefined.equal?(default)
                  default_ns = :Strict
                elsif Undefined.equal?(default)
                  default_ns = Undefined
        Severity: Minor
        Found in lib/dry/types/module.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 resolve_missing_keys has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

              def resolve_missing_keys(hash, options) # rubocop:disable Metrics/PerceivedComplexity
                skip_missing = options.fetch(:skip_missing, false)
                resolve_defaults = options.fetch(:resolve_defaults, true)
        
                keys.each do |key|
        Severity: Minor
        Found in lib/dry/types/schema.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 infer_predicate has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def infer_predicate(type) # rubocop:disable Metrics/PerceivedComplexity
                  pred = TYPE_TO_PREDICATE.fetch(type) do
                    if type.name.nil? || self.class.infer_predicate_by_class_name.equal?(false)
                      nil
                    else
        Severity: Minor
        Found in lib/dry/types/predicate_inferrer.rb - About 1 hr to fix

          Method fallback has 29 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

                def fallback(value = Undefined, shared: false, &_fallback) # rubocop:disable Metrics/PerceivedComplexity
                  if Undefined.equal?(value) && !block_given?
                    raise ::ArgumentError, "fallback value or a block must be given"
                  end
          
          
          Severity: Minor
          Found in lib/dry/types/builder.rb - About 1 hr to fix

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

                  def fallback(value = Undefined, shared: false, &_fallback) # rubocop:disable Metrics/PerceivedComplexity
                    if Undefined.equal?(value) && !block_given?
                      raise ::ArgumentError, "fallback value or a block must be given"
                    end
            
            
            Severity: Minor
            Found in lib/dry/types/builder.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 [] has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                def self.[](name)
                  type_map.fetch_or_store(name) do
                    case name
                    when ::String
                      result = name.match(TYPE_SPEC_REGEX)
            Severity: Minor
            Found in lib/dry/types.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 try has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
            Open

                    def try(input, &block)
                      result = type.try(input)
            
                      if result.success?
                        validation = rule.(result.input)
            Severity: Minor
            Found in lib/dry/types/constrained/coercible.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 call_safe has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                    def call_safe(input)
                      if primitive?(input)
                        failed = false
            
                        result = input.each_with_object([]) do |el, output|
            Severity: Minor
            Found in lib/dry/types/array/member.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 coerce has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                  def coerce(input)
                    unless primitive?(input)
                      return failure(
                        input, CoercionError.new("#{input.inspect} must be an instance of #{primitive}")
                      )
            Severity: Minor
            Found in lib/dry/types/map.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_ast has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                    def to_ast(meta: true)
                      if member.respond_to?(:to_ast)
                        [:array, [member.to_ast(meta: meta), meta ? self.meta : EMPTY_HASH]]
                      else
                        [:array, [member, meta ? self.meta : EMPTY_HASH]]
            Severity: Minor
            Found in lib/dry/types/array/member.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 define_constants has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
            Open

                  def define_constants(constants, mod = self)
                    constants.each do |name, value|
                      case value
                      when ::Hash
                        if mod.const_defined?(name, false)
            Severity: Minor
            Found in lib/dry/types/module.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 a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                    def self.[](fn)
                      raise ::ArgumentError, "Missing constructor block" if fn.nil?
            
                      if fn.is_a?(Function)
                        fn
            Severity: Minor
            Found in lib/dry/types/constructor/function.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 check_parameters has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                  def check_parameters(*namespaces, default: Undefined, **aliases)
                    referenced = namespaces.dup
                    referenced << default unless false.equal?(default) || Undefined.equal?(default)
                    referenced.concat(aliases.keys)
            
            
            Severity: Minor
            Found in lib/dry/types/module.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.
            Open

                  def to_date_time(input, &block)
                    if input.respond_to?(:to_str)
                      begin
                        ::DateTime.parse(input)
                      rescue ArgumentError => e
            Severity: Minor
            Found in lib/dry/types/coercions.rb and 1 other location - About 35 mins to fix
            lib/dry/types/coercions.rb on lines 64..77

            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

            Severity
            Category
            Status
            Source
            Language