Katello/katello

View on GitHub
app/models/katello/task_status.rb

Summary

Maintainability
D
2 days
Test Coverage

Method pending_message has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

    def pending_message
      # Retrieve a text message that may be rendered for a 'pending' task's status.  This is used in various places,
      # such as System Event history.
      details = TaskStatus::TYPES[self.task_type]
      case details[:type]
Severity: Minor
Found in app/models/katello/task_status.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

File task_status.rb has 255 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Katello
  class TaskStatus < Katello::Model
    include Util::TaskStatus

    serialize :result
Severity: Minor
Found in app/models/katello/task_status.rb - About 2 hrs to fix

    Method rmi_error_description has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def rmi_error_description
          errors, stacktrace = self.result[:errors]
          return "" unless errors
          # Handle not very friendly Pulp message
          if errors =~ /^\(.*\)$/
    Severity: Minor
    Found in app/models/katello/task_status.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 message has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def message
          # Retrieve a text message that may be rendered for a task's status.  This is used in various places,
          # such as System Event history.
          details = TaskStatus::TYPES[self.task_type]
          return _("Non-system event") if details.nil?
    Severity: Minor
    Found in app/models/katello/task_status.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 message has 33 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def message
          # Retrieve a text message that may be rendered for a task's status.  This is used in various places,
          # such as System Event history.
          details = TaskStatus::TYPES[self.task_type]
          return _("Non-system event") if details.nil?
    Severity: Minor
    Found in app/models/katello/task_status.rb - About 1 hr to fix

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

          def pending_message
            # Retrieve a text message that may be rendered for a 'pending' task's status.  This is used in various places,
            # such as System Event history.
            details = TaskStatus::TYPES[self.task_type]
            case details[:type]
      Severity: Minor
      Found in app/models/katello/task_status.rb - About 1 hr to fix

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

            def packages_change_description(data, action)
              ret = []
        
              data ||= {}
              data[:details] ||= {}
        Severity: Minor
        Found in app/models/katello/task_status.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 overall_status has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def overall_status
              # the overall status of tasks (e.g. associated with a system) are determined by a
              # combination of the task state and the status of the unit within the task.
              unit_status = true
              if (self.result.is_a? Hash) && (self.result.key? :details)
        Severity: Minor
        Found in app/models/katello/task_status.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 generate_description has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

            def generate_description
              ret = []
              task_type = self.task_type.to_s
        
              if task_type =~ /^package_group/
        Severity: Minor
        Found in app/models/katello/task_status.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 humanize_parameters has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def humanize_parameters
              humanized_parameters = []
              if (packages = self.parameters[:packages])
                humanized_parameters.concat(packages)
              end
        Severity: Minor
        Found in app/models/katello/task_status.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

        Avoid too many return statements within this method.
        Open

                      return _("all packages update")
        Severity: Major
        Found in app/models/katello/task_status.rb - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                  return n_(msg[1], msg[2], p.length) % { group: p.first, total: p.length - 1 }
          Severity: Major
          Found in app/models/katello/task_status.rb - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                      return p.first
            Severity: Major
            Found in app/models/katello/task_status.rb - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return n_(msg[1], msg[2], p.length) % { errata: p.first, total: p.length - 1 }
              Severity: Major
              Found in app/models/katello/task_status.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return self.result
                Severity: Major
                Found in app/models/katello/task_status.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                            return p.first
                  Severity: Major
                  Found in app/models/katello/task_status.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                              return _("%{group} (%{total} other package groups)") % {:group => p.first, :total => p.length - 1}
                    Severity: Major
                    Found in app/models/katello/task_status.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                              return n_(msg[1], msg[2], p.length) % { package: first_package, total: p.length - 1 }
                      Severity: Major
                      Found in app/models/katello/task_status.rb - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                  return _("%{errata} (%{total} other errata)") % {:errata => p.first, :total => p.length - 1}
                        Severity: Major
                        Found in app/models/katello/task_status.rb - About 30 mins to fix

                          Method initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              def initialize(attrs = nil, _options = {})
                                unless attrs.nil?
                                  # only keep keys for which we have db columns
                                  attrs = attrs.reject do |k, _v|
                                    !self.class.column_defaults.keys.member?(k.to_s) && (!respond_to?(:"#{k.to_s}=") rescue true)
                          Severity: Minor
                          Found in app/models/katello/task_status.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 2 locations. Consider refactoring.
                          Open

                                when :package_group
                                  p = self.parameters[:groups]
                                  msg = details[:event_messages][self.overall_status]
                                  return n_(msg[1], msg[2], p.length) % { group: p.first, total: p.length - 1 }
                          Severity: Minor
                          Found in app/models/katello/task_status.rb and 1 other location - About 35 mins to fix
                          app/models/katello/task_status.rb on lines 180..183

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

                          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

                                when :errata
                                  p = self.parameters[:errata_ids]
                                  msg = details[:event_messages][self.overall_status]
                                  return n_(msg[1], msg[2], p.length) % { errata: p.first, total: p.length - 1 }
                          Severity: Minor
                          Found in app/models/katello/task_status.rb and 1 other location - About 35 mins to fix
                          app/models/katello/task_status.rb on lines 176..179

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

                          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

                                when :errata
                                  p = self.parameters[:errata_ids]
                                  if p.length == 1
                                    return p.first
                                  else
                          Severity: Minor
                          Found in app/models/katello/task_status.rb and 1 other location - About 25 mins to fix
                          app/models/katello/task_status.rb on lines 128..133

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

                          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

                                when :package_group
                                  p = self.parameters[:groups]
                                  if p.length == 1
                                    return p.first
                                  else
                          Severity: Minor
                          Found in app/models/katello/task_status.rb and 1 other location - About 25 mins to fix
                          app/models/katello/task_status.rb on lines 135..140

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

                          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