Katello/katello

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

Summary

Maintainability
F
5 days
Test Coverage

File repository.rb has 840 lines of code (exceeds 250 allowed). Consider refactoring.
Open

module Katello
  # rubocop:disable Metrics/ClassLength
  class Repository < Katello::Model
    audited

Severity: Major
Found in app/models/katello/repository.rb - About 2 days to fix

    Class Repository has 104 methods (exceeds 20 allowed). Consider refactoring.
    Open

      class Repository < Katello::Model
        audited
    
        #pulp uses pulp id to sync with 'yum_distributor' on the end
        PULP_ID_MAX_LENGTH = 220
    Severity: Major
    Found in app/models/katello/repository.rb - About 2 days to fix

      Method build_clone has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def build_clone(options)
            to_env       = options[:environment]
            version      = options[:version]
            content_view = options[:content_view] || to_env.default_content_view
            to_version   = version || content_view.version(to_env)
      Severity: Minor
      Found in app/models/katello/repository.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 build_clone has 30 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def build_clone(options)
            to_env       = options[:environment]
            version      = options[:version]
            content_view = options[:content_view] || to_env.default_content_view
            to_version   = version || content_view.version(to_env)
      Severity: Minor
      Found in app/models/katello/repository.rb - About 1 hr to fix

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

            def self.safe_render_container_name(repository, pattern = nil)
              #            pattern provided / env pattern provided
              #                 |  00 |  01 |  11 |  10
              # ----------------+-----+-----+-----+------
              # env exists /  00|   4 | n/a | n/a |   4
        Severity: Minor
        Found in app/models/katello/repository.rb - About 1 hr to fix

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

              def self.safe_render_container_name(repository, pattern = nil)
                #            pattern provided / env pattern provided
                #                 |  00 |  01 |  11 |  10
                # ----------------+-----+-----+-----+------
                # env exists /  00|   4 | n/a | n/a |   4
          Severity: Minor
          Found in app/models/katello/repository.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 full_path has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def full_path(smart_proxy = nil, force_http = false)
                pulp_uri = URI.parse(smart_proxy ? smart_proxy.url : ::SmartProxy.pulp_primary.url)
                scheme = force_http ? 'http' : 'https'
                if docker?
                  "#{pulp_uri.host.downcase}/#{container_repository_name}"
          Severity: Minor
          Found in app/models/katello/repository.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

          Method target_repository has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def target_repository
                fail _("This is not a linked repository") if primary?
                return nil if self.archived_instance.nil?
          
                #this is an environment repo, and the archived_instance is a primary (not always true with composite)
          Severity: Minor
          Found in app/models/katello/repository.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

          Method destroyable? has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              def destroyable?(remove_from_content_view_versions = false)
                if self.environment.try(:library?) && self.content_view.default?
                  if self.environment.organization.being_deleted?
                    return true
                  elsif self.custom? && self.deletable?(remove_from_content_view_versions)
          Severity: Minor
          Found in app/models/katello/repository.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 true
          Severity: Major
          Found in app/models/katello/repository.rb - About 30 mins to fix

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

                def self.search_by_redhat(_key, operator, value)
                  value = value == 'true'
                  value = !value if operator == '<>'
            
                  product_ids = Katello::Product.redhat.select(:id)
            Severity: Minor
            Found in app/models/katello/repository.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

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

                def exist_for_environment?(environment, content_view, attribute = nil)
                  if environment.present? && content_view.in_environment?(environment)
                    repos = content_view.version(environment).repos(environment)
            
                    repos.any? do |repo|
            Severity: Minor
            Found in app/models/katello/repository.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

                  ::Katello::Erratum.joins(
                    "INNER JOIN #{erratum_package} on #{erratum_package}.erratum_id = #{errata}.id",
                    "INNER JOIN #{repository_errata} on #{repository_errata}.erratum_id = #{errata}.id",
                    "INNER JOIN #{rpm} on #{rpm}.filename = #{erratum_package}.filename",
                    "INNER JOIN #{repository_rpm} on #{repository_rpm}.rpm_id = #{rpm}.id").
            Severity: Major
            Found in app/models/katello/repository.rb and 1 other location - About 1 hr to fix
            app/models/katello/repository.rb on lines 384..391

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

            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

                  ::Katello::Erratum.joins(
                    "INNER JOIN #{erratum_package} on #{erratum_package}.erratum_id = #{errata}.id",
                    "INNER JOIN #{msep} on #{msep}.erratum_package_id = #{erratum_package}.id",
                    "INNER JOIN #{repository_errata} on #{repository_errata}.erratum_id = #{errata}.id",
                    "INNER JOIN #{repository_module_stream} on #{repository_module_stream}.module_stream_id = #{msep}.module_stream_id").
            Severity: Major
            Found in app/models/katello/repository.rb and 1 other location - About 1 hr to fix
            app/models/katello/repository.rb on lines 368..375

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

            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 check_ready_to_act!
                  blocking_tasks = content_views&.map { |cv| cv.blocking_task }&.compact
            
                  if blocking_tasks&.any?
                    errored_tasks = blocking_tasks
            Severity: Minor
            Found in app/models/katello/repository.rb and 1 other location - About 40 mins to fix
            app/models/katello/content_view.rb on lines 646..652

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

            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

                apipie :class, desc: "A class representing #{model_name.human} object" do
                  name 'Repository'
                  refs 'Repository'
                  sections only: %w[all additional]
                  prop_group :katello_basic_props, Katello::Model, meta: { friendly_name: 'Repository' }
            Severity: Minor
            Found in app/models/katello/repository.rb and 1 other location - About 35 mins to fix
            app/models/katello/content_view_version.rb on lines 477..483

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

            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

                  if product_ids.empty?
                    {:conditions => "1=0"}
                  else
                    operator = value ? 'IN' : 'NOT IN'
                    {:conditions => "#{Katello::Repository.table_name}.root_id #{operator} (#{root_ids.join(',')})"}
            Severity: Minor
            Found in app/models/katello/repository.rb and 1 other location - About 20 mins to fix
            app/models/katello/sync_plan.rb on lines 42..46

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

            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