Class BsRequest
has 77 methods (exceeds 20 allowed). Consider refactoring. Open
class BsRequest < ApplicationRecord
include BsRequest::Errors
SEARCHABLE_FIELDS = [
'bs_requests.creator',
'bs_requests.priority',
Method action_details
has a Cognitive Complexity of 52 (exceeds 8 allowed). Consider refactoring. Open
def action_details(opts = {}, xml:)
with_diff = opts.delete(:diffs)
action = { type: xml.action_type }
action[:id] = xml.id
action[:number] = xml.bs_request.number
- 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 new_from_hash
has a Cognitive Complexity of 42 (exceeds 8 allowed). Consider refactoring. Wontfix
def self.new_from_hash(hashed)
if hashed['id']
theid = hashed.delete('id') { raise 'not found' }
theid = Integer(theid)
else
- 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 _assignreview_update_reviews
has a Cognitive Complexity of 27 (exceeds 8 allowed). Consider refactoring. Open
def _assignreview_update_reviews(reviewer, opts, new_review = nil)
review_comment = nil
reviews.reverse_each do |review|
next if review.by_user
next if review.by_group && review.by_group != opts[:by_group]
- 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 change_review_state
has a Cognitive Complexity of 27 (exceeds 8 allowed). Consider refactoring. Open
def change_review_state(new_review_state, opts = {})
with_lock do
new_review_state = new_review_state.to_sym
raise InvalidStateError, 'request is not in a changeable state (new, review or declined)' unless state == :review || (state.in?(%i[new declined]) && new_review_state == :new)
- 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 action_details
has 80 lines of code (exceeds 25 allowed). Consider refactoring. Confirmed
def action_details(opts = {}, xml:)
with_diff = opts.delete(:diffs)
action = { type: xml.action_type }
action[:id] = xml.id
action[:number] = xml.bs_request.number
Method render_xml
has a Cognitive Complexity of 24 (exceeds 8 allowed). Consider refactoring. Open
def render_xml(opts = {})
builder = Nokogiri::XML::Builder.new
builder.request(id: number, creator: creator) do |r|
bs_request_actions.includes([:bs_request_action_accept_info]).find_each do |action|
action.render_xml(r)
- 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 apply_default_reviewers
has a Cognitive Complexity of 24 (exceeds 8 allowed). Consider refactoring. Open
def apply_default_reviewers
reviewers = collect_default_reviewers!
# apply reviewers
reviewers.each do |r|
if r.instance_of?(User)
- 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 is_reviewer?
has a Cognitive Complexity of 24 (exceeds 8 allowed). Consider refactoring. Open
def is_reviewer?(user)
return false if reviews.blank?
reviews.each do |r|
if r.by_user
- 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 new_from_hash
has 65 lines of code (exceeds 25 allowed). Consider refactoring. Wontfix
def self.new_from_hash(hashed)
if hashed['id']
theid = hashed.delete('id') { raise 'not found' }
theid = Integer(theid)
else
Method assignreview
has a Cognitive Complexity of 19 (exceeds 8 allowed). Consider refactoring. Open
def assignreview(opts = {})
raise InvalidStateError, 'request is not in review state' unless state == :review || state == :new
reviewer = User.find_by_login!(opts[:reviewer])
- 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 auto_accept
has a Cognitive Complexity of 18 (exceeds 8 allowed). Consider refactoring. Open
def auto_accept
# do not run for processed requests. Ignoring review on purpose since this
# must also work when people do not react anymore
return unless state == :new || state == :review
- 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 change_state
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
def change_state(opts)
with_lock do
permission_check_change_state!(opts)
changestate_revoked(opts) if opts[:newstate] == 'revoked'
changestate_accepted(opts) if opts[:newstate] == 'accepted'
Method render_xml
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
def render_xml(opts = {})
builder = Nokogiri::XML::Builder.new
builder.request(id: number, creator: creator) do |r|
bs_request_actions.includes([:bs_request_action_accept_info]).find_each do |action|
action.render_xml(r)
Method changestate_accepted
has a Cognitive Complexity of 15 (exceeds 8 allowed). Consider refactoring. Open
def changestate_accepted(opts)
# all maintenance_incident actions go into the same incident project
incident_project = nil # .where(type: 'maintenance_incident')
bs_request_actions.each do |action|
source_project = Project.find_by_name(action.source_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 change_state
has a Cognitive Complexity of 14 (exceeds 8 allowed). Consider refactoring. Open
def change_state(opts)
with_lock do
permission_check_change_state!(opts)
changestate_revoked(opts) if opts[:newstate] == 'revoked'
changestate_accepted(opts) if opts[:newstate] == 'accepted'
- 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 change_review_state
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def change_review_state(new_review_state, opts = {})
with_lock do
new_review_state = new_review_state.to_sym
raise InvalidStateError, 'request is not in a changeable state (new, review or declined)' unless state == :review || (state.in?(%i[new declined]) && new_review_state == :new)
Method obsolete_reviews
has a Cognitive Complexity of 12 (exceeds 8 allowed). Consider refactoring. Open
def obsolete_reviews(opts)
return false unless opts[:by_user] || opts[:by_group] || opts[:by_project] || opts[:by_package]
reviews.each do |review|
next unless review.reviewable_by?(opts)
- 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
Avoid deeply nested control flow statements. Confirmed
if r.by_package
pkg = Package.find_by_project_and_name(r.by_project, r.by_package)
return true if pkg && user.can_modify?(pkg)
else
prj = Project.find_by_name(r.by_project)
Avoid deeply nested control flow statements. Confirmed
if action[:forward]
action[:forward].each do |forward|
if forward[:project] == lprj && forward[:package] == lpkg
link_is_already_devel = true
break
Avoid deeply nested control flow statements. Confirmed
unless link_is_already_devel
action[:forward] ||= []
action[:forward] << { project: linkinfo['project'], package: linkinfo['package'], type: 'link' }
end
Avoid deeply nested control flow statements. Confirmed
next if reviews.any? { |a| a.by_project == r.name && a.by_package.nil? }
Avoid deeply nested control flow statements. Confirmed
elsif r.instance_of?(Package)
next if reviews.any? { |a| a.by_project == r.project.name && a.by_package == r.name }
reviews.new(by_project: r.project.name, by_package: r.name, state: :new)
else
Similar blocks of code found in 2 locations. Consider refactoring. Open
if xml.target_project
action[:tprj] = xml.target_project
action[:tpkg] = xml.target_package if xml.target_package
action[:trepo] = xml.target_repository if xml.target_repository
- 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 25.
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
if xml.source_project
action[:sprj] = xml.source_project
action[:spkg] = xml.source_package if xml.source_package
action[:srev] = xml.source_rev if xml.source_rev
- 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 25.
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