cloudamatic/mu

View on GitHub
modules/mu/providers/cloudformation.rb

Summary

Maintainability
D
2 days
Test Coverage

Assignment Branch Condition size for writeCloudFormationTemplate is too high. [297.4/75]
Open

      def self.writeCloudFormationTemplate(tails: MU::Config.tails, config: {}, path: nil, mommacat: nil)
        cfm_template = {
          "AWSTemplateFormatVersion" => "2010-09-09",
          "Description" =>  "Automatically generated by Mu",
          "Parameters" => {

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 has too many lines. [351/200]
Open

      def self.cloudFormationBase(type, cloudobj = nil, name: nil, tags: [], scrub_mu_isms: false)
        desc = {}
        tags = [] if tags.nil?
        realtags = []
        havenametag = false

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.

Method cloudFormationBase has 351 lines of code (exceeds 150 allowed). Consider refactoring.
Open

      def self.cloudFormationBase(type, cloudobj = nil, name: nil, tags: [], scrub_mu_isms: false)
        desc = {}
        tags = [] if tags.nil?
        realtags = []
        havenametag = false
Severity: Major
Found in modules/mu/providers/cloudformation.rb - About 1 day to fix

    Assignment Branch Condition size for cloudFormationBase is too high. [138.3/75]
    Open

          def self.cloudFormationBase(type, cloudobj = nil, name: nil, tags: [], scrub_mu_isms: false)
            desc = {}
            tags = [] if tags.nil?
            realtags = []
            havenametag = false

    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 cloudFormationBase is too high. [65/30]
    Open

          def self.cloudFormationBase(type, cloudobj = nil, name: nil, tags: [], scrub_mu_isms: false)
            desc = {}
            tags = [] if tags.nil?
            realtags = []
            havenametag = false

    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 has too many lines. [231/200]
    Open

          def self.writeCloudFormationTemplate(tails: MU::Config.tails, config: {}, path: nil, mommacat: nil)
            cfm_template = {
              "AWSTemplateFormatVersion" => "2010-09-09",
              "Description" =>  "Automatically generated by Mu",
              "Parameters" => {

    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.

    Method writeCloudFormationTemplate has 231 lines of code (exceeds 150 allowed). Consider refactoring.
    Open

          def self.writeCloudFormationTemplate(tails: MU::Config.tails, config: {}, path: nil, mommacat: nil)
            cfm_template = {
              "AWSTemplateFormatVersion" => "2010-09-09",
              "Description" =>  "Automatically generated by Mu",
              "Parameters" => {
    Severity: Major
    Found in modules/mu/providers/cloudformation.rb - About 4 hrs to fix

      Perceived complexity for writeCloudFormationTemplate is too high. [54/35]
      Open

            def self.writeCloudFormationTemplate(tails: MU::Config.tails, config: {}, path: nil, mommacat: nil)
              cfm_template = {
                "AWSTemplateFormatVersion" => "2010-09-09",
                "Description" =>  "Automatically generated by Mu",
                "Parameters" => {

      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 writeCloudFormationTemplate has a Cognitive Complexity of 96 (exceeds 75 allowed). Consider refactoring.
      Open

            def self.writeCloudFormationTemplate(tails: MU::Config.tails, config: {}, path: nil, mommacat: nil)
              cfm_template = {
                "AWSTemplateFormatVersion" => "2010-09-09",
                "Description" =>  "Automatically generated by Mu",
                "Parameters" => {
      Severity: Minor
      Found in modules/mu/providers/cloudformation.rb - About 3 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

      Cyclomatic complexity for writeCloudFormationTemplate is too high. [46/30]
      Open

            def self.writeCloudFormationTemplate(tails: MU::Config.tails, config: {}, path: nil, mommacat: nil)
              cfm_template = {
                "AWSTemplateFormatVersion" => "2010-09-09",
                "Description" =>  "Automatically generated by Mu",
                "Parameters" => {

      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.

      Perceived complexity for cloudFormationBase is too high. [43/35]
      Open

            def self.cloudFormationBase(type, cloudobj = nil, name: nil, tags: [], scrub_mu_isms: false)
              desc = {}
              tags = [] if tags.nil?
              realtags = []
              havenametag = false

      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

      Avoid deeply nested control flow statements.
      Open

                          child_params = Hash.new if child_params.nil?
      Severity: Major
      Found in modules/mu/providers/cloudformation.rb - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            subnet.private? ? priv_nets << { "Ref" => "#{subnet.cfm_name}" } : pub_nets << { "Ref" => "#{subnet.cfm_name}" }
        Severity: Major
        Found in modules/mu/providers/cloudformation.rb - About 45 mins to fix

          Avoid too many return statements within this method.
          Open

                      return tree
          Severity: Major
          Found in modules/mu/providers/cloudformation.rb - About 30 mins to fix

            Avoid more than 4 levels of block nesting.
            Open

                                child_params = Hash.new if child_params.nil?

            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 each_value instead of values.each.
            Open

                    MU::Cloud.resource_types.values.each { |data|

            This cop checks for uses of each_key and each_value Hash methods.

            Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

            Example:

            # bad
            hash.keys.each { |k| p k }
            hash.values.each { |v| p v }
            hash.each { |k, _v| p k }
            hash.each { |_k, v| p v }
            
            # good
            hash.each_key { |k| p k }
            hash.each_value { |v| p v }

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

                    elsif path.match(/^s3:\/\/(.+?)\/(.*)/i)

            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 each_key instead of keys.each.
            Open

                                cfm_template["Parameters"].keys.each { |key|

            This cop checks for uses of each_key and each_value Hash methods.

            Note: If you have an array of two-element arrays, you can put parentheses around the block arguments to indicate that you're not working with a hash, and suppress RuboCop offenses.

            Example:

            # bad
            hash.keys.each { |k| p k }
            hash.values.each { |v| p v }
            hash.each { |k, _v| p k }
            hash.each { |_k, v| p v }
            
            # good
            hash.each_key { |k| p k }
            hash.each_value { |v| p v }

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

                              cfm_template["Outputs"]["cachecluster"+namestr+"endpoint"] =
                                {
                                  "Value" =>
                                    { "Fn::GetAtt" =>
                                      [ resource['#MUOBJECT'].cloudobj.cfm_name, "ConfigurationEndpoint.Address" ]
            Severity: Minor
            Found in modules/mu/providers/cloudformation.rb and 1 other location - About 45 mins to fix
            modules/mu/providers/cloudformation.rb on lines 703..714

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

            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

                              cfm_template["Outputs"]["server"+namestr+"privateip"] =
                                {
                                  "Value" =>
                                    { "Fn::GetAtt" =>
                                      [ resource['#MUOBJECT'].cloudobj.cfm_name, "PrivateIp" ]
            Severity: Minor
            Found in modules/mu/providers/cloudformation.rb and 1 other location - About 45 mins to fix
            modules/mu/providers/cloudformation.rb on lines 688..699

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

            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 - name. If it's necessary, use _ or _name as an argument name to indicate that it won't be used. You can also write as credConfig(*) if you want the method to accept any arguments but don't care about them.
            Open

                  def self.credConfig(name = nil, name_only: false)

            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 - name_only. You can also write as credConfig(*) if you want the method to accept any arguments but don't care about them.
            Open

                  def self.credConfig(name = nil, name_only: false)

            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 - credentials. You can also write as writeDeploySecret(*) if you want the method to accept any arguments but don't care about them.
            Open

                  def self.writeDeploySecret(deploy_id, value, name = nil, credentials: nil)

            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 - credentials. If it's necessary, use _ or _credentials as an argument name to indicate that it won't be used. You can also write as adminBucketName(*) if you want the method to accept any arguments but don't care about them.
            Open

                  def self.adminBucketName(credentials = nil)

            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 - value. If it's necessary, use _ or _value as an argument name to indicate that it won't be used. You can also write as writeDeploySecret(*) if you want the method to accept any arguments but don't care about them.
            Open

                  def self.writeDeploySecret(deploy_id, value, name = nil, credentials: nil)

            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 - name. If it's necessary, use _ or _name as an argument name to indicate that it won't be used. You can also write as writeDeploySecret(*) if you want the method to accept any arguments but don't care about them.
            Open

                  def self.writeDeploySecret(deploy_id, value, name = nil, credentials: nil)

            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 - credentials. If it's necessary, use _ or _credentials as an argument name to indicate that it won't be used. You can also write as adminBucketUrl(*) if you want the method to accept any arguments but don't care about them.
            Open

                  def self.adminBucketUrl(credentials = nil)

            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 - deploy_id. If it's necessary, use _ or _deploy_id as an argument name to indicate that it won't be used. You can also write as writeDeploySecret(*) if you want the method to accept any arguments but don't care about them.
            Open

                  def self.writeDeploySecret(deploy_id, value, name = nil, credentials: nil)

            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 - use_cache.
            Open

                  def self.listHabitats(credentials = nil, use_cache: true)

            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