sul-dlss/moab-versioning

View on GitHub

Showing 30 of 32 total issues

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

    def array_to_hash(array, summary = false)
      item_hash = {}
      array.each_index do |index|
        item = array[index]
        ikey = item.respond_to?(:key) && item.key ? item.key : index
Severity: Minor
Found in lib/serializer/serializable.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

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

    def version_additions(version_inventory)
      version_additions = FileInventory.new(type: 'additions')
      version_additions.copy_ids(version_inventory)
      version_inventory.groups.each do |group|
        group_addtions = FileGroup.new(group_id: group.group_id)
Severity: Minor
Found in lib/moab/signature_catalog.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

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

    def signatures_from_bagit_manifests(bag_pathname)
      manifest_pathname = {}
      DEFAULT_CHECKSUM_TYPES.each do |type|
        manifest_pathname[type] = bag_pathname.join("manifest-#{type}.txt")
      end
Severity: Minor
Found in lib/moab/file_inventory.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

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

    def verify_version_inventory
      result = VerificationResult.new('version_inventory')
      version_inventory = file_inventory('version')
      result.subentities << VerificationResult.verify_value('inventory_key', composite_key, version_inventory.composite_key)
      signature_catalog = self.signature_catalog
Severity: Minor
Found in lib/moab/storage_object_version.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

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

    def key_name
      unless defined?(@key_name)
        @key_name = nil
        self.class.attributes.each do |attribute|
          if attribute.options[:key]
Severity: Minor
Found in lib/serializer/serializable.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

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

    def check_required_manifest_files(dir, version)
      return [result_hash(NO_FILES_IN_MANIFEST_DIR, version)] unless contains_file?(File.join(dir, MANIFESTS_DIR))

      errors = []
      errors << result_hash(NO_MANIFEST_INVENTORY, version) unless File.exist?(File.join(dir, MANIFEST_INVENTORY_PATH))
Severity: Minor
Found in lib/moab/storage_object_validator.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

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

    def reconstuct_group(group_id, storage_object_dir)
      group = bag_inventory.group(group_id)
      return nil? if group.nil? || group.files.empty?

      target_dir = bag_pathname.join('data', group_id)
Severity: Minor
Found in lib/moab/bagger.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

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

    def data_source
      data_source = (groups.collect { |g| g.data_source.to_s }).join('|')
      if data_source.start_with?('contentMetadata')
        version_id ? "v#{version_id}-#{data_source}" : "new-#{data_source}"
      else
Severity: Minor
Found in lib/moab/file_inventory.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

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

        storage_roots.each do |root|
          root_trunk = root.join(deposit_trunk)
          raise(MoabRuntimeError, "Deposit area not found at #{root_trunk}") unless root_trunk.exist?

          root_trunk_branch = root_trunk.join(branch)
Severity: Minor
Found in lib/moab/storage_repository.rb and 1 other location - About 15 mins to fix
lib/moab/storage_repository.rb on lines 78..83

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

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

      storage_roots.each do |root|
        root_trunk = root.join(storage_trunk)
        raise(MoabRuntimeError, "Storage area not found at #{root_trunk}") unless root_trunk.exist?

        root_trunk_branch = root_trunk.join(branch)
Severity: Minor
Found in lib/moab/storage_repository.rb and 1 other location - About 15 mins to fix
lib/moab/storage_repository.rb on lines 88..93

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

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

Severity
Category
Status
Source
Language