File create_virtual_machine.rb
has 362 lines of code (exceeds 250 allowed). Consider refactoring. Open
require 'base64'
WHITE_SPACE = ' '.freeze
module Fog
Method create_virtual_machine
has 58 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_virtual_machine(*)
vm = {
'location' => 'westus',
'id' => '/subscriptions/########-####-####-####-############/resourceGroups/fog-test-rg/providers/Microsoft.Compute/virtualMachines/fog-test-server',
'name' => 'fog-test-server',
Method create_virtual_machine
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def create_virtual_machine(vm_config, async = false)
vm_name = vm_config[:name]
rg_name = vm_config[:resource_group]
# In case of updating the VM, we check if the user has passed any value for os_disk_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 get_unmanaged_vm_storage_profile
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_unmanaged_vm_storage_profile(vm_config)
# Arguments unpacking
vm_name = vm_config[:name]
storage_account_name = vm_config[:storage_account_name]
publisher = vm_config[:publisher]
Method get_managed_vm_storage_profile
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_managed_vm_storage_profile(vm_config)
# Argument unpacking
managed_disk_storage_type = vm_config[:managed_disk_storage_type]
vhd_path = vm_config[:vhd_path]
resource_group = vm_config[:resource_group]
Method create_virtual_machine
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_virtual_machine(vm_config, async = false)
vm_name = vm_config[:name]
rg_name = vm_config[:resource_group]
# In case of updating the VM, we check if the user has passed any value for os_disk_name
Method copy_vhd_to_storage_account
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def copy_vhd_to_storage_account(resource_group, storage_account_name, vhd_path, location, vm_name)
# Copy if VHD does not exist belongs to same storage account.
vhd_storage_account_name = (vhd_path.split('/')[2]).split('.')[0]
if storage_account_name != vhd_storage_account_name
if storage_account_name.nil?
Method configure_os_disk_object
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def configure_os_disk_object(os_disk, os_disk_name, os_disk_caching, os_disk_size, platform, vm_name)
# It will use the os_disk_name provided or it will generate a name for itself if it is nil
os_disk.name = os_disk_name.nil? ? "#{vm_name}_os_disk" : os_disk_name
os_disk.os_type = platform
os_disk.disk_size_gb = os_disk_size unless os_disk_size.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 configure_os_disk_object
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def configure_os_disk_object(os_disk, os_disk_name, os_disk_caching, os_disk_size, platform, vm_name)
Method image_config_params
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def image_config_params(location, new_vhd_path, platform, resource_group, vm_name)
Method copy_vhd_to_storage_account
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def copy_vhd_to_storage_account(resource_group, storage_account_name, vhd_path, location, vm_name)
Method copy_vhd_to_storage_account
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def copy_vhd_to_storage_account(resource_group, storage_account_name, vhd_path, location, vm_name)
# Copy if VHD does not exist belongs to same storage account.
vhd_storage_account_name = (vhd_path.split('/')[2]).split('.')[0]
if storage_account_name != vhd_storage_account_name
if storage_account_name.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 get_os_disk_parameters
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_os_disk_parameters(resource_group, virtual_machine_name)
os_disk_parameters = {}
begin
vm = get_virtual_machine(resource_group, virtual_machine_name, false)
- 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_unmanaged_vm_storage_profile
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_unmanaged_vm_storage_profile(vm_config)
# Arguments unpacking
vm_name = vm_config[:name]
storage_account_name = vm_config[:storage_account_name]
publisher = vm_config[:publisher]
- 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_os_profile
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def get_os_profile(vm_config)
# Arguments unpacking
platform = vm_config[:platform]
vm_name = vm_config[:name]
username = vm_config[:username]
- 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 rescuing without specifying an error class. Open
rescue
- Read upRead up
- Exclude checks
This cop checks for rescuing StandardError
. There are two supported
styles implicit
and explicit
. This cop will not register an offense
if any error other than StandardError
is specified.
Example: EnforcedStyle: implicit
# `implicit` will enforce using `rescue` instead of
# `rescue StandardError`.
# bad
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end
Example: EnforcedStyle: explicit (default)
# `explicit` will enforce using `rescue StandardError`
# instead of `rescue`.
# bad
begin
foo
rescue
bar
end
# good
begin
foo
rescue StandardError
bar
end
# good
begin
foo
rescue OtherError
bar
end
# good
begin
foo
rescue StandardError, SecurityError
bar
end