Assignment Branch Condition size for find_team_participants is too high. [35.13/15] Open
def self.find_team_participants(assignment_id, ip_address = nil)
@participants = SignedUpTeam.joins('INNER JOIN sign_up_topics ON signed_up_teams.topic_id = sign_up_topics.id')
.select('signed_up_teams.id as id, sign_up_topics.id as topic_id, sign_up_topics.topic_name as name,
sign_up_topics.topic_name as team_name_placeholder, sign_up_topics.topic_name as user_name_placeholder,
signed_up_teams.is_waitlisted as is_waitlisted, signed_up_teams.team_id as team_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. [26/10] Open
def self.find_team_participants(assignment_id, ip_address = nil)
@participants = SignedUpTeam.joins('INNER JOIN sign_up_topics ON signed_up_teams.topic_id = sign_up_topics.id')
.select('signed_up_teams.id as id, sign_up_topics.id as topic_id, sign_up_topics.topic_name as name,
sign_up_topics.topic_name as team_name_placeholder, sign_up_topics.topic_name as user_name_placeholder,
signed_up_teams.is_waitlisted as is_waitlisted, signed_up_teams.team_id as team_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.
Method release_topics_selected_by_team_for_assignment
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def self.release_topics_selected_by_team_for_assignment(team_id, assignment_id)
old_teams_signups = SignedUpTeam.where(team_id: team_id)
# If the team has signed up for the topic and they are on the waitlist then remove that team from the waitlist.
unless old_teams_signups.nil?
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Method find_team_participants
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.find_team_participants(assignment_id, ip_address = nil)
@participants = SignedUpTeam.joins('INNER JOIN sign_up_topics ON signed_up_teams.topic_id = sign_up_topics.id')
.select('signed_up_teams.id as id, sign_up_topics.id as topic_id, sign_up_topics.topic_name as name,
sign_up_topics.topic_name as team_name_placeholder, sign_up_topics.topic_name as user_name_placeholder,
signed_up_teams.is_waitlisted as is_waitlisted, signed_up_teams.team_id as team_id')
Missing top-level class documentation comment. Open
class SignedUpTeam < ApplicationRecord
- 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
unless old_teams_signups.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