Method allocate_ip_by_type
has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring. Open
def allocate_ip_by_type(bc_instance, network, range, object, type, suggestion = nil)
Rails.logger.debug("Network allocate ip for #{type}: entering #{object} #{network} #{range}")
return [404, "No network specified"] if network.nil?
return [404, "No range specified"] if range.nil?
return [404, "No object specified"] if object.nil?
- 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 transition
has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring. Open
def transition(inst, name, state)
Rails.logger.debug("Network transition: entering: #{name} for #{state}")
# we need one state before "installed" (and after allocation) because we
# need the node to have the admin network fully defined for
- 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 deallocate_ip_by_type
has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring. Open
def deallocate_ip_by_type(bc_instance, network, object, type)
Rails.logger.debug("Network deallocate ip from #{type}: entering #{object} #{network}")
return [404, "No network specified"] if network.nil?
return [404, "No type specified"] if type.nil?
- 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 network_service.rb
has 354 lines of code (exceeds 250 allowed). Consider refactoring. Open
class NetworkService < ServiceObject
def initialize(thelogger = nil)
super
@bc_name = "network"
end
- Create a ticketCreate a ticket
Method allocate_ip_by_type
has 94 lines of code (exceeds 25 allowed). Consider refactoring. Open
def allocate_ip_by_type(bc_instance, network, range, object, type, suggestion = nil)
Rails.logger.debug("Network allocate ip for #{type}: entering #{object} #{network} #{range}")
return [404, "No network specified"] if network.nil?
return [404, "No range specified"] if range.nil?
return [404, "No object specified"] if object.nil?
- Create a ticketCreate a ticket
Method deallocate_ip_by_type
has 76 lines of code (exceeds 25 allowed). Consider refactoring. Open
def deallocate_ip_by_type(bc_instance, network, object, type)
Rails.logger.debug("Network deallocate ip from #{type}: entering #{object} #{network}")
return [404, "No network specified"] if network.nil?
return [404, "No type specified"] if type.nil?
- Create a ticketCreate a ticket
Method transition
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
def transition(inst, name, state)
Rails.logger.debug("Network transition: entering: #{name} for #{state}")
# we need one state before "installed" (and after allocation) because we
# need the node to have the admin network fully defined for
- Create a ticketCreate a ticket
Method enable_interface
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def enable_interface(bc_instance, network, name)
Rails.logger.debug("Network enable_interface: entering #{name} #{network}")
return [404, "No network specified"] if network.nil?
return [404, "No name specified"] if name.nil?
- 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 allocate_ip_by_type
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def allocate_ip_by_type(bc_instance, network, range, object, type, suggestion = nil)
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if result[0] != 200
Rails.logger.error(
"Failed to allocate bastion address for: #{node.name}: #{result[0]}"
)
else
- Create a ticketCreate a ticket
Avoid deeply nested control flow statements. Open
if result[0] != 200
Rails.logger.error("Failed to allocate bmc_vlan address for: " \
"#{node.name}: #{result[0]}")
end
- Create a ticketCreate a ticket
Method allocate_virtual_ip
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def allocate_virtual_ip(bc_instance, network, range, service, suggestion = nil)
- Create a ticketCreate a ticket
Method allocate_ip
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def allocate_ip(bc_instance, network, range, name, suggestion = nil)
- Create a ticketCreate a ticket
Method apply_role_pre_chef_call
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def apply_role_pre_chef_call(old_role, role, all_nodes)
Rails.logger.debug("Network apply_role_pre_chef_call: entering #{all_nodes.inspect}")
role.default_attributes["network"]["networks"].each do |k,net|
db = Chef::DataBag.load("crowbar/#{k}_network") rescue nil
- 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
Avoid too many return
statements within this method. Open
return [404, "No node found"] if node.nil?
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return [404, "No network data found"]
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return [200, net_info]
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return [404, "No Address Available"]
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return [404, "No network data found"]
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return [404, "Node does not have address in #{network}"]
- Create a ticketCreate a ticket
Avoid too many return
statements within this method. Open
return [404, "Network deallocate ip from #{type}: network does not exists: #{object} #{network}"]
- Create a ticketCreate a ticket
Similar blocks of code found in 2 locations. Consider refactoring. Open
if role.nil? || !role.default_attributes["network"]["networks"].key?(network)
Rails.logger.error("Network allocate ip by type: No network data found: #{name} #{network}")
return [404, "No network data found"]
end
- 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 27.
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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if role.nil? || !role.default_attributes["network"]["networks"].key?(network)
Rails.logger.error("Network enable_interface: No network data found: #{name} #{network}")
return [404, "No network data found"]
end
- 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 27.
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