File issues_controller.rb
has 621 lines of code (exceeds 250 allowed). Consider refactoring. Open
class IssuesController < ApplicationController
default_search_scope :issues
before_action :find_issue, :only => [:show, :edit, :update, :issue_tab]
before_action :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
Method bulk_update
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
def bulk_update
@issues.sort!
@copy = params[:copy].present?
attributes = parse_params_for_bulk_update(params[:issue])
- 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 bulk_edit
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
def bulk_edit
@issues.sort!
@copy = params[:copy].present?
@notes = params[:notes]
- 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 build_new_issue_from_params
has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring. Open
def build_new_issue_from_params
@issue = Issue.new
if params[:copy_from]
begin
@issue.init_journal(User.current)
- 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 retrieve_previous_and_next_issue_ids
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def retrieve_previous_and_next_issue_ids
if params[:prev_issue_id].present? || params[:next_issue_id].present?
@prev_issue_id = params[:prev_issue_id].presence.try(:to_i)
@next_issue_id = params[:next_issue_id].presence.try(:to_i)
@issue_position = params[:issue_position].presence.try(:to_i)
- 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 update
has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring. Open
def update
return unless update_issue_from_params
attachments = params[:attachments] || params.dig(:issue, :uploads)
if @issue.attachments_addable?
- 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 bulk_edit
has 73 lines of code (exceeds 25 allowed). Consider refactoring. Open
def bulk_edit
@issues.sort!
@copy = params[:copy].present?
@notes = params[:notes]
Method destroy
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def destroy
raise Unauthorized unless @issues.all?(&:deletable?)
# all issues and their descendants are about to be deleted
issues_and_descendants_ids = Issue.self_and_descendants(@issues).pluck(:id)
- 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 bulk_update
has 70 lines of code (exceeds 25 allowed). Consider refactoring. Open
def bulk_update
@issues.sort!
@copy = params[:copy].present?
attributes = parse_params_for_bulk_update(params[:issue])
Method build_new_issue_from_params
has 56 lines of code (exceeds 25 allowed). Consider refactoring. Open
def build_new_issue_from_params
@issue = Issue.new
if params[:copy_from]
begin
@issue.init_journal(User.current)
Method index
has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring. Open
def index
use_session = !request.format.csv?
retrieve_default_query(use_session)
retrieve_query(IssueQuery, use_session)
- 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 index
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
def index
use_session = !request.format.csv?
retrieve_default_query(use_session)
retrieve_query(IssueQuery, use_session)
Method show
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def show
if !api_request? || include_in_api_response?('journals')
@journals = @issue.visible_journals_with_index
@journals.reverse! if User.current.wants_comments_in_reverse_order?
end
- 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 update
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update
return unless update_issue_from_params
attachments = params[:attachments] || params.dig(:issue, :uploads)
if @issue.attachments_addable?
Method destroy
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
def destroy
raise Unauthorized unless @issues.all?(&:deletable?)
# all issues and their descendants are about to be deleted
issues_and_descendants_ids = Issue.self_and_descendants(@issues).pluck(:id)
Method show
has 39 lines of code (exceeds 25 allowed). Consider refactoring. Open
def show
if !api_request? || include_in_api_response?('journals')
@journals = @issue.visible_journals_with_index
@journals.reverse! if User.current.wants_comments_in_reverse_order?
end
Method create
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
unless User.current.allowed_to?(:add_issues, @issue.project, :global => true)
raise ::Unauthorized
end
Method create
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def create
unless User.current.allowed_to?(:add_issues, @issue.project, :global => true)
raise ::Unauthorized
end
- 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 save_issue_with_child_records
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
def save_issue_with_child_records
Issue.transaction do
if params[:time_entry] &&
(params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) &&
User.current.allowed_to?(:log_time, @issue.project)
Method retrieve_previous_and_next_issue_ids
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def retrieve_previous_and_next_issue_ids
if params[:prev_issue_id].present? || params[:next_issue_id].present?
@prev_issue_id = params[:prev_issue_id].presence.try(:to_i)
@next_issue_id = params[:next_issue_id].presence.try(:to_i)
@issue_position = params[:issue_position].presence.try(:to_i)
Method update_issue_from_params
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update_issue_from_params
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
if params[:time_entry]
@time_entry.safe_attributes = params[:time_entry]
end
Method retrieve_default_query
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def retrieve_default_query(use_session)
return if params[:query_id].present?
return if api_request?
return if params[:set_filter]
- 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 save_issue_with_child_records
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def save_issue_with_child_records
Issue.transaction do
if params[:time_entry] &&
(params[:time_entry][:hours].present? || params[:time_entry][:comments].present?) &&
User.current.allowed_to?(:log_time, @issue.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
Avoid too many return
statements within this method. Open
return if IssueQuery.where(id: query_id).exists? && project_id == @project&.id
Method update_issue_from_params
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def update_issue_from_params
@time_entry = TimeEntry.new(:issue => @issue, :project => @issue.project)
if params[:time_entry]
@time_entry.safe_attributes = params[:time_entry]
end
- 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 redirect_after_create
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def redirect_after_create
if params[:continue]
url_params = {}
url_params[:issue] =
{
- 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
if params[:issue]
@target_tracker = @trackers.detect {|t| t.id.to_s == params[:issue][:tracker_id].to_s}
if @target_tracker
edited_issues.each {|issue| issue.tracker = @target_tracker}
- 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 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
- 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 params[:issue]
@target_status = @available_statuses.detect {|t| t.id.to_s == params[:issue][:status_id].to_s}
if @target_status
edited_issues.each {|issue| issue.status = @target_status}
- 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 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
- 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