Showing 957 of 957 total issues
Method has too many lines. [12/10] Open
def accept
invite_token = session.delete(:invite_token)
@project_user = ProjectUser.find_by_invite_token invite_token
if @project_user && @project_user.user == current_user
redirect_to @project_user.project, notice: "You have already been added to #{@project_user.project.name}."
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Perceived complexity for reassign is too high. [9/7] Open
def reassign
original_user_id = User.with_project(@project.id, [true]).find_by_id(params[:from_user_id]).id rescue original_user_id = nil # Editors only
reassign_to_user_id = User.with_project(@project.id, [true]).find_by_id(params[:to_user_id]).id rescue reassign_to_user_id = nil # Editors only
params[:sticky_status] = 'not_completed' unless ['not_completed', 'completed', 'all'].include?(params[:sticky_status])
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Method has too many lines. [12/10] Open
def create
@sticky = current_user.all_viewable_stickies.find_by(id: params[:sticky_id])
@comment = @sticky ? @sticky.comments.new(comment_params) : Comment.new(comment_params)
respond_to do |format|
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Method has too many lines. [11/10] Open
def shift_group(days_to_shift, shift)
all_dates = []
if days_to_shift != 0 && group && %w(incomplete all).include?(shift)
sticky_scope = group.stickies.where.not(id: id)
sticky_scope = sticky_scope.where(completed: false) if shift == 'incomplete'
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Cyclomatic complexity for short_time is too high. [7/6] Open
def short_time
result = ''
if start_date && start_date.year == Time.zone.today.year
result += start_date.strftime('%m/%d')
elsif start_date
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Assignment Branch Condition size for set_project_and_board is too high. [16.4/15] Open
def set_project_and_board
return unless group
self.project_id = group.project_id
if !(group.project.boards.pluck(:id) + [nil]).include?(board_id) && saved_changes[:board_id]
self.board_id = saved_changes[:board_id][0]
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Assignment Branch Condition size for update_task_status is too high. [16.12/15] Open
def update_task_status
if params[:status] == 'all'
current_user.update calendar_task_status: nil
elsif params[:status] == 'completed'
current_user.update calendar_task_status: true
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Perceived complexity for add_stickies is too high. [8/7] Open
def add_stickies
@tag = current_user.all_tags.find_by_id(params[:tag_id])
@stickies = @project.stickies.where(id: params[:sticky_ids].split(',')) if @project
if @tag && @stickies.size > 0
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Assignment Branch Condition size for digest_stickies_created is too high. [16.03/15] Open
def digest_stickies_created
all_stickies.where(project_id: all_digest_projects.select(:id), completed: false).where('created_at > ?', (Time.zone.now.monday? ? Time.zone.now - 3.day : Time.zone.now - 1.day))
end
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric
Method has too many lines. [11/10] Open
def destroy
if @sticky.group && params[:discard] == 'following'
@sticky.group.stickies.where('due_date >= ?', @sticky.due_date).destroy_all
elsif @sticky.group && params[:discard] == 'all'
@sticky.group.destroy
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Cyclomatic complexity for move is too high. [7/6] Open
def move
params[:due_date] = parse_date(params[:due_date])
@all_dates = []
if @sticky && params[:due_date].present?
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Cyclomatic complexity for destroy is too high. [7/6] Open
def destroy
@project_user = ProjectUser.find_by_id(params[:id])
@project = current_user.all_projects.find_by_id(@project_user.project_id) if @project_user
if @project.blank? && @project_user && current_user == @project_user.user
@project = current_user.all_viewable_projects.find_by_id(@project_user.project_id)
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Method has too many lines. [11/10] Open
def change_password
if current_user.valid_password?(params[:user][:current_password])
if current_user.reset_password(params[:user][:password], params[:user][:password_confirmation])
bypass_sign_in current_user
redirect_to settings_path, notice: 'Your password has been changed.'
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Perceived complexity for group_params is too high. [8/7] Open
def group_params
params[:group] ||= { blank: '1' } # {}
if @project && params[:create_new_board] == '1'
if params[:group_board_name].to_s.strip.blank?
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Cyclomatic complexity for create is too high. [7/6] Open
def create
g_params = group_params
@template = @project.templates.find_by_id(params[:group][:template_id]) if @project && params[:group]
- Read upRead up
- Exclude checks
This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.
An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.
Perceived complexity for create is too high. [8/7] Open
def create
g_params = group_params
@template = @project.templates.find_by_id(params[:group][:template_id]) if @project && params[:group]
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Method has too many lines. [11/10] Open
def destroy
@project_user = ProjectUser.find_by_id(params[:id])
@project = current_user.all_projects.find_by_id(@project_user.project_id) if @project_user
if @project.blank? && @project_user && current_user == @project_user.user
@project = current_user.all_viewable_projects.find_by_id(@project_user.project_id)
- Read upRead up
- Exclude checks
This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Perceived complexity for destroy is too high. [8/7] Open
def destroy
@project_user = ProjectUser.find_by_id(params[:id])
@project = current_user.all_projects.find_by_id(@project_user.project_id) if @project_user
if @project.blank? && @project_user && current_user == @project_user.user
@project = current_user.all_viewable_projects.find_by_id(@project_user.project_id)
- Read upRead up
- Exclude checks
This cop tries to produce a complexity score that's a measure of the
complexity the reader experiences when looking at a method. For that
reason it considers when
nodes as something that doesn't add as much
complexity as an if
or a &&
. Except if it's one of those special
case
/when
constructs where there's no expression after case
. Then
the cop treats it as an if
/elsif
/elsif
... and lets all the when
nodes count. In contrast to the CyclomaticComplexity cop, this cop
considers else
nodes as adding complexity.
Example:
def my_method # 1
if cond # 1
case var # 2 (0.8 + 4 * 0.2, rounded)
when 1 then func_one
when 2 then func_two
when 3 then func_three
when 4..10 then func_other
end
else # 1
do_something until a && b # 2
end # ===
end # 7 complexity points
Method sticky_params
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def sticky_params
params[:sticky] ||= { blank: '1' }
params[:sticky][:due_date] = parse_date(params[:sticky][:due_date]) unless params[:sticky][:due_date].blank?
- 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
Assignment Branch Condition size for index is too high. [15.13/15] Open
def index
@order = scrub_order(Tag, params[:order], 'tags.name')
@tags = current_user.all_viewable_tags.search(params[:search]).filter(params).order(@order).page(params[:page]).per( 40 )
end
- Read upRead up
- Exclude checks
This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric