orange-cloudfoundry/cf-ops-automation

View on GitHub
concourse/tasks/resolve_manifest_versions/resolve_manifest_versions.rb

Summary

Maintainability
A
25 mins
Test Coverage
A
100%

Method process_releases_versions has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def process_releases_versions(resolved_manifest, versions)
    resolved_manifest['releases']&.each do |release|
      name, version = extract_release_manifest_info(release)
      lock_version, release_versions_details = extract_expected_info(name, versions)
      puts "WARNING: inconsistent versions detected. Release: #{name} - Manifest version: #{version} - COA expected version: #{lock_version}. Using COA version." if version != 'latest' && lock_version && version != lock_version
Severity: Minor
Found in concourse/tasks/resolve_manifest_versions/resolve_manifest_versions.rb - About 25 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

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

  def extract_release_manifest_info(release)

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

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

  def extract_stemcell_manifest_info(stemcell)

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

ResolveManifestVersions takes parameters ['stemcell_name', 'versions'] to 4 methods
Open

  def process(versions, stemcell_name)
    resolved_manifest = @manifest.dup
    process_releases_versions(resolved_manifest, versions)
    process_stemcells_version(resolved_manifest, stemcell_name, versions)

In general, a Data Clump occurs when the same two or three items frequently appear together in classes and parameter lists, or when a group of instance variable names start or end with similar substrings.

The recurrence of the items often means there is duplicate code spread around to handle them. There may be an abstraction missing from the code, making the system harder to understand.

Example

Given

class Dummy
  def x(y1,y2); end
  def y(y1,y2); end
  def z(y1,y2); end
end

Reek would emit the following warning:

test.rb -- 1 warning:
  [2, 3, 4]:Dummy takes parameters [y1, y2] to 3 methods (DataClump)

A possible way to fix this problem (quoting from Martin Fowler):

The first step is to replace data clumps with objects and use the objects whenever you see them. An immediate benefit is that you'll shrink some parameter lists. The interesting stuff happens as you begin to look for behavior to move into the new objects.

There are no issues that match your filters.

Category
Status