theforeman/foreman

View on GitHub
app/models/setting.rb

Summary

Maintainability
C
1 day
Test Coverage

Class Setting has 30 methods (exceeds 20 allowed). Consider refactoring.
Open

class Setting < ApplicationRecord
  audited :except => [:name]
  extend FriendlyId
  friendly_id :name
  include ActiveModel::Validations
Severity: Minor
Found in app/models/setting.rb - About 3 hrs to fix

    Method parse_string_value has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

      def parse_string_value(val)
        case settings_type
        when "boolean"
          boolean = Foreman::Cast.to_bool(val)
    
    
    Severity: Minor
    Found in app/models/setting.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 parse_string_value has 35 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def parse_string_value(val)
        case settings_type
        when "boolean"
          boolean = Foreman::Cast.to_bool(val)
    
    
    Severity: Minor
    Found in app/models/setting.rb - About 1 hr to fix

      Method value= has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

        def value=(v)
          v = v.to_yaml unless v.nil?
          # the has_attribute is for enabling DB migrations on older versions
          if setting_definition&.encrypted?
            # Don't re-write the attribute if the current encrypted value is identical to the new one
      Severity: Minor
      Found in app/models/setting.rb - About 45 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 set has 6 arguments (exceeds 4 allowed). Consider refactoring.
      Open

        def self.set(name, description, default, full_name = nil, value = nil, options = {})
      Severity: Minor
      Found in app/models/setting.rb - About 45 mins to fix

        There are no issues that match your filters.

        Category
        Status