theforeman/foreman

View on GitHub
app/services/puppet_fact_parser.rb

Summary

Maintainability
D
1 day
Test Coverage

Class PuppetFactParser has 35 methods (exceeds 20 allowed). Consider refactoring.
Open

class PuppetFactParser < FactParser
  attr_reader :facts

  def operatingsystem
    orel = os_release.dup
Severity: Minor
Found in app/services/puppet_fact_parser.rb - About 4 hrs to fix

    File puppet_fact_parser.rb has 262 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class PuppetFactParser < FactParser
      attr_reader :facts
    
      def operatingsystem
        orel = os_release.dup
    Severity: Minor
    Found in app/services/puppet_fact_parser.rb - About 2 hrs to fix

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

        def operatingsystem
          orel = os_release.dup
      
          if orel.present?
            major, minor = orel.split('.', 2)
      Severity: Minor
      Found in app/services/puppet_fact_parser.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 os_release has 33 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def os_release
          case os_name
          when /(windows)/i
            facts[:kernelrelease]
          when /AIX/i
      Severity: Minor
      Found in app/services/puppet_fact_parser.rb - About 1 hr to fix

        Method operatingsystem has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def operatingsystem
            orel = os_release.dup
        
            if orel.present?
              major, minor = orel.split('.', 2)
        Severity: Minor
        Found in app/services/puppet_fact_parser.rb - About 1 hr to fix

          Method os_name has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def os_name
              # Facter 2.2 introduced the os fact
              os_name = facts.dig(:os, :name).presence || facts[:operatingsystem].presence || raise(::Foreman::Exception.new("invalid facts, missing operating system value"))
              # CentOS Stream doesn't have a minor version so it's good to check it at two places according to version of Facter that produced facts
              has_no_minor = facts[:lsbdistrelease]&.exclude?('.') || (facts.dig(:os, :name).presence && facts.dig(:os, :release, :minor).nil?)
          Severity: Minor
          Found in app/services/puppet_fact_parser.rb - About 1 hr 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 interfaces has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

            def interfaces
              interfaces = super
              return interfaces unless use_legacy_facts?
              underscore_device_regexp = /\A([^_]*)_(\d+)\z/
              interfaces.clone.each do |identifier, _|
          Severity: Minor
          Found in app/services/puppet_fact_parser.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 3 locations. Consider refactoring.
          Open

            def distro_description
              # Facter 3.0 introduced the os.distro fact
              facts.dig(:os, :distro, :description).presence || facts[:lsbdistdescription].presence
            rescue StandardError => e
              logger.warning { "Failed to read the distribution description: #{e}" }
          Severity: Minor
          Found in app/services/puppet_fact_parser.rb and 2 other locations - About 15 mins to fix
          app/services/puppet_fact_parser.rb on lines 278..284
          app/services/puppet_fact_parser.rb on lines 288..294

          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 3 locations. Consider refactoring.
          Open

            def distro_id
              # Facter 3.0 introduced the os.distro fact
              facts.dig(:os, :distro, :id).presence || facts[:lsbdistid].presence
            rescue StandardError => e
              logger.warning { "Failed to the read distribution id: #{e}" }
          Severity: Minor
          Found in app/services/puppet_fact_parser.rb and 2 other locations - About 15 mins to fix
          app/services/puppet_fact_parser.rb on lines 288..294
          app/services/puppet_fact_parser.rb on lines 298..304

          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 3 locations. Consider refactoring.
          Open

            def distro_codename
              # Facter 3.0 introduced the os.distro fact
              facts.dig(:os, :distro, :codename).presence || facts[:lsbdistcodename].presence
            rescue StandardError => e
              logger.warning { "Failed to read the distribution codename: #{e}" }
          Severity: Minor
          Found in app/services/puppet_fact_parser.rb and 2 other locations - About 15 mins to fix
          app/services/puppet_fact_parser.rb on lines 278..284
          app/services/puppet_fact_parser.rb on lines 298..304

          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

            def architecture_fact
              # Facter 3.0 introduced the os.architecture fact
              facts.dig(:os, :architecture).presence || facts[:architecture].presence
            rescue StandardError => e
              logger.error { "Failed to read the architecture: #{e}" }
          Severity: Minor
          Found in app/services/puppet_fact_parser.rb and 1 other location - About 15 mins to fix
          app/services/puppet_fact_parser.rb on lines 334..340

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

          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

            def hardware_isa
              # Facter 3.0 introduced the processors.isa fact
              facts.dig(:processors, :isa).presence || facts[:hardwareisa].presence
            rescue StandardError => e
              logger.error { "Failed to read the hardware ISA: #{e}" }
          Severity: Minor
          Found in app/services/puppet_fact_parser.rb and 1 other location - About 15 mins to fix
          app/services/puppet_fact_parser.rb on lines 325..331

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

          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

            def dmi_board_product
              # Facter 3.0 introduced the dmi fact
              facts.dig(:dmi, :board, :product).presence || facts[:boardproductname]
            rescue StandardError => e
              logger.warning { "Failed to read the board product: #{e}" }
          Severity: Minor
          Found in app/services/puppet_fact_parser.rb and 1 other location - About 15 mins to fix
          app/services/puppet_fact_parser.rb on lines 307..313

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

          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

            def dmi_product_name
              # Facter 3.0 introduced the dmi fact
              facts.dig(:dmi, :product, :name).presence || facts[:productname]
            rescue StandardError => e
              logger.warning { "Failed to read the product name: #{e}" }
          Severity: Minor
          Found in app/services/puppet_fact_parser.rb and 1 other location - About 15 mins to fix
          app/services/puppet_fact_parser.rb on lines 316..322

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

          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

          There are no issues that match your filters.

          Category
          Status