fog/fog-azure-rm

View on GitHub
lib/fog/azurerm/models/network/network_security_group.rb

Summary

Maintainability
A
50 mins
Test Coverage
F
32%

Method parse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def self.parse(nsg)
          hash = {}
          hash['id'] = nsg.id
          hash['name'] = nsg.name
          hash['resource_group'] = get_resource_from_resource_id(nsg.id, RESOURCE_GROUP_NAME)
Severity: Minor
Found in lib/fog/azurerm/models/network/network_security_group.rb - About 25 mins to fix

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_security_rules has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

        def validate_security_rules(security_rules)
          if security_rules.is_a?(Array)
            security_rules.each do |sr|
              if sr.is_a?(Hash)
                validate_security_rule_params(sr)
Severity: Minor
Found in lib/fog/azurerm/models/network/network_security_group.rb - About 25 mins to fix

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 a guard clause instead of wrapping the code inside a conditional expression.
Open

              if sr.is_a?(Hash)

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

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

          if missing.length == 1

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

Use %i or %I for an array of symbols.
Open

          required_params = [
            :name,
            :protocol,
            :source_port_range,
            :destination_port_range,

This cop can check for array literals made up of symbols that are not using the %i() syntax.

Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

Example: EnforcedStyle: percent (default)

# good
%i[foo bar baz]

# bad
[:foo, :bar, :baz]

Example: EnforcedStyle: brackets

# good
[:foo, :bar, :baz]

# bad
%i[foo bar baz]

Use a guard clause instead of wrapping the code inside a conditional expression.
Open

          if security_rules.is_a?(Array)

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

Favor a normal unless-statement over a modifier clause in a multiline statement.
Open

          nsg.security_rules.each do |sr|
            security_rule = Fog::Network::AzureRM::NetworkSecurityRule.new
            hash['security_rules'] << security_rule.merge_attributes(Fog::Network::AzureRM::NetworkSecurityRule.parse(sr))
          end unless nsg.security_rules.nil?

Checks for uses of if/unless modifiers with multiple-lines bodies.

Example:

# bad
{
  result: 'this should not happen'
} unless cond

# good
{ result: 'ok' } if cond

There are no issues that match your filters.

Category
Status