Method get_private_images
has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring. Open
def get_private_images(storage_accounts)
results = []
mutex = Mutex.new
Parallel.each(storage_accounts, :in_threads => configuration.max_threads) do |storage_account|
- 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 StorageAccountService
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class StorageAccountService < ResourceGroupBasedService
# Creates and returns a new StorageAccountService (SAS) instance.
#
def initialize(configuration, options = {})
super(configuration, 'storageAccounts', 'Microsoft.Storage', options)
Method get_private_images
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def get_private_images(storage_accounts)
results = []
mutex = Mutex.new
Parallel.each(storage_accounts, :in_threads => configuration.max_threads) do |storage_account|
Method parse_uri
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def parse_uri(uri)
uri = Addressable::URI.parse(uri)
host_components = uri.host.split('.')
rh = {
- 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
Use match?
instead of =~
when MatchData
is not used. Open
next if container.name_from_hash =~ /^bootdiagnostics/i
- Read upRead up
- Exclude checks
In Ruby 2.4, String#match?
, Regexp#match?
and Symbol#match?
have been added. The methods are faster than match
.
Because the methods avoid creating a MatchData
object or saving
backref.
So, when MatchData
is not used, use match?
instead of match
.
Example:
# bad
def foo
if x =~ /re/
do_something
end
end
# bad
def foo
if x.match(/re/)
do_something
end
end
# bad
def foo
if /re/ === x
do_something
end
end
# good
def foo
if x.match?(/re/)
do_something
end
end
# good
def foo
if x =~ /re/
do_something(Regexp.last_match)
end
end
# good
def foo
if x.match(/re/)
do_something($~)
end
end
# good
def foo
if /re/ === x
do_something($~)
end
end