Showing 52 of 52 total issues
Method bill_deployment
has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring. Open
def self.bill_deployment(dep, billing_time, message, apply_prepayment = true)
appl = dep.appliance # Shorthand
if dep.prepaid_until.blank?
# This should not happen - it means that we do not know when this deployment will run out of funds.
# Therefore we cannot meaningfully bill it again and must return an error.
- 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
Class AppliancesController
has 30 methods (exceeds 20 allowed). Consider refactoring. Open
class Atmosphere::Api::V1::AppliancesController < Atmosphere::Api::ApplicationController
before_action :build_appliance, only: :create
load_and_authorize_resource :appliance,
class: 'Atmosphere::Appliance'
Method execute
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def execute
action.log(I18n.t('satisfy_appliance.start'))
if appliance.virtual_machines.blank?
if optimization_strategy.can_reuse_vm? &&
!(vm = optimization_strategy.vm_to_reuse).nil?
- 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 nav_link
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def nav_link(options = {}, &block)
if path = options.delete(:path)
if path.respond_to?(:each)
c = path.map { |p| p.split('#').first }
a = path.map { |p| p.split('#').last }
- 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
Class VmUpdater
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class VmUpdater
def initialize(tenant, server, updater_class = Proxy::ApplianceProxyUpdater)
@tenant = tenant
@server = server
@updater_class = updater_class
Method execute
has 49 lines of code (exceeds 25 allowed). Consider refactoring. Open
def execute
action.log(I18n.t('satisfy_appliance.start'))
if appliance.virtual_machines.blank?
if optimization_strategy.can_reuse_vm? &&
!(vm = optimization_strategy.vm_to_reuse).nil?
Method action
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def action
return reboot if reboot_action?
return scale if scale_action?
return pause if pause_action?
return stop if stop_action?
- 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 bill_deployment
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.bill_deployment(dep, billing_time, message, apply_prepayment = true)
appl = dep.appliance # Shorthand
if dep.prepaid_until.blank?
# This should not happen - it means that we do not know when this deployment will run out of funds.
# Therefore we cannot meaningfully bill it again and must return an error.
Method select
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def select
best_template = nil
best_tenant = nil
best_flavor = nil
instantiation_cost = Float::INFINITY
- 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 perform_update!
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def perform_update!
vmt.id_at_site = image.id
vmt.name = image.name
vmt.architecture = image.architecture
vmt.state = image.status.downcase.to_sym
- 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 select
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def select
best_template = nil
best_tenant = nil
best_flavor = nil
instantiation_cost = Float::INFINITY
Method get_optimal_flavor_for_tenant
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_optimal_flavor_for_tenant(tmpl, t)
mfs = matching_flavors(tmpl, t)
best_cost = Float::INFINITY
best_mem = Float::INFINITY
opt_fl = nil
Similar blocks of code found in 2 locations. Consider refactoring. Open
def min_elements_by_with_block(arr, &block)
min_elements, arr = first_elements_and_residue(arr, &block)
return [] if arr.empty? && min_elements.nil?
arr.each do |e|
current_min_elements_value = yield(min_elements.first)
- Read upRead up
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 51.
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
def max_elements_by_with_block(arr, &block)
max_elements, arr = first_elements_and_residue(arr, &block)
return [] if arr.empty? && max_elements.nil?
arr.each do |e|
current_max_elements_value = yield(max_elements.first)
- Read upRead up
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 51.
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
Method execute
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def execute
Atmosphere::ApplianceType.transaction do
if vm = appliance && appliance.virtual_machines.first
@tmpl = Atmosphere::VirtualMachineTemplate.
create_from_vm(vm, params[:name])
- 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 min_elements_by_with_block
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def min_elements_by_with_block(arr, &block)
min_elements, arr = first_elements_and_residue(arr, &block)
return [] if arr.empty? && min_elements.nil?
arr.each do |e|
current_min_elements_value = yield(min_elements.first)
- 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 get_optimal_flavor_for_tenant
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def get_optimal_flavor_for_tenant(tmpl, t)
mfs = matching_flavors(tmpl, t)
best_cost = Float::INFINITY
best_mem = Float::INFINITY
opt_fl = nil
- 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 index
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def index
flavors = []
cs_id = params[:compute_site_id]
if optimizer_query?
- 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 create_from_vm
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.create_from_vm(virtual_machine, name = virtual_machine.name)
name_with_timestamp = "#{name}/#{VirtualMachineTemplate.generate_timestamp}"
tmpl_name = VirtualMachineTemplate.sanitize_tmpl_name(name_with_timestamp)
t = virtual_machine.tenant
Method instantiate_vm
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def instantiate_vm(tmpl, tenant, flavor, name)
server_id = start_vm_on_cloud(tmpl, tenant, flavor, name)
vm = VirtualMachine.find_or_initialize_by(
id_at_site: server_id,
tenant: tenant