app/models/runtime/constraints/ports_policy.rb
Method verify_ports
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
def verify_ports
@process.route_mappings.each do |mapping|
if mapping.app_port.blank?
return false unless @process.ports.include?(VCAP::CloudController::ProcessModel::DEFAULT_HTTP_PORT)
elsif mapping.has_app_port_specified? && @process.ports.exclude?(mapping.app_port)
- 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 a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
Open
def validate
return if @process.ports.nil? || @process.ports.empty?
return @errors.add('Process', 'must have at most 10 exposed ports.') if ports_limit_exceeded?
return @errors.add('Ports', 'must be integers.') unless all_ports_are_integers?
return @errors.add('Ports', 'must be in the 1024-65535 range.') unless all_ports_are_in_range?
- 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 too many return
statements within this method. Open
Open
return if verify_ports