Method validate
has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring. Open
def validate(record)
unless record.rules.is_a?(Array)
record.errors.add :rules, 'must be an array'
return
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"
Further reading
Method validate_destination
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def validate_destination(destination, record, index)
error_message = 'destination must be a valid CIDR, IP address, or IP address range'
error_message = 'destination must contain valid CIDR(s), IP address(es), or IP address range(s)' if CloudController::RuleValidator.comma_delimited_destinations_enabled?
add_rule_error('empty destination specified in comma-delimited list', record, index) if destination.empty?
- 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 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def validate(record)
unless record.rules.is_a?(Array)
record.errors.add :rules, 'must be an array'
return
end
Method validate_icmp_protocol
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def validate_icmp_protocol(rule, record, index)
add_rule_error('code is required for protocols of type ICMP', record, index) unless rule[:code]
add_rule_error('code must be an integer between -1 and 255 (inclusive)', record, index) unless valid_icmp_format(rule[:code])
add_rule_error('type is required for protocols of type ICMP', record, index) unless rule[:type]
- 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 valid_destination_type
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def valid_destination_type(destination, record, index)
error_message = 'destination must be a valid CIDR, IP address, or IP address range'
if CloudController::RuleValidator.comma_delimited_destinations_enabled?
error_message = 'nil destination; destination must be a comma-delimited list of valid CIDRs, IP addresses, or IP address ranges'
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"