orange-cloudfoundry/cf-ops-automation

View on GitHub
upgrade/v3.2.0/01-upgrade-config.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Assignment Branch Condition size for insert_pipeline_config is too high. [46.27/15]
Open

def insert_pipeline_config(ci_deployment_overview)
  migrated = false
  ci_deployment_overview['ci-deployment']&.each do |_, details|
    additional_pipelines = {}
    details['pipelines']&.select { |name, _| name.end_with?('-init-generated') }
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.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

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

def insert_pipeline_config(ci_deployment_overview)
  migrated = false
  ci_deployment_overview['ci-deployment']&.each do |_, details|
    additional_pipelines = {}
    details['pipelines']&.select { |name, _| name.end_with?('-init-generated') }
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by rubocop

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

def insert_new_pipeline_configuration(ci_deployment_overview_files)
  migrated_counter = 0
  ci_deployment_overview_files&.each do |ci_deployment_filename|
    ci_deployment = YAML.load_file(ci_deployment_filename)
    unless ci_deployment
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by rubocop

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

def insert_pipeline_config(ci_deployment_overview)
  migrated = false
  ci_deployment_overview['ci-deployment']&.each do |_, details|
    additional_pipelines = {}
    details['pipelines']&.select { |name, _| name.end_with?('-init-generated') }
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.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

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

def process_credentials_files(target_dir, credentials_files)
  migrated_counter = 0
  credentials_files.each do |file|
    target_file = File.join(target_dir, File.basename(file))
    if File.exist?(target_file)
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by rubocop

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

def create_coa_config_readme(coa_config_dir)
  readme_filename = "Readme.md"
  readme_file = File.join(coa_config_dir, readme_filename)
  return if File.exist?(readme_file)

Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by rubocop

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

def insert_pipeline_config(ci_deployment_overview)
  migrated = false
  ci_deployment_overview['ci-deployment']&.each do |_, details|
    additional_pipelines = {}
    details['pipelines']&.select { |name, _| name.end_with?('-init-generated') }
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb - About 1 hr to fix

insert_new_pipeline_configuration has approx 12 statements
Open

def insert_new_pipeline_configuration(ci_deployment_overview_files)
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.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.)

insert_pipeline_config has approx 37 statements
Open

def insert_pipeline_config(ci_deployment_overview)
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.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.)

insert_pipeline_config contains iterators nested 3 deep
Open

        next unless details['pipelines']&.select { |name, _| name.end_with?('depls-update-generated') }.empty?

        puts "\t>> INFO: checking #{name} configuration"
        pipeline_config = old_pipeline_config.dup
        update_pipeline_name = name.gsub(/(([a-z]|[A-Z]|[0-9])+)-depls-init-generated/, '\1-depls-update-generated')
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by reek

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)

insert_pipeline_config refers to 'pipeline_config' more than self (maybe move it to another class?)
Open

        vars_files = pipeline_config['vars_files'].map { |path| File.join(COA_CONFIG_DIR, File.basename(path)) }
        vars_files.insert(-1, File.join(COA_CONFIG_DIR, SLACK_CONFIG_FILENAME))
        pipeline_config['vars_files'] = vars_files
        pipeline_config.delete_if { |key, _| key == 'config_file' }
        additional_pipelines[update_pipeline_name] = pipeline_config
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by reek

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.

insert_pipeline_config refers to 'name' more than self (maybe move it to another class?)
Open

    details['pipelines']&.select { |name, _| name.end_with?('-init-generated') }
      &.each do |name, old_pipeline_config|
        next unless details['pipelines']&.select { |name, _| name.end_with?('depls-update-generated') }.empty?

        puts "\t>> INFO: checking #{name} configuration"
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by reek

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.

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

  ci_deployment_overview['ci-deployment']&.each do |_, details|
    additional_pipelines = {}
    details['pipelines']&.select { |name, _| name.end_with?('-init-generated') }
      &.each do |name, old_pipeline_config|
        next unless details['pipelines']&.select { |name, _| name.end_with?('depls-update-generated') }.empty?
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by rubocop

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.

Method insert_new_pipeline_configuration has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

def insert_new_pipeline_configuration(ci_deployment_overview_files)
  migrated_counter = 0
  ci_deployment_overview_files&.each do |ci_deployment_filename|
    ci_deployment = YAML.load_file(ci_deployment_filename)
    unless ci_deployment
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb - About 35 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

insert_pipeline_config calls 'details['pipelines']' 5 times
Open

    details['pipelines']&.select { |name, _| name.end_with?('-init-generated') }
      &.each do |name, old_pipeline_config|
        next unless details['pipelines']&.select { |name, _| name.end_with?('depls-update-generated') }.empty?

        puts "\t>> INFO: checking #{name} configuration"
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by reek

Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

Reek implements a check for Duplicate Method Call.

Example

Here's a very much simplified and contrived example. The following method will report a warning:

def double_thing()
  @other.thing + @other.thing
end

One quick approach to silence Reek would be to refactor the code thus:

def double_thing()
  thing = @other.thing
  thing + thing
end

A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

class Other
  def double_thing()
    thing + thing
  end
end

The approach you take will depend on balancing other factors in your code.

select_credentials_files doesn't depend on instance state (maybe move it to another class?)
Open

def select_credentials_files(credentials_files)
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by reek

A Utility Function is any instance method that has no dependency on the state of the instance.

Shadowing outer local variable - name.
Open

        next unless details['pipelines']&.select { |name, _| name.end_with?('depls-update-generated') }.empty?
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by rubocop

This cop looks for use of the same name as outer local variables for block arguments or block local variables. This is a mimic of the warning "shadowing outer local variable - foo" from ruby -cw.

Example:

# bad

def some_method
  foo = 1

  2.times do |foo| # shadowing outer `foo`
    do_something(foo)
  end
end

Example:

# good

def some_method
  foo = 1

  2.times do |bar|
    do_something(bar)
  end
end

Shadowing outer local variable - name.
Open

      next unless details['pipelines']&.select { |name, _| name.end_with?('depls-bosh-generated') }.empty?
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by rubocop

This cop looks for use of the same name as outer local variables for block arguments or block local variables. This is a mimic of the warning "shadowing outer local variable - foo" from ruby -cw.

Example:

# bad

def some_method
  foo = 1

  2.times do |foo| # shadowing outer `foo`
    do_something(foo)
  end
end

Example:

# good

def some_method
  foo = 1

  2.times do |bar|
    do_something(bar)
  end
end

Do not use semicolons to terminate expressions.
Open

    .map { |filepath| puts "\t>> DEBUG: deleting #{filepath}"; FileUtils.rm(filepath) }
Severity: Minor
Found in upgrade/v3.2.0/01-upgrade-config.rb by rubocop

This cop checks for multiple expressions placed on the same line. It also checks for lines terminated with a semicolon.

Example:

# bad
foo = 1; bar = 2;
baz = 3;

# good
foo = 1
bar = 2
baz = 3

There are no issues that match your filters.

Category
Status