Method create_branch_packages
has a Cognitive Complexity of 67 (exceeds 8 allowed). Consider refactoring. Open
def create_branch_packages(tprj)
# collect also the needed repositories here
response = nil
@packages.each do |p|
raise CanNotBranchPackage, "project is developed at #{p[:link_target_project].scmsync}. Fork it instead." if p[:link_target_project].try(:scmsync).present?
- 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 determine_details_about_package_to_branch
has a Cognitive Complexity of 51 (exceeds 8 allowed). Consider refactoring. Open
def determine_details_about_package_to_branch(p)
return unless p[:link_target_project].is_a?(Project) # only for local source projects
check_for_update_project(p) unless params[:ignoredevel]
- 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 find_packages_to_branch
has a Cognitive Complexity of 39 (exceeds 8 allowed). Consider refactoring. Open
def find_packages_to_branch
@packages = []
if params[:request]
# find packages from request
req = BsRequest.find_by_number(params[:request])
- 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 create_branch_packages
has 67 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create_branch_packages(tprj)
# collect also the needed repositories here
response = nil
@packages.each do |p|
raise CanNotBranchPackage, "project is developed at #{p[:link_target_project].scmsync}. Fork it instead." if p[:link_target_project].try(:scmsync).present?
Method find_packages_to_branch
has 64 lines of code (exceeds 25 allowed). Consider refactoring. Open
def find_packages_to_branch
@packages = []
if params[:request]
# find packages from request
req = BsRequest.find_by_number(params[:request])
Method extend_packages_to_link
has a Cognitive Complexity of 18 (exceeds 8 allowed). Consider refactoring. Open
def extend_packages_to_link(p)
return unless p[:package].is_a?(Package) # only for local packages
pkg = p[:package]
if pkg.is_link?
- 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 create_branch_project
has a Cognitive Complexity of 18 (exceeds 8 allowed). Consider refactoring. Open
def create_branch_project
if Project.exists_by_name(@target_project)
raise CreateProjectNoPermission, "The destination project already exists, so the api can't make it not readable" if @noaccess
tprj = Project.get_by_name(@target_project)
- 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 determine_details_about_package_to_branch
has 47 lines of code (exceeds 25 allowed). Consider refactoring. Open
def determine_details_about_package_to_branch(p)
return unless p[:link_target_project].is_a?(Project) # only for local source projects
check_for_update_project(p) unless params[:ignoredevel]
Method extend_packages_to_link
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def extend_packages_to_link(p)
return unless p[:package].is_a?(Package) # only for local packages
pkg = p[:package]
if pkg.is_link?
Avoid deeply nested control flow statements. Confirmed
p[:target_package] += ".#{p[:link_target_project].name}" if @extend_names
Avoid deeply nested control flow statements. Confirmed
p[:link_target_project] = p[:package].project unless params[:newinstance]
Avoid deeply nested control flow statements. Confirmed
ltprj = pkg2.project if ltprj.find_attribute('OBS', 'BranchTarget').nil?
Avoid deeply nested control flow statements. Confirmed
raise NotMissingError, "Branch call with missingok parameter but branched source (#{params[:project]}/#{params[:package]}) exists." if Package.exists_by_project_and_name(params[:project], params[:package],
allow_remote_packages: true)
Avoid deeply nested control flow statements. Open
if prj.is_a?(Project) && prj.find_attribute('OBS', 'BranchTarget')
@copy_from_devel = true
elsif pkg
prj = pkg.project
tpkg_name ||= pkg.releasename
Avoid deeply nested control flow statements. Confirmed
p[:target_package] = params[:target_package] if params[:target_package]
Avoid deeply nested control flow statements. Confirmed
next if pkg2.nil? || @packages.pluck(:package).include?(pkg2) # avoid double instances
Method branch
has a Cognitive Complexity of 9 (exceeds 8 allowed). Consider refactoring. Open
def branch
#
# 1) BaseProject <-- 2) UpdateProject <-- 3) DevelProject/Package
# X) BranchProject
#
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
logger.info "Found package instance #{p.project.name}/#{p.name} for attribute #{at.name} with value #{params[:value]}"
@packages.push(base_project: p.project, link_target_project: p.project, package: p, target_package: "#{p.name}.#{p.project.name}")
- 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 42.
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
logger.info "Found package instance #{p.project.name}/#{p.name} for attribute #{at.name} and given package name #{params[:package]}"
@packages.push(base_project: p.project, link_target_project: p.project, package: p, target_package: "#{p.name}.#{p.project.name}")
- 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 42.
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