crowbar/crowbar-core

View on GitHub
crowbar_framework/app/models/api/backup.rb

Summary

Maintainability
B
4 hrs
Test Coverage

Class Backup has 22 methods (exceeds 20 allowed). Consider refactoring.
Open

class Api::Backup < ActiveRecord::Base
  belongs_to :crowbar

  attr_accessor :file

Severity: Minor
Found in crowbar_framework/app/models/api/backup.rb - About 2 hrs to fix

Method save_archive has 30 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def save_archive
    if file.nil?
      errors.add_on_blank :file
      return false
    end
Severity: Minor
Found in crowbar_framework/app/models/api/backup.rb - About 1 hr to fix

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

  def restore(options = {})
    background = options.fetch(:background, false)
    from_upgrade = options.fetch(:from_upgrade, false)

    if Crowbar::Backup::Restore.restore_steps_path.exist?
Severity: Minor
Found in crowbar_framework/app/models/api/backup.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 save_archive has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def save_archive
    if file.nil?
      errors.add_on_blank :file
      return false
    end
Severity: Minor
Found in crowbar_framework/app/models/api/backup.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 validate_chef_file_extension has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_chef_file_extension
    Dir.glob(data.join("knife", "**", "*")).each do |file|
      next if Pathname.new(file).directory?
      next if File.extname(file) == ".json"
      errors.add(:base, I18n.t("backups.validation.non_json_file"))
Severity: Minor
Found in crowbar_framework/app/models/api/backup.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

There are no issues that match your filters.

Category
Status