orange-cloudfoundry/cf-ops-automation

View on GitHub
lib/tasks/bosh/create_release.rb

Summary

Maintainability
A
45 mins
Test Coverage
A
100%

Assignment Branch Condition size for execute is too high. [22.02/15]
Open

      def execute(name:, version:, tarball_path:, dir: '.', final: true, force: false, timestamp_version: false)
        raise "Missing required parameter: name:#{name}, version: #{version} or tarball_path: #{tarball_path}" if name.to_s.empty? || version.to_s.empty? || tarball_path.to_s.empty?

        dir_option = "--dir='#{dir}' "
        timestamp_option = timestamp_version ? "--timestamp-version " : ""
Severity: Minor
Found in lib/tasks/bosh/create_release.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 execute is too high. [7/6]
Open

      def execute(name:, version:, tarball_path:, dir: '.', final: true, force: false, timestamp_version: false)
        raise "Missing required parameter: name:#{name}, version: #{version} or tarball_path: #{tarball_path}" if name.to_s.empty? || version.to_s.empty? || tarball_path.to_s.empty?

        dir_option = "--dir='#{dir}' "
        timestamp_option = timestamp_version ? "--timestamp-version " : ""
Severity: Minor
Found in lib/tasks/bosh/create_release.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.

Tasks::Bosh::CreateRelease#execute has boolean parameter 'final'
Open

      def execute(name:, version:, tarball_path:, dir: '.', final: true, force: false, timestamp_version: false)
Severity: Minor
Found in lib/tasks/bosh/create_release.rb by reek

Boolean Parameter is a special case of Control Couple, where a method parameter is defaulted to true or false. A Boolean Parameter effectively permits a method's caller to decide which execution path to take. This is a case of bad cohesion. You're creating a dependency between methods that is not really necessary, thus increasing coupling.

Example

Given

class Dummy
  def hit_the_switch(switch = true)
    if switch
      puts 'Hitting the switch'
      # do other things...
    else
      puts 'Not hitting the switch'
      # do other things...
    end
  end
end

Reek would emit the following warning:

test.rb -- 3 warnings:
  [1]:Dummy#hit_the_switch has boolean parameter 'switch' (BooleanParameter)
  [2]:Dummy#hit_the_switch is controlled by argument switch (ControlParameter)

Note that both smells are reported, Boolean Parameter and Control Parameter.

Getting rid of the smell

This is highly dependent on your exact architecture, but looking at the example above what you could do is:

  • Move everything in the if branch into a separate method
  • Move everything in the else branch into a separate method
  • Get rid of the hit_the_switch method alltogether
  • Make the decision what method to call in the initial caller of hit_the_switch

Tasks::Bosh::CreateRelease#execute has 7 parameters
Open

      def execute(name:, version:, tarball_path:, dir: '.', final: true, force: false, timestamp_version: false)
Severity: Minor
Found in lib/tasks/bosh/create_release.rb by reek

A Long Parameter List occurs when a method has a lot of parameters.

Example

Given

class Dummy
  def long_list(foo,bar,baz,fling,flung)
    puts foo,bar,baz,fling,flung
  end
end

Reek would report the following warning:

test.rb -- 1 warning:
  [2]:Dummy#long_list has 5 parameters (LongParameterList)

A common solution to this problem would be the introduction of parameter objects.

Tasks::Bosh::CreateRelease#execute is controlled by argument 'force'
Open

        force_option = force ? "--force " : ""
Severity: Minor
Found in lib/tasks/bosh/create_release.rb by reek

Control Parameter is a special case of Control Couple

Example

A simple example would be the "quoted" parameter in the following method:

def write(quoted)
  if quoted
    write_quoted @value
  else
    write_unquoted @value
  end
end

Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

Tasks::Bosh::CreateRelease#execute has boolean parameter 'timestamp_version'
Open

      def execute(name:, version:, tarball_path:, dir: '.', final: true, force: false, timestamp_version: false)
Severity: Minor
Found in lib/tasks/bosh/create_release.rb by reek

Boolean Parameter is a special case of Control Couple, where a method parameter is defaulted to true or false. A Boolean Parameter effectively permits a method's caller to decide which execution path to take. This is a case of bad cohesion. You're creating a dependency between methods that is not really necessary, thus increasing coupling.

Example

Given

class Dummy
  def hit_the_switch(switch = true)
    if switch
      puts 'Hitting the switch'
      # do other things...
    else
      puts 'Not hitting the switch'
      # do other things...
    end
  end
end

Reek would emit the following warning:

test.rb -- 3 warnings:
  [1]:Dummy#hit_the_switch has boolean parameter 'switch' (BooleanParameter)
  [2]:Dummy#hit_the_switch is controlled by argument switch (ControlParameter)

Note that both smells are reported, Boolean Parameter and Control Parameter.

Getting rid of the smell

This is highly dependent on your exact architecture, but looking at the example above what you could do is:

  • Move everything in the if branch into a separate method
  • Move everything in the else branch into a separate method
  • Get rid of the hit_the_switch method alltogether
  • Make the decision what method to call in the initial caller of hit_the_switch

Tasks::Bosh::CreateRelease#execute has approx 13 statements
Open

      def execute(name:, version:, tarball_path:, dir: '.', final: true, force: false, timestamp_version: false)
Severity: Minor
Found in lib/tasks/bosh/create_release.rb by reek

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

Tasks::Bosh::CreateRelease#execute has boolean parameter 'force'
Open

      def execute(name:, version:, tarball_path:, dir: '.', final: true, force: false, timestamp_version: false)
Severity: Minor
Found in lib/tasks/bosh/create_release.rb by reek

Boolean Parameter is a special case of Control Couple, where a method parameter is defaulted to true or false. A Boolean Parameter effectively permits a method's caller to decide which execution path to take. This is a case of bad cohesion. You're creating a dependency between methods that is not really necessary, thus increasing coupling.

Example

Given

class Dummy
  def hit_the_switch(switch = true)
    if switch
      puts 'Hitting the switch'
      # do other things...
    else
      puts 'Not hitting the switch'
      # do other things...
    end
  end
end

Reek would emit the following warning:

test.rb -- 3 warnings:
  [1]:Dummy#hit_the_switch has boolean parameter 'switch' (BooleanParameter)
  [2]:Dummy#hit_the_switch is controlled by argument switch (ControlParameter)

Note that both smells are reported, Boolean Parameter and Control Parameter.

Getting rid of the smell

This is highly dependent on your exact architecture, but looking at the example above what you could do is:

  • Move everything in the if branch into a separate method
  • Move everything in the else branch into a separate method
  • Get rid of the hit_the_switch method alltogether
  • Make the decision what method to call in the initial caller of hit_the_switch

Tasks::Bosh::CreateRelease#execute is controlled by argument 'timestamp_version'
Open

        timestamp_option = timestamp_version ? "--timestamp-version " : ""
Severity: Minor
Found in lib/tasks/bosh/create_release.rb by reek

Control Parameter is a special case of Control Couple

Example

A simple example would be the "quoted" parameter in the following method:

def write(quoted)
  if quoted
    write_quoted @value
  else
    write_unquoted @value
  end
end

Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

Tasks::Bosh::CreateRelease#execute is controlled by argument 'final'
Open

        final_option = final ? "--final " : ""
Severity: Minor
Found in lib/tasks/bosh/create_release.rb by reek

Control Parameter is a special case of Control Couple

Example

A simple example would be the "quoted" parameter in the following method:

def write(quoted)
  if quoted
    write_quoted @value
  else
    write_unquoted @value
  end
end

Fixing those problems is out of the scope of this document but an easy solution could be to remove the "write" method alltogether and to move the calls to "writequoted" / "writeunquoted" in the initial caller of "write".

Method execute has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

      def execute(name:, version:, tarball_path:, dir: '.', final: true, force: false, timestamp_version: false)
        raise "Missing required parameter: name:#{name}, version: #{version} or tarball_path: #{tarball_path}" if name.to_s.empty? || version.to_s.empty? || tarball_path.to_s.empty?

        dir_option = "--dir='#{dir}' "
        timestamp_option = timestamp_version ? "--timestamp-version " : ""
Severity: Minor
Found in lib/tasks/bosh/create_release.rb - About 45 mins 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 parameter lists longer than 5 parameters. [7/5]
Open

      def execute(name:, version:, tarball_path:, dir: '.', final: true, force: false, timestamp_version: false)
Severity: Minor
Found in lib/tasks/bosh/create_release.rb by rubocop

This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.

There are no issues that match your filters.

Category
Status