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
- Read upRead up
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
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,
- Read upRead up
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
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}}"
- Read upRead up
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,
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}}"
Avoid deeply nested control flow statements. Open
return false unless full
Avoid deeply nested control flow statements. Open
return false unless full
Method add_error
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def self.add_error(raise_errors, errors, parent_path, key, constraint, value)
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
Avoid deeply nested control flow statements. Open
return false unless full
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
- Read upRead up
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
Avoid too many return
statements within this method. Open
return false unless full
Avoid too many return
statements within this method. Open
return false unless full
Avoid too many return
statements within this method. Open
return false unless full
Avoid too many return
statements within this method. Open
return false unless full
Avoid too many return
statements within this method. Open
return false unless full
Avoid too many return
statements within this method. Open
return false unless res || full
Avoid too many return
statements within this method. Open
return false unless res || full
Avoid too many return
statements within this method. Open
return false unless full
Avoid too many return
statements within this method. Open
return false unless res || full
Avoid too many return
statements within this method. Open
return false unless full
Avoid too many return
statements within this method. Open
return false unless full
Avoid too many return
statements within this method. Open
return false unless full
Avoid too many return
statements within this method. Open
return false unless full
Avoid too many return
statements within this method. Open
return false unless full