Class Repository
has 69 methods (exceeds 20 allowed). Consider refactoring. Open
class Repository
include Katello::Util::HttpProxy
include Katello::Pulp3::ServiceCommon
attr_accessor :repo
attr_accessor :smart_proxy
File repository.rb
has 475 lines of code (exceeds 250 allowed). Consider refactoring. Open
require "pulpcore_client"
module Katello
module Pulp3
class Repository
include Katello::Util::HttpProxy
Method delete_version
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def delete_version
ignore_404_exception { api.repository_versions_api.delete(repo.version_href) } unless version_zero?
rescue api.api_exception_class => e
if e.message.include?("are currently being used to distribute content")
Rails.logger.warn "Exception when calling repository_versions_api->delete: #{e}"
- Read upRead up
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 refresh_distributions
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def refresh_distributions
if repo.docker?
dist = lookup_distributions(base_path: repo.container_repository_name).first
else
dist = lookup_distributions(base_path: repo.relative_path).first
- Read upRead up
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 refresh_distributions
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
def refresh_distributions
if repo.docker?
dist = lookup_distributions(base_path: repo.container_repository_name).first
else
dist = lookup_distributions(base_path: repo.relative_path).first
Method add_content
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def add_content(content_unit_href, remove_all_units = false)
content_unit_href = [content_unit_href] unless content_unit_href.is_a?(Array)
if remove_all_units
api.repositories_api.modify(repository_reference.repository_href, remove_content_units: ['*'])
api.repositories_api.modify(repository_reference.repository_href, add_content_units: content_unit_href)
- Read upRead up
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 ssl_remote_options
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def ssl_remote_options
options = {}
if root.redhat? && root.cdn_configuration.redhat_cdn?
options = {
client_cert: root.product.certificate,
Method save_distribution_references
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def save_distribution_references(hrefs)
hrefs.each do |href|
pulp3_distribution_data = api.get_distribution(href)
path, content_guard_href = pulp3_distribution_data&.base_path, pulp3_distribution_data&.content_guard
if distribution_reference
- Read upRead up
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 add_content_for_repo
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def add_content_for_repo(repository_href, content_unit_href)
content_unit_href = [content_unit_href] unless content_unit_href.is_a?(Array)
api.repositories_api.modify(repository_href, add_content_units: content_unit_href)
rescue api.client_module::ApiError => e
if e.message.include? 'Could not find the following content units'
- Read upRead up
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 common_remote_options
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def common_remote_options
remote_options = {
tls_validation: root.verify_ssl_on_sync,
name: generate_backend_object_name,
url: root.url,
- Read upRead up
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 remote_partial_update
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def remote_partial_update
url_type = remote_options[:url]&.start_with?('uln') ? 'uln' : 'default'
remote_type = repo.remote_href.start_with?('/pulp/api/v3/remotes/rpm/uln/') ? 'uln' : 'default'
href = repo.remote_href
- Read upRead up
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 ssl_remote_options
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def ssl_remote_options
options = {}
if root.redhat? && root.cdn_configuration.redhat_cdn?
options = {
client_cert: root.product.certificate,
- Read upRead up
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
rescue api.client_module::ApiError => e
if e.message.include? 'Could not find the following content units'
raise ::Katello::Errors::Pulp3Error, "Content units that do not exist in Pulp were requested to be copied."\
" Please run `foreman-rake katello:delete_orphaned_content` to fix the following repository:"\
" #{repository_reference.root_repository.name}. Original error: #{e.message}"
- Read upRead up
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 27.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
def delete_remote(options = {})
options[:href] ||= repo.remote_href
ignore_404_exception { api.get_remotes_api(href: options[:href]).delete(options[:href]) } if options[:href]
- Read upRead up
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 27.
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
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76