Class Server
has 24 methods (exceeds 20 allowed). Consider refactoring. Open
class Server < Fog::Model
attribute :id
identity :name
attribute :location
attribute :resource_group
Method parse
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def self.parse(vm)
hash = {}
hash['id'] = vm.id
hash['name'] = vm.name
hash['location'] = vm.location
- 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 parse
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.parse(vm)
hash = {}
hash['id'] = vm.id
hash['name'] = vm.name
hash['location'] = vm.location
Method virtual_machine_params
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def virtual_machine_params(ssh_key_path)
{
resource_group: resource_group,
name: name,
location: location,
Method save
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def save(async = false)
requires :name, :location, :resource_group, :vm_size, :username, :network_interface_card_ids
requires :publisher, :offer, :sku, :version if vhd_path.nil? && image_ref.nil?
requires :storage_account_name if managed_disk_storage_type.nil?
requires :managed_disk_storage_type 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 data_disk_params
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def data_disk_params(disk_name, disk_size = nil, storage_account = nil, disk_resource_group = nil, caching = nil)
Useless assignment to variable - vm
. Open
vm = service.create_virtual_machine(virtual_machine_params(ssh_key_path))
- Read upRead up
- Exclude checks
This cop checks for every useless assignment to local variable in every
scope.
The basic idea for this cop was from the warning of ruby -cw
:
assigned but unused variable - foo
Currently this cop has advanced logic that detects unreferenced reassignments and properly handles varied cases such as branch, loop, rescue, ensure, etc.
Example:
# bad
def some_method
some_var = 1
do_something
end
Example:
# good
def some_method
some_var = 1
do_something(some_var)
end
Use a guard clause instead of wrapping the code inside a conditional expression. Open
unless vhd_path.nil? || !managed_disk_storage_type.nil?
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok