cloudamatic/mu

View on GitHub
modules/mu/mommacat/search.rb

Summary

Maintainability
C
1 day
Test Coverage

Assignment Branch Condition size for search_my_deploys is too high. [156.8/75]
Open

    def self.search_my_deploys(type, deploy_id: nil, name: nil, mu_name: nil, cloud_id: nil, credentials: nil)
      kittens = {}
      _shortclass, _cfg_name, type, _classname, attrs = MU::Cloud.getResourceNames(type, true)

      # Check our in-memory cache of live deploys before resorting to
Severity: Minor
Found in modules/mu/mommacat/search.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

Assignment Branch Condition size for findLitterMate is too high. [114.3/75]
Open

    def findLitterMate(type: nil, name: nil, mu_name: nil, cloud_id: nil, created_only: false, return_all: false, credentials: nil, habitat: nil, ignore_missing: false, debug: false, **flags)
      _shortclass, _cfg_name, type, _classname, attrs = MU::Cloud.getResourceNames(type)

      # If we specified a habitat, which we may also have done by its shorthand
      # sibling name, or a Ref. Convert to something we can use.
Severity: Minor
Found in modules/mu/mommacat/search.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

Cyclomatic complexity for findLitterMate is too high. [53/30]
Open

    def findLitterMate(type: nil, name: nil, mu_name: nil, cloud_id: nil, created_only: false, return_all: false, credentials: nil, habitat: nil, ignore_missing: false, debug: false, **flags)
      _shortclass, _cfg_name, type, _classname, attrs = MU::Cloud.getResourceNames(type)

      # If we specified a habitat, which we may also have done by its shorthand
      # sibling name, or a Ref. Convert to something we can use.
Severity: Minor
Found in modules/mu/mommacat/search.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.

Perceived complexity for findLitterMate is too high. [56/35]
Open

    def findLitterMate(type: nil, name: nil, mu_name: nil, cloud_id: nil, created_only: false, return_all: false, credentials: nil, habitat: nil, ignore_missing: false, debug: false, **flags)
      _shortclass, _cfg_name, type, _classname, attrs = MU::Cloud.getResourceNames(type)

      # If we specified a habitat, which we may also have done by its shorthand
      # sibling name, or a Ref. Convert to something we can use.
Severity: Minor
Found in modules/mu/mommacat/search.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 findLitterMate has a Cognitive Complexity of 96 (exceeds 75 allowed). Consider refactoring.
Open

    def findLitterMate(type: nil, name: nil, mu_name: nil, cloud_id: nil, created_only: false, return_all: false, credentials: nil, habitat: nil, ignore_missing: false, debug: false, **flags)
      _shortclass, _cfg_name, type, _classname, attrs = MU::Cloud.getResourceNames(type)

      # If we specified a habitat, which we may also have done by its shorthand
      # sibling name, or a Ref. Convert to something we can use.
Severity: Minor
Found in modules/mu/mommacat/search.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

Perceived complexity for search_my_deploys is too high. [50/35]
Open

    def self.search_my_deploys(type, deploy_id: nil, name: nil, mu_name: nil, cloud_id: nil, credentials: nil)
      kittens = {}
      _shortclass, _cfg_name, type, _classname, attrs = MU::Cloud.getResourceNames(type, true)

      # Check our in-memory cache of live deploys before resorting to
Severity: Minor
Found in modules/mu/mommacat/search.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

Cyclomatic complexity for search_my_deploys is too high. [44/30]
Open

    def self.search_my_deploys(type, deploy_id: nil, name: nil, mu_name: nil, cloud_id: nil, credentials: nil)
      kittens = {}
      _shortclass, _cfg_name, type, _classname, attrs = MU::Cloud.getResourceNames(type, true)

      # Check our in-memory cache of live deploys before resorting to
Severity: Minor
Found in modules/mu/mommacat/search.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.

Cyclomatic complexity for findStray is too high. [40/30]
Open

    def self.findStray(cloud, type,
        dummy_ok: false,
        no_deploy_search: false,
        allow_multi: false,
        deploy_id: nil,
Severity: Minor
Found in modules/mu/mommacat/search.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.

Perceived complexity for findStray is too high. [42/35]
Open

    def self.findStray(cloud, type,
        dummy_ok: false,
        no_deploy_search: false,
        allow_multi: false,
        deploy_id: nil,
Severity: Minor
Found in modules/mu/mommacat/search.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 search_my_deploys has a Cognitive Complexity of 84 (exceeds 75 allowed). Consider refactoring.
Open

    def self.search_my_deploys(type, deploy_id: nil, name: nil, mu_name: nil, cloud_id: nil, credentials: nil)
      kittens = {}
      _shortclass, _cfg_name, type, _classname, attrs = MU::Cloud.getResourceNames(type, true)

      # Check our in-memory cache of live deploys before resorting to
Severity: Minor
Found in modules/mu/mommacat/search.rb - About 1 hr 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

Avoid deeply nested control flow statements.
Open

              MU.log "#{@deploy_id}'s original config has #{@original_config[type].size == 1 ? "a" : @original_config[type].size.to_s} #{type}, but loadObjects could not populate anything from deployment metadata", MU::ERR if !@object_load_fails
Severity: Major
Found in modules/mu/mommacat/search.rb - About 45 mins to fix

    Method generate_dummy_object has 11 arguments (exceeds 10 allowed). Consider refactoring.
    Open

        def self.generate_dummy_object(type, cloud, name, mu_name, cloud_id, desc, region, habitat, tag_value, calling_deploy, credentials)
    Severity: Major
    Found in modules/mu/mommacat/search.rb - About 35 mins to fix

      Avoid too many return statements within this method.
      Open

              return matches.values.first if matches.size == 1
      Severity: Major
      Found in modules/mu/mommacat/search.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

              return nil
        Severity: Major
        Found in modules/mu/mommacat/search.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return matches if return_all and matches.size >= 1
          Severity: Major
          Found in modules/mu/mommacat/search.rb - About 30 mins to fix

            Avoid more than 4 levels of block nesting.
            Open

                          MU.log "#{@deploy_id}'s original config has #{@original_config[type].size == 1 ? "a" : @original_config[type].size.to_s} #{type}, but loadObjects could not populate anything from deployment metadata", MU::ERR if !@object_load_fails
            Severity: Minor
            Found in modules/mu/mommacat/search.rb by rubocop

            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.

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

                        (mu_name and obj.mu_name and mu_name.to_s != obj.mu_name) or
                        (cloud_id and obj.cloud_id and cloud_id.to_s != obj.cloud_id.to_s) or
                        (credentials and obj.credentials and credentials.to_s != obj.credentials.to_s)
                      )
            Severity: Minor
            Found in modules/mu/mommacat/search.rb and 1 other location - About 35 mins to fix
            modules/mu/mommacat/search.rb on lines 162..164

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

            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

                      (mu_name and obj.mu_name and mu_name.to_s == obj.mu_name) or
                      (cloud_id and obj.cloud_id and cloud_id.to_s == obj.cloud_id.to_s) or
                      (credentials and obj.credentials and credentials.to_s == obj.credentials.to_s) and
            Severity: Minor
            Found in modules/mu/mommacat/search.rb and 1 other location - About 35 mins to fix
            modules/mu/mommacat/search.rb on lines 166..169

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

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

                def findLitterMate(type: nil, name: nil, mu_name: nil, cloud_id: nil, created_only: false, return_all: false, credentials: nil, habitat: nil, ignore_missing: false, debug: false, **flags)
            Severity: Minor
            Found in modules/mu/mommacat/search.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 - flags. If it's necessary, use _ or _flags as an argument name to indicate that it won't be used.
            Open

                def findLitterMate(type: nil, name: nil, mu_name: nil, cloud_id: nil, created_only: false, return_all: false, credentials: nil, habitat: nil, ignore_missing: false, debug: false, **flags)
            Severity: Minor
            Found in modules/mu/mommacat/search.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 261, 6 is not aligned with if at 253, 17.
            Open

                  end
            Severity: Minor
            Found in modules/mu/mommacat/search.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)

            end at 324, 6 is not aligned with if at 312, 16.
            Open

                  end
            Severity: Minor
            Found in modules/mu/mommacat/search.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)

            end at 477, 8 is not aligned with if at 464, 22.
            Open

                    end
            Severity: Minor
            Found in modules/mu/mommacat/search.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)

            There are no issues that match your filters.

            Category
            Status