Class has too many lines. [469/100] Open
class ReviewMappingController < ApplicationController
include AuthorizationHelper
autocomplete :user, :name
# helper :dynamic_review_assignment
- Read upRead up
- Exclude checks
This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.
Assignment Branch Condition size for peer_review_strategy is too high. [95.89/15] Open
def peer_review_strategy(assignment_id, review_strategy, participants_hash)
teams = review_strategy.teams
participants = review_strategy.participants
num_participants = participants.size
- 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 automatic_review_mapping is too high. [83.92/15] Open
def automatic_review_mapping
assignment_id = params[:id].to_i
assignment = Assignment.find(params[:id])
participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
- 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 peer_review_strategy
has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring. Open
def peer_review_strategy(assignment_id, review_strategy, participants_hash)
teams = review_strategy.teams
participants = review_strategy.participants
num_participants = participants.size
- 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
File review_mapping_controller.rb
has 471 lines of code (exceeds 250 allowed). Consider refactoring. Open
class ReviewMappingController < ApplicationController
include AuthorizationHelper
autocomplete :user, :name
# helper :dynamic_review_assignment
Method has too many lines. [57/10] Open
def peer_review_strategy(assignment_id, review_strategy, participants_hash)
teams = review_strategy.teams
participants = review_strategy.participants
num_participants = participants.size
- 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. [46/10] Open
def automatic_review_mapping
assignment_id = params[:id].to_i
assignment = Assignment.find(params[:id])
participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
- 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.
Assignment Branch Condition size for assign_reviewer_dynamically is too high. [51.63/15] Open
def assign_reviewer_dynamically
assignment = Assignment.find(params[:assignment_id])
participant = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
reviewer = participant.get_reviewer
if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?
- 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. [44/10] Open
def assign_reviewer_dynamically
assignment = Assignment.find(params[:assignment_id])
participant = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
reviewer = participant.get_reviewer
if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?
- 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 assign_reviewer_dynamically
has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring. Open
def assign_reviewer_dynamically
assignment = Assignment.find(params[:assignment_id])
participant = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
reviewer = participant.get_reviewer
if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_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
Assignment Branch Condition size for add_reviewer is too high. [44.25/15] Open
def add_reviewer
assignment = Assignment.find(params[:id])
topic_id = params[:topic_id]
user_id = User.where(name: params[:user][:name]).first.id
# If instructor want to assign one student to review his/her own artifact,
- 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. [33/10] Open
def assign_reviewers_for_team(assignment_id, review_strategy, participants_hash)
if ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 0)
.where('created_at > :time',
time: @@time_create_last_review_mapping_record).size < review_strategy.reviews_needed
- 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.
Assignment Branch Condition size for assign_reviewers_for_team is too high. [35.4/15] Open
def assign_reviewers_for_team(assignment_id, review_strategy, participants_hash)
if ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 0)
.where('created_at > :time',
time: @@time_create_last_review_mapping_record).size < review_strategy.reviews_needed
- 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 add_calibration is too high. [34.47/15] Open
def add_calibration
participant = begin
AssignmentParticipant.where(parent_id: params[:id], user_id: session[:user].id).first
rescue StandardError
nil
- 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 assign_quiz_dynamically is too high. [32.42/15] Open
def assign_quiz_dynamically
begin
assignment = Assignment.find(params[:assignment_id])
reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
if ResponseMap.where(reviewed_object_id: params[:questionnaire_id], reviewer_id: params[:participant_id]).first
- 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 delete_all_metareviewers is too high. [30.43/15] Open
def delete_all_metareviewers
mapping = ResponseMap.find(params[:id])
mmappings = MetareviewResponseMap.where(reviewed_object_id: mapping.map_id)
num_unsuccessful_deletes = 0
mmappings.each do |mmapping|
- 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 add_metareviewer is too high. [29.9/15] Open
def add_metareviewer
mapping = ResponseMap.find(params[:id])
msg = ''
begin
user = User.from_params(params)
- 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. [24/10] Open
def add_reviewer
assignment = Assignment.find(params[:id])
topic_id = params[:topic_id]
user_id = User.where(name: params[:user][:name]).first.id
# If instructor want to assign one student to review his/her own artifact,
- 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 peer_review_strategy is too high. [21/7] Open
def peer_review_strategy(assignment_id, review_strategy, participants_hash)
teams = review_strategy.teams
participants = review_strategy.participants
num_participants = participants.size
- 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
Perceived complexity for assign_reviewer_dynamically is too high. [20/7] Open
def assign_reviewer_dynamically
assignment = Assignment.find(params[:assignment_id])
participant = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
reviewer = participant.get_reviewer
if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?
- 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
Class ReviewMappingController
has 27 methods (exceeds 20 allowed). Consider refactoring. Open
class ReviewMappingController < ApplicationController
include AuthorizationHelper
autocomplete :user, :name
# helper :dynamic_review_assignment
Assignment Branch Condition size for start_self_review is too high. [27.37/15] Open
def start_self_review
user_id = params[:reviewer_userid]
assignment = Assignment.find(params[:assignment_id])
team = Team.find_team_for_assignment_and_user(assignment.id, user_id).first
begin
- 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
Cyclomatic complexity for peer_review_strategy is too high. [18/6] Open
def peer_review_strategy(assignment_id, review_strategy, participants_hash)
teams = review_strategy.teams
participants = review_strategy.participants
num_participants = participants.size
- 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 unsubmit_review is too high. [26.7/15] Open
def unsubmit_review
@response = Response.where(map_id: params[:id]).last
review_response_map = ReviewResponseMap.find_by(id: params[:id])
reviewer = review_response_map.reviewer.get_reviewer.name
reviewee = review_response_map.reviewee.name
- 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. [20/10] Open
def delete_all_metareviewers
mapping = ResponseMap.find(params[:id])
mmappings = MetareviewResponseMap.where(reviewed_object_id: mapping.map_id)
num_unsuccessful_deletes = 0
mmappings.each do |mmapping|
- 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.
Assignment Branch Condition size for delete_metareviewer is too high. [24.35/15] Open
def delete_metareviewer
mapping = MetareviewResponseMap.find(params[:id])
assignment_id = mapping.assignment.id
flash[:note] = 'The metareview mapping for ' + mapping.reviewee.name + ' and ' + mapping.reviewer.name + ' has been deleted.'
- 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 automatic_review_mapping is too high. [15/7] Open
def automatic_review_mapping
assignment_id = params[:id].to_i
assignment = Assignment.find(params[:id])
participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
- 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
Block has too many lines. [52/25] Open
teams.each_with_index do |team, iterator|
selected_participants = []
if !team.equal? teams.last
# need to even out the # of reviews for teams
while selected_participants.size < review_strategy.reviews_per_team
- Read upRead up
- Exclude checks
This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.
Cyclomatic complexity for assign_reviewer_dynamically is too high. [13/6] Open
def assign_reviewer_dynamically
assignment = Assignment.find(params[:assignment_id])
participant = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
reviewer = participant.get_reviewer
if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?
- 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 delete_outstanding_reviewers is too high. [21.63/15] Open
def delete_outstanding_reviewers
assignment = Assignment.find(params[:id])
team = AssignmentTeam.find(params[:contributor_id])
review_response_maps = team.review_mappings
num_remain_review_response_maps = review_response_maps.size
- 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. [16/10] Open
def add_metareviewer
mapping = ResponseMap.find(params[:id])
msg = ''
begin
user = User.from_params(params)
- 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 automatic_review_mapping is too high. [12/6] Open
def automatic_review_mapping
assignment_id = params[:id].to_i
assignment = Assignment.find(params[:id])
participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
- 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. [16/10] Open
def delete_outstanding_reviewers
assignment = Assignment.find(params[:id])
team = AssignmentTeam.find(params[:contributor_id])
review_response_maps = team.review_mappings
num_remain_review_response_maps = review_response_maps.size
- 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. [16/10] Open
def assign_quiz_dynamically
begin
assignment = Assignment.find(params[:assignment_id])
reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
if ResponseMap.where(reviewed_object_id: params[:questionnaire_id], reviewer_id: params[:participant_id]).first
- 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 peer_review_strategy
has 57 lines of code (exceeds 25 allowed). Consider refactoring. Open
def peer_review_strategy(assignment_id, review_strategy, participants_hash)
teams = review_strategy.teams
participants = review_strategy.participants
num_participants = participants.size
Method automatic_review_mapping
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def automatic_review_mapping
assignment_id = params[:id].to_i
assignment = Assignment.find(params[:id])
participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
- 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 save_grade_and_comment_for_reviewer is too high. [20.9/15] Open
def save_grade_and_comment_for_reviewer
review_grade = ReviewGrade.find_or_create_by(participant_id: params[:review_grade][:participant_id])
review_grade.attributes = review_mapping_params
review_grade.review_graded_at = Time.now
review_grade.reviewer_id = session[:user].id
- 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. [15/10] Open
def add_calibration
participant = begin
AssignmentParticipant.where(parent_id: params[:id], user_id: session[:user].id).first
rescue StandardError
nil
- 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. [15/10] Open
def start_self_review
user_id = params[:reviewer_userid]
assignment = Assignment.find(params[:assignment_id])
team = Team.find_team_for_assignment_and_user(assignment.id, user_id).first
begin
- 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.
Assignment Branch Condition size for delete_reviewer is too high. [19.34/15] Open
def delete_reviewer
review_response_map = ReviewResponseMap.find_by(id: params[:id])
if review_response_map && !Response.exists?(map_id: review_response_map.id)
review_response_map.destroy
flash[:success] = 'The review mapping for "' + review_response_map.reviewee.name + '" and "' + review_response_map.reviewer.name + '" has been deleted.'
- 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. [14/10] Open
def save_grade_and_comment_for_reviewer
review_grade = ReviewGrade.find_or_create_by(participant_id: params[:review_grade][:participant_id])
review_grade.attributes = review_mapping_params
review_grade.review_graded_at = Time.now
review_grade.reviewer_id = session[:user].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.
Assignment Branch Condition size for automatic_review_mapping_strategy is too high. [18.71/15] Open
def automatic_review_mapping_strategy(assignment_id,
participants, teams, student_review_num = 0,
submission_review_num = 0, exclude_teams = false)
participants_hash = {}
participants.each { |participant| participants_hash[participant.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
Method has too many lines. [12/10] Open
def check_outstanding_reviews?(assignment, reviewer)
@review_mappings = ReviewResponseMap.where(reviewer_id: reviewer.id, reviewed_object_id: assignment.id)
@num_reviews_total = @review_mappings.size
if @num_reviews_total.zero?
true
- 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 automatic_review_mapping
has 46 lines of code (exceeds 25 allowed). Consider refactoring. Open
def automatic_review_mapping
assignment_id = params[:id].to_i
assignment = Assignment.find(params[:id])
participants = AssignmentParticipant.where(parent_id: params[:id].to_i).to_a.select(&:can_review).shuffle!
teams = AssignmentTeam.where(parent_id: params[:id].to_i).to_a.shuffle!
Cyclomatic complexity for automatic_review_mapping_strategy is too high. [7/6] Open
def automatic_review_mapping_strategy(assignment_id,
participants, teams, student_review_num = 0,
submission_review_num = 0, exclude_teams = false)
participants_hash = {}
participants.each { |participant| participants_hash[participant.id] = 0 }
- 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 automatic_review_mapping_strategy is too high. [8/7] Open
def automatic_review_mapping_strategy(assignment_id,
participants, teams, student_review_num = 0,
submission_review_num = 0, exclude_teams = false)
participants_hash = {}
participants.each { |participant| participants_hash[participant.id] = 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 check_outstanding_reviews? is too high. [16.43/15] Open
def check_outstanding_reviews?(assignment, reviewer)
@review_mappings = ReviewResponseMap.where(reviewer_id: reviewer.id, reviewed_object_id: assignment.id)
@num_reviews_total = @review_mappings.size
if @num_reviews_total.zero?
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
Method assign_reviewer_dynamically
has 44 lines of code (exceeds 25 allowed). Consider refactoring. Open
def assign_reviewer_dynamically
assignment = Assignment.find(params[:assignment_id])
participant = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
reviewer = participant.get_reviewer
if params[:i_dont_care].nil? && params[:topic_id].nil? && assignment.topics? && assignment.can_choose_topic_to_review?
Method assign_reviewers_for_team
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def assign_reviewers_for_team(assignment_id, review_strategy, participants_hash)
if ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 0)
.where('created_at > :time',
time: @@time_create_last_review_mapping_record).size < review_strategy.reviews_needed
- 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 assign_reviewers_for_team
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
def assign_reviewers_for_team(assignment_id, review_strategy, participants_hash)
if ReviewResponseMap.where(reviewed_object_id: assignment_id, calibrate_to: 0)
.where('created_at > :time',
time: @@time_create_last_review_mapping_record).size < review_strategy.reviews_needed
Method automatic_review_mapping_strategy
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
def automatic_review_mapping_strategy(assignment_id,
participants, teams, student_review_num = 0,
submission_review_num = 0, exclude_teams = false)
Avoid deeply nested control flow statements. Open
rescue StandardError
nil
Method add_reviewer
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def add_reviewer
assignment = Assignment.find(params[:id])
topic_id = params[:topic_id]
user_id = User.where(name: params[:user][:name]).first.id
# If instructor want to assign one student to review his/her own artifact,
- 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 assign_quiz_dynamically
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def assign_quiz_dynamically
begin
assignment = Assignment.find(params[:assignment_id])
reviewer = AssignmentParticipant.where(user_id: params[:reviewer_id], parent_id: assignment.id).first
if ResponseMap.where(reviewed_object_id: params[:questionnaire_id], reviewer_id: params[:participant_id]).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 check_outstanding_reviews?
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def check_outstanding_reviews?(assignment, reviewer)
@review_mappings = ReviewResponseMap.where(reviewer_id: reviewer.id, reviewed_object_id: assignment.id)
@num_reviews_total = @review_mappings.size
if @num_reviews_total.zero?
true
- 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 parameter lists longer than 5 parameters. [6/5] Open
def automatic_review_mapping_strategy(assignment_id,
participants, teams, student_review_num = 0,
submission_review_num = 0, exclude_teams = false)
- Read upRead up
- Exclude checks
This cop checks for methods with too many parameters. The maximum number of parameters is configurable. Keyword arguments can optionally be excluded from the total count.
Avoid more than 3 levels of block nesting. Open
if assignment.topics? # assignment with topics
topic = if params[:topic_id]
SignUpTopic.find(params[:topic_id])
else
begin
- Read upRead up
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
Avoid more than 3 levels of block nesting. Open
participants_with_min_assigned_reviews << participants.index(participant) if participants_hash[participant.id] == min_value
- Read upRead up
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
Avoid more than 3 levels of block nesting. Open
rand_num = if if_condition_1 || if_condition_2
# use original method to get random number
rand(0..num_participants - 1)
else
# rand_num should be the position of this participant in original array
- Read upRead up
- Exclude checks
This cop checks for excessive nesting of conditional and looping constructs.
You can configure if blocks are considered using the CountBlocks
option. When set to false
(the default) blocks are not counted
towards the nesting level. Set to true
to count blocks as well.
The maximum level of nesting allowed is configurable.
Use normalcase for variable numbers. Open
if_condition_2 = ((participants_with_min_assigned_reviews.size == 1) && TeamsUser.exists?(team_id: team.id, user_id: participants[participants_with_min_assigned_reviews[0]].user_id))
- Read upRead up
- Exclude checks
This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.
Example: EnforcedStyle: snake_case
# bad
variable1 = 1
# good
variable_1 = 1
Example: EnforcedStyle: normalcase (default)
# bad
variable_1 = 1
# good
variable1 = 1
Example: EnforcedStyle: non_integer
# bad
variable1 = 1
variable_1 = 1
# good
variableone = 1
variable_one = 1
Use normalcase for variable numbers. Open
if_condition_2 = (!selected_participants.include? participants[rand_num].id)
- Read upRead up
- Exclude checks
This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.
Example: EnforcedStyle: snake_case
# bad
variable1 = 1
# good
variable_1 = 1
Example: EnforcedStyle: normalcase (default)
# bad
variable_1 = 1
# good
variable1 = 1
Example: EnforcedStyle: non_integer
# bad
variable1 = 1
variable_1 = 1
# good
variableone = 1
variable_one = 1
Convert if
nested inside else
to elsif
. Open
if review_allowed?(assignment, reviewer)
- Read upRead up
- Exclude checks
If the else
branch of a conditional consists solely of an if
node,
it can be combined with the else
to become an elsif
.
This helps to keep the nesting level from getting too deep.
Example:
# bad
if condition_a
action_a
else
if condition_b
action_b
else
action_c
end
end
# good
if condition_a
action_a
elsif condition_b
action_b
else
action_c
end
Replace class var @@time_create_last_review_mapping_record with a class instance var. Open
@@time_create_last_review_mapping_record = ReviewResponseMap
- Read upRead up
- Exclude checks
This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.
Use the return of the conditional for variable assignment and comparison. Open
if assignment.auto_assign_mentor
team = MentoredTeam.create_team_and_node(assignment_id)
else
team = AssignmentTeam.create_team_and_node(assignment_id)
end
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if SelfReviewResponseMap.where(reviewee_id: team.id, reviewer_id: params[:reviewer_id]).first.nil?
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Missing top-level class documentation comment. Open
class ReviewMappingController < ApplicationController
- Read upRead up
- Exclude checks
This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.
The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.
Example:
# bad
class Person
# ...
end
# good
# Description/Explanation of Person class
class Person
# ...
end
Use a guard clause instead of wrapping the code inside a conditional expression. Open
if ReviewResponseMap.where(reviewee_id: params[:contributor_id], reviewer_id: reviewer.id).first.nil?
- Read upRead up
- Exclude checks
Use a guard clause instead of wrapping the code inside a conditional expression
Example:
# bad
def test
if something
work
end
end
# good
def test
return unless something
work
end
# also good
def test
work if something
end
# bad
if something
raise 'exception'
else
ok
end
# good
raise 'exception' if something
ok
Missing space after #
. Open
#if exclude_teams_without_submission is true check if team has submission if not discard
- Read upRead up
- Exclude checks
This cop checks whether comments have a leading space after the
#
denoting the start of the comment. The leading space is not
required for some RDoc special syntax, like #++
, #--
,
#:nodoc
, =begin
- and =end
comments, "shebang" directives,
or rackup options.
Example:
# bad
#Some comment
# good
# Some comment
Use normalcase for variable numbers. Open
if_condition_1 = participants_with_min_assigned_reviews.empty?
- Read upRead up
- Exclude checks
This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.
Example: EnforcedStyle: snake_case
# bad
variable1 = 1
# good
variable_1 = 1
Example: EnforcedStyle: normalcase (default)
# bad
variable_1 = 1
# good
variable1 = 1
Example: EnforcedStyle: non_integer
# bad
variable1 = 1
variable_1 = 1
# good
variableone = 1
variable_one = 1
Use normalcase for variable numbers. Open
if_condition_1 = (participants_hash[participants[rand_num].id] < review_strategy.reviews_per_student)
- Read upRead up
- Exclude checks
This cop makes sure that all numbered variables use the configured style, snakecase, normalcase or noninteger, for their numbering.
Example: EnforcedStyle: snake_case
# bad
variable1 = 1
# good
variable_1 = 1
Example: EnforcedStyle: normalcase (default)
# bad
variable_1 = 1
# good
variable1 = 1
Example: EnforcedStyle: non_integer
# bad
variable1 = 1
variable_1 = 1
# good
variableone = 1
variable_one = 1
Replace class var @@time_create_last_review_mapping_record with a class instance var. Open
@@time_create_last_review_mapping_record = nil
- Read upRead up
- Exclude checks
This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.