Class has too many lines. [253/250] Open
class Params
DEFAULT_OPTS = { strict: true }.freeze
BASIC_TYPES = [String, Symbol, Float, Integer, Array, Hash].freeze
DEFAULT_TYPE_MATCHERS = {
- Read upRead up
- Exclude checks
This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Class Params
has 31 methods (exceeds 20 allowed). Consider refactoring. Open
class Params
DEFAULT_OPTS = { strict: true }.freeze
BASIC_TYPES = [String, Symbol, Float, Integer, Array, Hash].freeze
DEFAULT_TYPE_MATCHERS = {
File params.rb
has 259 lines of code (exceeds 250 allowed). Consider refactoring. Open
module Rester
class Service::Resource
class Params
DEFAULT_OPTS = { strict: true }.freeze
BASIC_TYPES = [String, Symbol, Float, Integer, Array, Hash].freeze
Cyclomatic complexity for _add_validator is too high. [7/6] Open
def _add_validator(name, klass, opts)
fail 'must specify param name' unless name
fail 'validation options must be a Hash' unless opts.is_a?(Hash)
default_opts = { match: DEFAULT_TYPE_MATCHERS[klass] }
opts = default_opts.merge(opts)
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Cyclomatic complexity for _parse_with_class is too high. [7/6] Open
def _parse_with_class(klass, value)
if klass == String
value
elsif klass == Integer
value.to_i
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Method _add_validator
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def _add_validator(name, klass, opts)
fail 'must specify param name' unless name
fail 'validation options must be a Hash' unless opts.is_a?(Hash)
default_opts = { match: DEFAULT_TYPE_MATCHERS[klass] }
opts = default_opts.merge(opts)
- 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 _parse_with_class
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def _parse_with_class(klass, value)
if klass == String
value
elsif klass == Integer
value.to_i
- 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_required
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def _validate_required(key, is_defined)
unless is_defined
_, key, index = /(\w+)(\[\d+\])?/.match(key).to_a
if required?(key)
- 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_obj
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def _validate_obj(key, obj, opts)
fail if obj.nil? # Assert, at this point should be guaranteed
opts.each do |opt, value|
case opt
- 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_str
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _validate_str(key, value, klass, opts)
fail unless value.is_a?(String) # assert
if [Array, Hash].include?(klass)
_error!("expected #{key} to be of type #{klass}")
end
- 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"