orange-cloudfoundry/cf-ops-automation

View on GitHub
upgrade/v5.0.0/01-upgrade-paas-template.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Method has too many lines. [47/10]
Open

def migrate_to_root_deployment_yml(paas_template_root)
  root_deployment_migrated = 0
  incomplete_releases = {}
  root_deployments_path = Dir["#{paas_template_root}/*-depls"]
  puts root_deployments_path

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.

Assignment Branch Condition size for migrate_to_root_deployment_yml is too high. [46.37/15]
Open

def migrate_to_root_deployment_yml(paas_template_root)
  root_deployment_migrated = 0
  incomplete_releases = {}
  root_deployments_path = Dir["#{paas_template_root}/*-depls"]
  puts root_deployments_path

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 migrate_to_root_deployment_yml has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

def migrate_to_root_deployment_yml(paas_template_root)
  root_deployment_migrated = 0
  incomplete_releases = {}
  root_deployments_path = Dir["#{paas_template_root}/*-depls"]
  puts root_deployments_path
Severity: Minor
Found in upgrade/v5.0.0/01-upgrade-paas-template.rb - About 2 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

Method migrate_to_root_deployment_yml has 47 lines of code (exceeds 25 allowed). Consider refactoring.
Open

def migrate_to_root_deployment_yml(paas_template_root)
  root_deployment_migrated = 0
  incomplete_releases = {}
  root_deployments_path = Dir["#{paas_template_root}/*-depls"]
  puts root_deployments_path
Severity: Minor
Found in upgrade/v5.0.0/01-upgrade-paas-template.rb - About 1 hr to fix

Block has too many lines. [40/25]
Open

  root_deployments_path.each do |path|
    root_deployment_name = File.basename(path)
    versions_file = File.join(path, "#{root_deployment_name}-versions.yml")
    versions = YAML.load_file(versions_file)

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

migrate_to_root_deployment_yml refers to 'root_deployment_file' more than self (maybe move it to another class?)
Open

    root_deployment_file.update_stemcell_version(stemcell_version.to_s)
    versions.each do |item, value|
      puts "Versions: processing #{item}"
      case item
      when /^(.*)-sha1/

Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.

Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.

Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.

Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.

Example

Running Reek on:

class Warehouse
  def sale_price(item)
    (item.price - item.rebate) * @vat
  end
end

would report:

Warehouse#total_price refers to item more than self (FeatureEnvy)

since this:

(item.price - item.rebate)

belongs to the Item class, not the Warehouse.

migrate_to_root_deployment_yml has approx 38 statements
Open

def migrate_to_root_deployment_yml(paas_template_root)

A method with Too Many Statements is any method that has a large number of lines.

Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

So the following method would score +6 in Reek's statement-counting algorithm:

def parse(arg, argv, &error)
  if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
    return nil, block, nil                                         # +1
  end
  opt = (val = parse_arg(val, &error))[1]                          # +2
  val = conv_arg(*val)                                             # +3
  if opt and !arg
    argv.shift                                                     # +4
  else
    val[0] = nil                                                   # +5
  end
  val                                                              # +6
end

(You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

migrate_to_root_deployment_yml contains iterators nested 3 deep
Open

      deployment_dependencies_releases.each do |release, details|

A Nested Iterator occurs when a block contains another block.

Example

Given

class Duck
  class << self
    def duck_names
      %i!tick trick track!.each do |surname|
        %i!duck!.each do |last_name|
          puts "full name is #{surname} #{last_name}"
        end
      end
    end
  end
end

Reek would report the following warning:

test.rb -- 1 warning:
  [5]:Duck#duck_names contains iterators nested 2 deep (NestedIterators)

RootDeploymentFile has no descriptive comment
Open

class RootDeploymentFile

Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

Example

Given

class Dummy
  # Do things...
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [1]:Dummy has no descriptive comment (IrresponsibleModule)

Fixing this is simple - just an explaining comment:

# The Dummy class is responsible for ...
class Dummy
  # Do things...
end

RootDeploymentFile#update_release_sha1 has the name 'update_release_sha1'
Open

  def update_release_sha1(release_name, sha1)

An Uncommunicative Method Name is a method name that doesn't communicate its intent well enough.

Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

RootDeploymentFile#update_release_sha1 has the parameter name 'sha1'
Open

  def update_release_sha1(release_name, sha1)

An Uncommunicative Parameter Name is a parameter name that doesn't communicate its intent well enough.

Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

RootDeploymentFile#update_stemcell_sha1 has the name 'update_stemcell_sha1'
Open

  def update_stemcell_sha1(sha1)

An Uncommunicative Method Name is a method name that doesn't communicate its intent well enough.

Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

RootDeploymentFile#update_stemcell_sha1 has the parameter name 'sha1'
Open

  def update_stemcell_sha1(sha1)

An Uncommunicative Parameter Name is a parameter name that doesn't communicate its intent well enough.

Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

%r-literals should be delimited by { and }.
Open

        updated_base_location = details.dig('base_location').gsub(%r(bosh.io/d/), '')

This cop enforces the consistent usage of %-literal delimiters.

Specify the 'default' key to set all preferred delimiters at once. You can continue to specify individual preferred delimiters to override the default.

Example:

# Style/PercentLiteralDelimiters:
#   PreferredDelimiters:
#     default: '[]'
#     '%i':    '()'

# good
%w[alpha beta] + %i(gamma delta)

# bad
%W(alpha #{beta})

# bad
%I(alpha beta)

Redundant curly braces around a hash parameter.
Open

    YAML.dump({ 'name' => @name, 'releases' => @releases.sort.to_h, 'stemcell' => @stemcell })

This cop checks for braces around the last parameter in a method call if the last parameter is a hash. It supports braces, no_braces and context_dependent styles.

Example: EnforcedStyle: braces

# The `braces` style enforces braces around all method
# parameters that are hashes.

# bad
some_method(x, y, a: 1, b: 2)

# good
some_method(x, y, {a: 1, b: 2})

Example: EnforcedStyle: no_braces (default)

# The `no_braces` style checks that the last parameter doesn't
# have braces around it.

# bad
some_method(x, y, {a: 1, b: 2})

# good
some_method(x, y, a: 1, b: 2)

Example: EnforcedStyle: context_dependent

# The `context_dependent` style checks that the last parameter
# doesn't have braces around it, but requires braces if the
# second to last parameter is also a hash literal.

# bad
some_method(x, y, {a: 1, b: 2})
some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)

# good
some_method(x, y, a: 1, b: 2)
some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})

There are no issues that match your filters.

Category
Status