deseretbook/classy_hash

View on GitHub
lib/classy_hash.rb

Summary

Maintainability
F
1 wk
Test Coverage

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

          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

                        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

                          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

                            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

                              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

                                Avoid too many return statements within this method.
                                Open

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

                                  Avoid too many return statements within this method.
                                  Open

                                          return false unless res || full
                                  Severity: Major
                                  Found in lib/classy_hash.rb - About 30 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

                                      Avoid too many return statements within this method.
                                      Open

                                                  return false unless res || full
                                      Severity: Major
                                      Found in lib/classy_hash.rb - About 30 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

                                          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

                                            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

                                              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

                                                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

                                                  There are no issues that match your filters.

                                                  Category
                                                  Status