cloudamatic/mu

View on GitHub
modules/mu/providers/azure/vpc.rb

Summary

Maintainability
D
2 days
Test Coverage

Assignment Branch Condition size for create_update is too high. [259.1/75]
Open

        def create_update
          @config = MU::Config.manxify(@config)
          @config['region'] ||= MU::Cloud::Azure.myRegion(@config['credentials'])
          tags = {}
          if !@config['scrub_mu_isms']
Severity: Minor
Found in modules/mu/providers/azure/vpc.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

Method create_update has a Cognitive Complexity of 117 (exceeds 75 allowed). Consider refactoring.
Open

        def create_update
          @config = MU::Config.manxify(@config)
          @config['region'] ||= MU::Cloud::Azure.myRegion(@config['credentials'])
          tags = {}
          if !@config['scrub_mu_isms']
Severity: Minor
Found in modules/mu/providers/azure/vpc.rb - About 7 hrs 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

Perceived complexity for create_update is too high. [65/35]
Open

        def create_update
          @config = MU::Config.manxify(@config)
          @config['region'] ||= MU::Cloud::Azure.myRegion(@config['credentials'])
          tags = {}
          if !@config['scrub_mu_isms']
Severity: Minor
Found in modules/mu/providers/azure/vpc.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Method has too many lines. [226/200]
Open

        def create_update
          @config = MU::Config.manxify(@config)
          @config['region'] ||= MU::Cloud::Azure.myRegion(@config['credentials'])
          tags = {}
          if !@config['scrub_mu_isms']
Severity: Minor
Found in modules/mu/providers/azure/vpc.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Cyclomatic complexity for create_update is too high. [52/30]
Open

        def create_update
          @config = MU::Config.manxify(@config)
          @config['region'] ||= MU::Cloud::Azure.myRegion(@config['credentials'])
          tags = {}
          if !@config['scrub_mu_isms']
Severity: Minor
Found in modules/mu/providers/azure/vpc.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method create_update has 226 lines of code (exceeds 150 allowed). Consider refactoring.
Open

        def create_update
          @config = MU::Config.manxify(@config)
          @config['region'] ||= MU::Cloud::Azure.myRegion(@config['credentials'])
          tags = {}
          if !@config['scrub_mu_isms']
Severity: Major
Found in modules/mu/providers/azure/vpc.rb - About 4 hrs to fix

    Assignment Branch Condition size for groom is too high. [81.91/75]
    Open

            def groom
    
              if @config['peers']
                @config['peers'].each { |peer|
                  if peer['vpc']['name']
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Use =~ in places where the MatchData returned by #match will not be used.
    Open

                    if e.message.match(/: ResourceNotFound:/)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

    Example:

    # bad
    do_something if str.match(/regex/)
    while regex.match('str')
      do_something
    end
    
    # good
    method(str =~ /regex/)
    return value unless regex =~ 'str'

    Use =~ in places where the MatchData returned by #match will not be used.
    Open

                      if e.message.match(/\bNotFound\b/)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

    Example:

    # bad
    do_something if str.match(/regex/)
    while regex.match('str')
      do_something
    end
    
    # good
    method(str =~ /regex/)
    return value unless regex =~ 'str'

    Use caller(1..1).first instead of caller[0].
    Open

              MU.log "getSubnet(cloud_id: #{cloud_id}, name: #{name}, tag_key: #{tag_key}, tag_value: #{tag_value}, ip_block: #{ip_block})", MU::DEBUG, details: caller[0]
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop identifies places where caller[n] can be replaced by caller(n..n).first.

    Example:

    # bad
    caller[1]
    caller.first
    caller_locations[1]
    caller_locations.first
    
    # good
    caller(2..2).first
    caller(1..1).first
    caller_locations(2..2).first
    caller_locations(1..1).first

    Use =~ in places where the MatchData returned by #match will not be used.
    Open

                  if e.message.match(/InUseSubnetCannotBeDeleted: /)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

    Example:

    # bad
    do_something if str.match(/regex/)
    while regex.match('str')
      do_something
    end
    
    # good
    method(str =~ /regex/)
    return value unless regex =~ 'str'

    Use =~ in places where the MatchData returned by #match will not be used.
    Open

                        if e.message.match(/InUseSubnetCannotBeUpdated: /)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

    Example:

    # bad
    do_something if str.match(/regex/)
    while regex.match('str')
      do_something
    end
    
    # good
    method(str =~ /regex/)
    return value unless regex =~ 'str'

    Use =~ in places where the MatchData returned by #match will not be used.
    Open

                if e.message.match(/: ResourceNotFound:/)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

    Example:

    # bad
    do_something if str.match(/regex/)
    while regex.match('str')
      do_something
    end
    
    # good
    method(str =~ /regex/)
    return value unless regex =~ 'str'

    Use =~ in places where the MatchData returned by #match will not be used.
    Open

                      if e.message.match(/\bNotFound\b/)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop identifies the use of Regexp#match or String#match, which returns #<MatchData>/nil. The return value of =~ is an integral index/nil and is more performant.

    Example:

    # bad
    do_something if str.match(/regex/)
    while regex.match('str')
      do_something
    end
    
    # good
    method(str =~ /regex/)
    return value unless regex =~ 'str'

    Similar blocks of code found in 3 locations. Consider refactoring.
    Open

            def self.find(**args)
              found = {}
    
              # Azure resources are namedspaced by resource group. If we weren't
              # told one, we may have to search all the ones we can see.
    Severity: Major
    Found in modules/mu/providers/azure/vpc.rb and 2 other locations - About 4 hrs to fix
    modules/mu/providers/azure/container_cluster.rb on lines 86..117
    modules/mu/providers/azure/loadbalancer.rb on lines 122..153

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 148.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                    tag_key, tag_value = peer['vpc']['tag'].split(/=/, 2) if !peer['vpc']['tag'].nil?
                    if peer['vpc']['deploy_id'].nil? and peer['vpc']['id'].nil? and tag_key.nil?
                      peer['vpc']['deploy_id'] = @deploy.deploy_id
                    end
    
    
    Severity: Major
    Found in modules/mu/providers/azure/vpc.rb and 1 other location - About 2 hrs to fix
    modules/mu/providers/google/vpc.rb on lines 170..185

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 78.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

                if !cloud_id.nil? and !subnet.cloud_id.nil? and subnet.cloud_id.to_s == cloud_id.to_s
                  return subnet
                elsif !name.nil? and !subnet.name.nil? and subnet.name.to_s == name.to_s
                  return subnet
                end
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb and 1 other location - About 35 mins to fix
    modules/mu/providers/aws/vpc.rb on lines 633..637

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 36.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Unused method argument - nat_filter_value. You can also write as findNat(*) if you want the method to accept any arguments but don't care about them.
    Open

            def findNat(nat_cloud_id: nil, nat_filter_key: nil, nat_filter_value: nil, region: MU.curRegion)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end

    Example:

    # good
    
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    Unused method argument - nat_filter_key. You can also write as findNat(*) if you want the method to accept any arguments but don't care about them.
    Open

            def findNat(nat_cloud_id: nil, nat_filter_key: nil, nat_filter_value: nil, region: MU.curRegion)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end

    Example:

    # good
    
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    end at 593, 16 is not aligned with if at 568, 42.
    Open

                    end
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop checks whether the end keywords are aligned properly.

    Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

    If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

    If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

    If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

    Example: EnforcedStyleAlignWith: keyword (default)

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
               end

    Example: EnforcedStyleAlignWith: variable

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
    end

    Example: EnforcedStyleAlignWith: startofline

    # bad
    
    variable = if true
        end
    
    # good
    
    puts(if true
    end)

    Unused method argument - credentials. You can also write as haveRouteToInstance?(*) if you want the method to accept any arguments but don't care about them.
    Open

            def self.haveRouteToInstance?(target_instance, region: MU.curRegion, credentials: nil)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end

    Example:

    # good
    
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    Unused method argument - region. You can also write as findNat(*) if you want the method to accept any arguments but don't care about them.
    Open

            def findNat(nat_cloud_id: nil, nat_filter_key: nil, nat_filter_value: nil, region: MU.curRegion)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end

    Example:

    # good
    
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    Unused method argument - region. You can also write as haveRouteToInstance?(*) if you want the method to accept any arguments but don't care about them.
    Open

            def self.haveRouteToInstance?(target_instance, region: MU.curRegion, credentials: nil)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end

    Example:

    # good
    
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    Unused method argument - nat_cloud_id. You can also write as findNat(*) if you want the method to accept any arguments but don't care about them.
    Open

            def findNat(nat_cloud_id: nil, nat_filter_key: nil, nat_filter_value: nil, region: MU.curRegion)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end

    Example:

    # good
    
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    end at 152, 10 is not aligned with if at 146, 28.
    Open

              end
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop checks whether the end keywords are aligned properly.

    Three modes are supported through the EnforcedStyleAlignWith configuration parameter:

    If it's set to keyword (which is the default), the end shall be aligned with the start of the keyword (if, class, etc.).

    If it's set to variable the end shall be aligned with the left-hand-side of the variable assignment, if there is one.

    If it's set to start_of_line, the end shall be aligned with the start of the line where the matching keyword appears.

    Example: EnforcedStyleAlignWith: keyword (default)

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
               end

    Example: EnforcedStyleAlignWith: variable

    # bad
    
    variable = if true
        end
    
    # good
    
    variable = if true
    end

    Example: EnforcedStyleAlignWith: startofline

    # bad
    
    variable = if true
        end
    
    # good
    
    puts(if true
    end)

    Unused method argument - target_instance. If it's necessary, use _ or _target_instance as an argument name to indicate that it won't be used. You can also write as haveRouteToInstance?(*) if you want the method to accept any arguments but don't care about them.
    Open

            def self.haveRouteToInstance?(target_instance, region: MU.curRegion, credentials: nil)
    Severity: Minor
    Found in modules/mu/providers/azure/vpc.rb by rubocop

    This cop checks for unused method arguments.

    Example:

    # bad
    
    def some_method(used, unused, _unused_but_allowed)
      puts used
    end

    Example:

    # good
    
    def some_method(used, _unused, _unused_but_allowed)
      puts used
    end

    There are no issues that match your filters.

    Category
    Status