fog/fog-azure-rm

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

Summary

Maintainability
A
3 hrs
Test Coverage
F
40%

Method parse has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

        def self.parse(network_gateway)
          hash = {}
          hash['id'] = network_gateway.id
          hash['name'] = network_gateway.name
          hash['location'] = network_gateway.location
Severity: Minor
Found in lib/fog/azurerm/models/network/virtual_network_gateway.rb - About 1 hr to fix

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

            def self.parse(network_gateway)
              hash = {}
              hash['id'] = network_gateway.id
              hash['name'] = network_gateway.name
              hash['location'] = network_gateway.location
    Severity: Minor
    Found in lib/fog/azurerm/models/network/virtual_network_gateway.rb - About 45 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_ip_configuration_params has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

            def validate_ip_configuration_params(ip_configuration)
              required_params = [
                :name,
                :private_ipallocation_method
              ]
    Severity: Minor
    Found in lib/fog/azurerm/models/network/virtual_network_gateway.rb - About 45 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_ip_configurations has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

            def validate_ip_configurations(ip_configurations)
              unless ip_configurations.is_a?(Array)
                raise(ArgumentError, ':ip_configurations must be an Array')
              end
              unless ip_configurations.any?
    Severity: Minor
    Found in lib/fog/azurerm/models/network/virtual_network_gateway.rb - About 35 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 ip_configuration.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

              unless ip_configuration.key?(:subnet_id) || ip_configuration.key?(:public_ipaddress_id)

    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

              network_gateway.ip_configurations.each do |ip_config|
                ip_configuration = Fog::Network::AzureRM::FrontendIPConfiguration.new
                hash['ip_configurations'] << ip_configuration.merge_attributes(Fog::Network::AzureRM::FrontendIPConfiguration.parse(ip_config))
              end unless network_gateway.ip_configurations.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

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

              required_params = [
                :name,
                :private_ipallocation_method
              ]

    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]

    There are no issues that match your filters.

    Category
    Status