theforeman/foreman_maintain

View on GitHub

Showing 98 of 98 total issues

Method run has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

    def run
      unless @preserve_dir
        puts "Creating backup folder #{@backup_dir}"

        FileUtils.mkdir_p @backup_dir
Severity: Minor
Found in definitions/procedures/backup/prepare_directory.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 tar_command has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def tar_command(options)
    volume_size = options.fetch(:volume_size, nil)
    absolute_names = options.fetch(:absolute_names, nil)
    validate_volume_size(volume_size) unless volume_size.nil?

Severity: Minor
Found in definitions/features/tar.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 ask_to_select has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

      def ask_to_select(message, steps, run_strategy)
        if assumeyes?
          step = steps[@select_option_counter]
          @select_option_counter += 1
          puts("(assuming option #{@select_option_counter})")
Severity: Minor
Found in lib/foreman_maintain/reporter/cli_reporter.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 ask_to_select has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def ask_to_select(message, steps, run_strategy)
      if assumeyes?
        puts('(assuming first option)')
        return steps.first
      end
Severity: Minor
Found in lib/foreman_maintain/reporter.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 tar_command has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def tar_command(options)
    volume_size = options.fetch(:volume_size, nil)
    absolute_names = options.fetch(:absolute_names, nil)
    validate_volume_size(volume_size) unless volume_size.nil?

Severity: Minor
Found in definitions/features/tar.rb - About 1 hr to fix

    Method run has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def run
          backup = ForemanMaintain::Utils::Backup.new(@backup_dir)
          if feature(:instance).postgresql_local? && backup.online_backup?
            errors = []
            [:candlepin_dump, :foreman_dump, :pulpcore_dump].each do |dump|
    Severity: Minor
    Found in definitions/checks/restore/validate_postgresql_dump_permissions.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 compose has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def compose
          backup = ForemanMaintain::Utils::Backup.new(context.get(:backup_dir))
    
          add_steps(find_checks(:root_user))
          add_steps_with_context(Checks::Restore::ValidateBackup,
    Severity: Minor
    Found in definitions/scenarios/restore.rb - About 1 hr to fix

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

        module Foreman
          class DBUp < ForemanMaintain::Check
            metadata do
              description 'Make sure Foreman DB is up'
              label :foreman_db_up
      Severity: Major
      Found in definitions/checks/foreman/db_up.rb and 1 other location - About 1 hr to fix
      definitions/checks/candlepin/db_up.rb on lines 2..28

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

      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

        module Candlepin
          class DBUp < ForemanMaintain::Check
            metadata do
              description 'Make sure Candlepin DB is up'
              label :candlepin_db_up
      Severity: Major
      Found in definitions/checks/candlepin/db_up.rb and 1 other location - About 1 hr to fix
      definitions/checks/foreman/db_up.rb on lines 2..28

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

      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

      Method compose has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def compose
            add_steps(
              Checks::Foreman::FactsNames, # if Foreman database present
              Checks::ForemanProxy::CheckTftpStorage, # if Satellite with foreman-proxy+tftp
              Checks::ForemanProxy::VerifyDhcpConfigSyntax, # if foreman-proxy+dhcp-isc
      Severity: Minor
      Found in definitions/scenarios/update.rb - About 1 hr to fix

        Method compose has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def compose
              add_steps(
                Checks::Foreman::FactsNames, # if Foreman database present
                Checks::ForemanProxy::CheckTftpStorage, # if Satellite with foreman-proxy+tftp
                Checks::ForemanProxy::VerifyDhcpConfigSyntax, # if foreman-proxy+dhcp-isc
        Severity: Minor
        Found in definitions/scenarios/foreman_upgrade.rb - About 1 hr to fix

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

            def include_unregistered_services(service_list, services_filter)
              return service_list unless services_filter
              return service_list unless services_filter.any?
          
              services_filter = services_filter.reject do |obj|
          Severity: Minor
          Found in definitions/features/service.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 setup_protector has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              def setup_protector(enabled)
                config = protector_config
                config += "\n" unless config[-1] == "\n"
                enabled_re = /^\s*enabled\s*=.*$/
                if enabled_re.match(config)
          Severity: Minor
          Found in lib/foreman_maintain/package_manager/dnf.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 run_action_on_services has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def run_action_on_services(action, options, spinner)
              status = 0
              failed_services = []
              filtered_services(options, action).each_value do |group|
                fork_threads_for_services(action, group, spinner).each do |service, status_and_output|
          Severity: Minor
          Found in definitions/features/service.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 status_for_maintenance_mode has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def status_for_maintenance_mode(mode_on)
              default_storage = ForemanMaintain.storage(:default)
              load_from_storage(default_storage)
              return ['sync plans: empty data', []] if both_empty?
          
          
          Severity: Minor
          Found in definitions/features/sync_plans.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 find_http_error_msg has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

            def find_http_error_msg(array_output, curl_http_status)
              if curl_http_status == 0
                'No valid HTTP response (Connection failed)'
              else
                http_line = ''
          Severity: Minor
          Found in definitions/features/foreman_proxy.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

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

                until_valid_decision do
                  actions = (run_strategy == :fail_slow) ? 'n(next)' : 'n(next), q(quit)'
          
                  answer = ask("#{message}, [#{actions}]")
                  if answer =~ /^\d+$/ && (answer.to_i - 1) < steps.size
          Severity: Major
          Found in lib/foreman_maintain/reporter.rb and 1 other location - About 1 hr to fix
          lib/foreman_maintain/reporter/cli_reporter.rb on lines 230..242

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

          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

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

                  until_valid_decision do
                    actions = (run_strategy == :fail_slow) ? 'n(next)' : 'n(next), q(quit)'
                    answer = ask("#{message}, [#{actions}]")
                    if answer =~ /^\d+$/ && (answer.to_i - 1) < steps.size
                      steps[answer.to_i - 1]
          Severity: Major
          Found in lib/foreman_maintain/reporter/cli_reporter.rb and 1 other location - About 1 hr to fix
          lib/foreman_maintain/reporter.rb on lines 115..128

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

          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

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

            def katello_ping
              res = server_connection.get('/katello/api/ping')
              logger.debug('Called /katello/api/ping')
              logger.debug("Response: #{res.code}, #{res.body}")
              response = JSON.parse(res.body)
          Severity: Minor
          Found in definitions/features/instance.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 ask_about_offered_steps has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def ask_about_offered_steps(step, scenario)
                if step.next_steps && !step.next_steps.empty?
                  @last_decision_step = step
                  @procedure_step_counter += 1
                  steps = step.next_steps.map(&:ensure_instance)
          Severity: Minor
          Found in lib/foreman_maintain/runner.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

          Severity
          Category
          Status
          Source
          Language