Method validate_proposal_after_save
has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring. Open
def validate_proposal_after_save(proposal)
validate_one_for_role proposal, "nova-controller"
elements = proposal["deployment"]["nova"]["elements"]
nodes = Hash.new(0)
- 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 nova_service.rb
has 441 lines of code (exceeds 250 allowed). Consider refactoring. Open
class NovaService < OpenstackServiceObject
def initialize(thelogger = nil)
super(thelogger)
@bc_name = "nova"
end
- Create a ticketCreate a ticket
Method apply_role_pre_chef_call
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
def apply_role_pre_chef_call(old_role, role, all_nodes)
@logger.debug("Nova apply_role_pre_chef_call: entering #{all_nodes.inspect}")
unless hyperv_available?
role.override_attributes["nova"]["elements"]["nova-compute-hyperv"] = []
- 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 99 lines of code (exceeds 25 allowed). Consider refactoring. Open
def validate_proposal_after_save(proposal)
validate_one_for_role proposal, "nova-controller"
elements = proposal["deployment"]["nova"]["elements"]
nodes = Hash.new(0)
- Create a ticketCreate a ticket
Method apply_role_pre_chef_call
has 88 lines of code (exceeds 25 allowed). Consider refactoring. Open
def apply_role_pre_chef_call(old_role, role, all_nodes)
@logger.debug("Nova apply_role_pre_chef_call: entering #{all_nodes.inspect}")
unless hyperv_available?
role.override_attributes["nova"]["elements"]["nova-compute-hyperv"] = []
- Create a ticketCreate a ticket
Method role_constraints
has 77 lines of code (exceeds 25 allowed). Consider refactoring. Open
def role_constraints
{
"nova-controller" => {
"unique" => false,
"count" => 1,
- Create a ticketCreate a ticket
Method create_proposal
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def create_proposal
@logger.debug("Nova create_proposal: entering")
base = super
@logger.debug("Nova create_proposal: done with base")
- 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 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_proposal
@logger.debug("Nova create_proposal: entering")
base = super
@logger.debug("Nova create_proposal: done with base")
- Create a ticketCreate a ticket
Method active_update
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def active_update(proposal, inst, in_queue, bootstrap = false)
deployment = proposal["deployment"]["nova"]
elements = deployment["elements"]
# always reset elements of nova-ha-compute in case the user tried to
- 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 skip_unchanged_node?
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def skip_unchanged_node?(node, old_role, new_role)
# if old_role is nil, then we are applying the barclamp for the first time, so no skip
return false if old_role.nil?
# if the node changed roles, then we need to apply, so no skip
- 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 node_is_remote_ha?
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def node_is_remote_ha?(node, new_role)
new_role.override_attributes[@bc_name]["elements"].each do |role_name, elements|
next unless role_name =~ /^nova-compute-/
elements.each do |element|
if is_remotes?(element)
- 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 false if node_changed_ha?(node, old_role, new_role)
- Create a ticketCreate a ticket
Similar blocks of code found in 2 locations. Consider refactoring. Open
unless network_present? proposal["attributes"][@bc_name]["migration"]["network"]
validation_error I18n.t(
"barclamp.#{@bc_name}.validation.invalid_migration_network",
network: proposal["attributes"][@bc_name]["migration"]["network"]
)
- 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 29.
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
unless network_present? proposal["attributes"][@bc_name]["zvm"]["zvm_xcat_network"]
validation_error I18n.t(
"barclamp.#{@bc_name}.validation.invalid_zvm_xcat_network",
network: proposal["attributes"][@bc_name]["zvm"]["zvm_xcat_network"]
)
- 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 29.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
def network_present?(network_name)
net_svc = NetworkService.new @logger
network_proposal = Proposal.find_by(barclamp: net_svc.bc_name, name: "default")
!network_proposal["attributes"]["network"]["networks"][network_name].nil?
- 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 26.
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