cloudamatic/mu

View on GitHub
modules/mu/providers/aws/collection.rb

Summary

Maintainability
B
5 hrs
Test Coverage

Assignment Branch Condition size for create is too high. [247.2/75]
Open

        def create
          flag="SUCCESS"
          MU.setVar("curRegion", @region) if !@region.nil?
          region = @region
          server=@config["name"]

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

Cyclomatic complexity for create is too high. [31/30]
Open

        def create
          flag="SUCCESS"
          MU.setVar("curRegion", @region) if !@region.nil?
          region = @region
          server=@config["name"]

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 has 169 lines of code (exceeds 150 allowed). Consider refactoring.
Open

        def create
          flag="SUCCESS"
          MU.setVar("curRegion", @region) if !@region.nil?
          region = @region
          server=@config["name"]
Severity: Major
Found in modules/mu/providers/aws/collection.rb - About 1 hr to fix

    Avoid more than 4 levels of block nesting.
    Open

                        if mystack.size > 0 and mystack.stack_status == "DELETE_FAILED"
                          MU.log "Couldn't delete CloudFormation stack #{stack.stack_name}", MU::ERR, details: mystack.stack_status_reason
                          return
                        end

    This cop checks for excessive nesting of conditional and looping constructs.

    You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

    The maximum level of nesting allowed is configurable.

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

                    if @config["template_file"].match(/^\//)

    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 2 locations. Consider refactoring.
    Open

                    when "AWS::EC2::Subnet"
                      MU::Cloud::AWS.createStandardTags(resource.physical_resource_id)
                      MU::Cloud::AWS.createTag(resource.physical_resource_id, "Name", MU.deploy_id+"-"+@config['name']+'-'+resource.logical_resource_id, credentials: @credentials)
                      data = {
                          "collection" => @config["name"],
    Severity: Major
    Found in modules/mu/providers/aws/collection.rb and 1 other location - About 1 hr to fix
    modules/mu/providers/aws/collection.rb on lines 193..200

    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 53.

    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

                    when "AWS::EC2::VPC"
                      MU::Cloud::AWS.createStandardTags(resource.physical_resource_id)
                      MU::Cloud::AWS.createTag(resource.physical_resource_id, "Name", MU.deploy_id+"-"+@config['name']+'-'+resource.logical_resource_id, credentials: @credentials)
                      data = {
                          "collection" => @config["name"],
    Severity: Major
    Found in modules/mu/providers/aws/collection.rb and 1 other location - About 1 hr to fix
    modules/mu/providers/aws/collection.rb on lines 185..192

    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 53.

    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

                    when "AWS::EC2::RouteTable"
                      MU::Cloud::AWS.createStandardTags(resource.physical_resource_id)
                      MU::Cloud::AWS.createTag(resource.physical_resource_id, "Name", MU.deploy_id+"-"+@config['name']+'-'+resource.logical_resource_id, credentials: @credentials)
    Severity: Minor
    Found in modules/mu/providers/aws/collection.rb and 1 other location - About 30 mins to fix
    modules/mu/providers/aws/collection.rb on lines 201..203

    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 32.

    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

                    when "AWS::EC2::InternetGateway"
                      MU::Cloud::AWS.createStandardTags(resource.physical_resource_id)
                      MU::Cloud::AWS.createTag(resource.physical_resource_id, "Name", MU.deploy_id+"-"+@config['name']+'-'+resource.logical_resource_id, credentials: @credentials)
    Severity: Minor
    Found in modules/mu/providers/aws/collection.rb and 1 other location - About 30 mins to fix
    modules/mu/providers/aws/collection.rb on lines 204..206

    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 32.

    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

    Do not suppress exceptions.
    Open

                    rescue Aws::CloudFormation::Errors::ValidationError

    This cop checks for rescue blocks with no body.

    Example:

    # bad
    
    def some_method
      do_something
    rescue
      # do nothing
    end

    Example:

    # bad
    
    begin
      do_something
    rescue
      # do nothing
    end

    Example:

    # good
    
    def some_method
      do_something
    rescue
      handle_exception
    end

    Example:

    # good
    
    begin
      do_something
    rescue
      handle_exception
    end

    There are no issues that match your filters.

    Category
    Status