theforeman/foreman

View on GitHub
app/models/provisioning_template.rb

Summary

Maintainability
C
1 day
Test Coverage

Class ProvisioningTemplate has 25 methods (exceeds 20 allowed). Consider refactoring.
Open

class ProvisioningTemplate < Template
  audited
  has_many :audits, :as => :auditable, :class_name => Audited.audit_class.name

  include Authorizable
Severity: Minor
Found in app/models/provisioning_template.rb - About 2 hrs to fix

    Method build_pxe_default has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.build_pxe_default
        return [:unprocessable_entity, _("No TFTP proxies defined, can't continue")] if (proxies = SmartProxy.with_features("TFTP")).empty?
        error_msgs = []
        used_templates = []
        TemplateKind::PXE.each do |kind|
    Severity: Minor
    Found in app/models/provisioning_template.rb - About 2 hrs 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 build_pxe_default has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def self.build_pxe_default
        return [:unprocessable_entity, _("No TFTP proxies defined, can't continue")] if (proxies = SmartProxy.with_features("TFTP")).empty?
        error_msgs = []
        used_templates = []
        TemplateKind::PXE.each do |kind|
    Severity: Minor
    Found in app/models/provisioning_template.rb - About 1 hr to fix

      Method pxe_default_combos has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.pxe_default_combos
          combos = []
          ProvisioningTemplate.joins(:template_kind).where("template_kinds.name" => "provision").includes(:template_combinations => [{:hostgroup => [:operatingsystem, :architecture]}]).find_each do |template|
            template.template_combinations.each do |combination|
              hostgroup = combination.hostgroup
      Severity: Minor
      Found in app/models/provisioning_template.rb - About 55 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 find_template has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.find_template(opts = {})
          raise ::Foreman::Exception.new(N_("Must provide template kind")) unless opts[:kind]
          raise ::Foreman::Exception.new(N_("Must provide an operating system")) unless opts[:operatingsystem_id]
      
          # first filter valid templates to our OS and requested template kind.
      Severity: Minor
      Found in app/models/provisioning_template.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

      There are no issues that match your filters.

      Category
      Status