Method update_ovs_bridge_attributes
has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring. Open
def update_ovs_bridge_attributes(attributes, node)
needs_save = false
ovs_bridge_networks = []
ml2_mechanism_drivers = []
if attributes["networking_plugin"] == "ml2"
- Read upRead up
- Create a ticketCreate a ticket
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 neutron_service.rb
has 436 lines of code (exceeds 250 allowed). Consider refactoring. Open
require "ipaddr"
class NeutronService < OpenstackServiceObject
def initialize(thelogger = nil)
super(thelogger)
- Create a ticketCreate a ticket
Method validate_ml2
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def validate_ml2(proposal)
ml2_mechanism_drivers = proposal["attributes"]["neutron"]["ml2_mechanism_drivers"]
ml2_type_drivers = proposal["attributes"]["neutron"]["ml2_type_drivers"]
ml2_type_drivers_default_provider_network = proposal["attributes"]["neutron"]["ml2_type_drivers_default_provider_network"]
ml2_type_drivers_default_tenant_network = proposal["attributes"]["neutron"]["ml2_type_drivers_default_tenant_network"]
- Read upRead up
- Create a ticketCreate a ticket
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_ml2
has 71 lines of code (exceeds 25 allowed). Consider refactoring. Open
def validate_ml2(proposal)
ml2_mechanism_drivers = proposal["attributes"]["neutron"]["ml2_mechanism_drivers"]
ml2_type_drivers = proposal["attributes"]["neutron"]["ml2_type_drivers"]
ml2_type_drivers_default_provider_network = proposal["attributes"]["neutron"]["ml2_type_drivers_default_provider_network"]
ml2_type_drivers_default_tenant_network = proposal["attributes"]["neutron"]["ml2_type_drivers_default_tenant_network"]
- Create a ticketCreate a ticket
Class NeutronService
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class NeutronService < OpenstackServiceObject
def initialize(thelogger = nil)
super(thelogger)
@bc_name = "neutron"
end
- Create a ticketCreate a ticket
Method enable_neutron_networks
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def enable_neutron_networks(attributes, nodename, net_svc, needs_external = true)
if needs_external
net_svc.enable_interface "default", "nova_floating", nodename
attributes["additional_external_networks"].each do |extnet|
net_svc.enable_interface "default", extnet, nodename
- Read upRead up
- Create a ticketCreate a ticket
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 update_ovs_bridge_attributes
has 53 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update_ovs_bridge_attributes(attributes, node)
needs_save = false
ovs_bridge_networks = []
ml2_mechanism_drivers = []
if attributes["networking_plugin"] == "ml2"
- Create a ticketCreate a ticket
Method validate_cisco_aci
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def validate_cisco_aci(proposal)
# Checks for Cisco ACI ml2 driver
ml2_mechanism_drivers = proposal["attributes"]["neutron"]["ml2_mechanism_drivers"]
ml2_type_drivers = proposal["attributes"]["neutron"]["ml2_type_drivers"]
- Read upRead up
- Create a ticketCreate a ticket
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 enable_neutron_networks
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def enable_neutron_networks(attributes, nodename, net_svc, needs_external = true)
if needs_external
net_svc.enable_interface "default", "nova_floating", nodename
attributes["additional_external_networks"].each do |extnet|
net_svc.enable_interface "default", extnet, nodename
- Create a ticketCreate a ticket
Method validate_vxlan
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def validate_vxlan(vxlan_settings)
if vxlan_settings["vni_start"] < 0 || vxlan_settings["vni_start"] > 16777215
validation_error I18n.t("barclamp.#{@bc_name}.validation.vxlan_vni_start")
end
if vxlan_settings["vni_end"] < 0 || vxlan_settings["vni_end"] > 16777215
- Read upRead up
- Create a ticketCreate a ticket
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 role_constraints
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def role_constraints
{
"neutron-server" => {
"unique" => false,
"count" => 1,
- Create a ticketCreate a ticket
Method validate_vxlan
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def validate_vxlan(vxlan_settings)
if vxlan_settings["vni_start"] < 0 || vxlan_settings["vni_start"] > 16777215
validation_error I18n.t("barclamp.#{@bc_name}.validation.vxlan_vni_start")
end
if vxlan_settings["vni_end"] < 0 || vxlan_settings["vni_end"] > 16777215
- Create a ticketCreate a ticket
Method validate_cisco_aci
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def validate_cisco_aci(proposal)
# Checks for Cisco ACI ml2 driver
ml2_mechanism_drivers = proposal["attributes"]["neutron"]["ml2_mechanism_drivers"]
ml2_type_drivers = proposal["attributes"]["neutron"]["ml2_type_drivers"]
- Create a ticketCreate a ticket
Method apply_role_pre_chef_call
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def apply_role_pre_chef_call(old_role, role, all_nodes)
@logger.debug("Neutron apply_role_pre_chef_call: entering #{all_nodes.inspect}")
return if all_nodes.empty?
net_svc = NetworkService.new @logger
- Create a ticketCreate a ticket
Method validate_dvr
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def validate_dvr(proposal)
plugin = proposal["attributes"]["neutron"]["networking_plugin"]
ml2_mechanism_drivers = proposal["attributes"]["neutron"]["ml2_mechanism_drivers"]
ml2_type_drivers = proposal["attributes"]["neutron"]["ml2_type_drivers"]
- Read upRead up
- Create a ticketCreate a ticket
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_proposal_after_save
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def validate_proposal_after_save(proposal)
validate_one_for_role proposal, "neutron-server"
validate_at_least_n_for_role proposal, "neutron-network", 1
plugin = proposal["attributes"]["neutron"]["networking_plugin"]
- Read upRead up
- Create a ticketCreate a ticket
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 save_proposal!
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def save_proposal!(prop, options = {})
# Fill in missing defaults for infoblox grid configurations
if prop.raw_data[:attributes][:neutron][:use_infoblox]
prop.raw_data[:attributes][:neutron][:infoblox][:grids].each do |grid|
defaults = prop.raw_data["attributes"]["neutron"]["infoblox"]["grid_defaults"]
- Read upRead up
- Create a ticketCreate a ticket
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 apply_role_pre_chef_call
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def apply_role_pre_chef_call(old_role, role, all_nodes)
@logger.debug("Neutron apply_role_pre_chef_call: entering #{all_nodes.inspect}")
return if all_nodes.empty?
net_svc = NetworkService.new @logger
- Read upRead up
- Create a ticketCreate a ticket
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 create_proposal
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def create_proposal
base = super
nodes = NodeObject.all
nodes.delete_if { |n| n.nil? or n.admin? }
- Read upRead up
- Create a ticketCreate a ticket
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_gre
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def validate_gre(gre_settings)
if gre_settings["tunnel_id_start"] < 1 || gre_settings["tunnel_id_start"] > 2147483647
validation_error I18n.t("barclamp.#{@bc_name}.validation.start_id")
end
if gre_settings["tunnel_id_end"] < 1 || gre_settings["tunnel_id_end"] > 2147483647
- Read upRead up
- Create a ticketCreate a ticket
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
Similar blocks of code found in 4 locations. Consider refactoring. Open
def proposal_dependencies(role)
answer = []
answer << { "barclamp" => "database", "inst" => role.default_attributes["neutron"]["database_instance"] }
answer << { "barclamp" => "rabbitmq", "inst" => role.default_attributes["neutron"]["rabbitmq_instance"] }
answer << { "barclamp" => "keystone", "inst" => role.default_attributes["neutron"]["keystone_instance"] }
- Read upRead up
- Create a ticketCreate a ticket
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 41.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76