deseretbook/classy_hash

View on GitHub

Showing 35 of 35 total issues

Method validate has a Cognitive Complexity of 167 (exceeds 5 allowed). Consider refactoring.
Open

  def self.validate(value, constraint, strict: false, full: false, verbose: false,
                    raise_errors: true, errors: nil, parent_path: nil, key: NO_VALUE)
    errors = [] if errors.nil? && (full || !raise_errors)
    raise_below = raise_errors && !full

Severity: Minor
Found in lib/classy_hash.rb - About 3 days 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 validate has 160 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.validate(value, constraint, strict: false, full: false, verbose: false,
                    raise_errors: true, errors: nil, parent_path: nil, key: NO_VALUE)
    errors = [] if errors.nil? && (full || !raise_errors)
    raise_below = raise_errors && !full

Severity: Major
Found in lib/classy_hash.rb - About 6 hrs to fix

    Method do_test has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
    Open

    def do_test(hashes, expect_fail)
      results = []
    
      ser_enabled = (ENV['SERIALIZERS'] || '').split(/[, ]+/)
      val_enabled = (ENV['VALIDATORS'] || '').split(/[, ]+/)
    Severity: Minor
    Found in benchmark.rb - About 5 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 benchmark.rb has 359 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require 'benchmark'
    require 'msgpack'
    require 'json'
    require 'json-schema'
    require 'schema_hash'
    Severity: Minor
    Found in benchmark.rb - About 4 hrs to fix

      Method check_multi has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.check_multi(value, constraints, strict: nil, full: nil, verbose: nil, raise_errors: nil,
                             parent_path: nil, key: nil, errors: nil)
          if constraints.length == 0 || constraints.length == 1 && constraints.first == :optional
            return add_error(raise_errors, errors,
              parent_path,
      Severity: Minor
      Found in lib/classy_hash.rb - About 4 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 classy_hash.rb has 312 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      require 'set'
      require 'securerandom'
      
      # This module contains the ClassyHash methods for making sure Ruby Hash objects
      # match a given schema.  ClassyHash runs fast by taking advantage of Ruby
      Severity: Minor
      Found in lib/classy_hash.rb - About 3 hrs to fix

        Method constraint_string has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.constraint_string(constraint, value)
            case constraint
            when Hash
              "a Hash matching {schema with keys #{constraint.keys.inspect}}"
        
        
        Severity: Minor
        Found in lib/classy_hash.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 check_multi has 53 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.check_multi(value, constraints, strict: nil, full: nil, verbose: nil, raise_errors: nil,
                               parent_path: nil, key: nil, errors: nil)
            if constraints.length == 0 || constraints.length == 1 && constraints.first == :optional
              return add_error(raise_errors, errors,
                parent_path,
        Severity: Major
        Found in lib/classy_hash.rb - About 2 hrs to fix

          Method length has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def self.length(length)
                raise "length must be an Integer or a Range" unless length.is_a?(Integer) || length.is_a?(Range)
          
                if length.is_a?(Range) && !(length.min.is_a?(Integer) && length.max.is_a?(Integer))
                  raise "Range length endpoints must be Integers"
          Severity: Minor
          Found in lib/classy_hash/generate.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 constraint_string has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.constraint_string(constraint, value)
              case constraint
              when Hash
                "a Hash matching {schema with keys #{constraint.keys.inspect}}"
          
          
          Severity: Minor
          Found in lib/classy_hash.rb - About 1 hr to fix

            Method do_test has 42 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

            def do_test(hashes, expect_fail)
              results = []
            
              ser_enabled = (ENV['SERIALIZERS'] || '').split(/[, ]+/)
              val_enabled = (ENV['VALIDATORS'] || '').split(/[, ]+/)
            Severity: Minor
            Found in benchmark.rb - About 1 hr to fix

              Method array_length has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  def self.array_length(length, *constraints)
                    raise 'one or more constraints must be provided' if constraints.empty?
              
                    length_lambda = self.length(length)
                    msg = "an Array of length #{length}"
              Severity: Minor
              Found in lib/classy_hash/generate.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

              Avoid deeply nested control flow statements.
              Open

                          return false unless full
              Severity: Major
              Found in lib/classy_hash.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                            return false unless full
                Severity: Major
                Found in lib/classy_hash.rb - About 45 mins to fix

                  Method add_error has 6 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                    def self.add_error(raise_errors, errors, parent_path, key, constraint, value)
                  Severity: Minor
                  Found in lib/classy_hash.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                if verbose
                                  msg = "valid: contains members #{extra_keys.map(&:inspect).join(', ')} not specified in schema"
                                else
                                  msg = 'valid: contains members not specified in schema'
                                end
                    Severity: Major
                    Found in lib/classy_hash.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                return false unless full
                      Severity: Major
                      Found in lib/classy_hash.rb - About 45 mins to fix

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

                          def self.add_error(raise_errors, errors, parent_path, key, constraint, value)
                            message = constraint.is_a?(String) ? constraint : constraint_string(constraint, value)
                            entry = { full_path: self.join_path(parent_path, key) || 'Top level', message: message }
                        
                            if raise_errors
                        Severity: Minor
                        Found in lib/classy_hash.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

                        Avoid deeply nested control flow statements.
                        Open

                                unless value.is_a?(String)
                                  add_error(raise_below, errors, parent_path, key, constraint, value)
                                  return false unless full
                                  range_type_valid = false
                                end
                        Severity: Major
                        Found in lib/classy_hash.rb - About 45 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                return false unless full
                          Severity: Major
                          Found in lib/classy_hash.rb - About 30 mins to fix
                            Severity
                            Category
                            Status
                            Source
                            Language