Class has too many lines. [176/100] Open
class ReputationWebServiceController < ApplicationController
include AuthorizationHelper
# Method: action_allowed
# This method checks if the currently authenticated user has the authorization
- 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 get_peer_reviews is too high. [27.86/15] Open
def get_peer_reviews(assignment_id_list, round_num, has_topic)
raw_data_array = []
ReviewResponseMap.where('reviewed_object_id in (?) and calibrate_to = ?', assignment_id_list, false).each do |response_map|
reviewer = response_map.reviewer.user
team = AssignmentTeam.find(response_map.reviewee_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
Class ReputationWebServiceController
has 24 methods (exceeds 20 allowed). Consider refactoring. Open
class ReputationWebServiceController < ApplicationController
include AuthorizationHelper
# Method: action_allowed
# This method checks if the currently authenticated user has the authorization
Assignment Branch Condition size for prepare_request_body is too high. [23.79/15] Open
def prepare_request_body
reputation_web_service_path = URI.parse(WEBSERVICE_CONFIG['reputation_web_service_url']).path
post_req = Net::HTTP::Post.new(reputation_web_service_path, { 'Content-Type' => 'application/json', 'charset' => 'utf-8' })
curr_assignment_id = (params[:assignment_id].empty? ? '754' : params[:assignment_id])
assignment_id_list_peers = get_assignment_id_list(curr_assignment_id, params[:another_assignment_id].to_i)
- 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_additional_info_details is too high. [23.37/15] Open
def add_additional_info_details(post_req)
if params[:checkbox][:expert_grade] == 'Add expert grades'
add_expert_grades(post_req.body)
elsif params[:checkbox][:hamer] == 'Add initial Hamer reputation values'
add_hamer_reputation_values
- 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 generate_json_body is too high. [21.4/15] Open
def generate_json_body(results)
request_body = {}
results.each_with_index do |record, _index|
request_body['submission' + record[1].to_s] = {} unless request_body.key?('submission' + record[1].to_s)
request_body['submission' + record[1].to_s]['stu' + record[0].to_s] = record[2]
- 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 get_peer_reviews(assignment_id_list, round_num, has_topic)
raw_data_array = []
ReviewResponseMap.where('reviewed_object_id in (?) and calibrate_to = ?', assignment_id_list, false).each do |response_map|
reviewer = response_map.reviewer.user
team = AssignmentTeam.find(response_map.reviewee_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 has too many lines. [11/10] Open
def add_additional_info_details(post_req)
if params[:checkbox][:expert_grade] == 'Add expert grades'
add_expert_grades(post_req.body)
elsif params[:checkbox][:hamer] == 'Add initial Hamer reputation values'
add_hamer_reputation_values
- 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 get_peer_reviews is too high. [7/6] Open
def get_peer_reviews(assignment_id_list, round_num, has_topic)
raw_data_array = []
ReviewResponseMap.where('reviewed_object_id in (?) and calibrate_to = ?', assignment_id_list, false).each do |response_map|
reviewer = response_map.reviewer.user
team = AssignmentTeam.find(response_map.reviewee_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 get_peer_reviews
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def get_peer_reviews(assignment_id_list, round_num, has_topic)
raw_data_array = []
ReviewResponseMap.where('reviewed_object_id in (?) and calibrate_to = ?', assignment_id_list, false).each do |response_map|
reviewer = response_map.reviewer.user
team = AssignmentTeam.find(response_map.reviewee_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 update_participants_reputation
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def update_participants_reputation(reputation_response)
JSON.parse(reputation_response.body.to_s).each do |reputation_algorithm, user_resputation_list|
next unless %w[Hamer Lauw].include?(reputation_algorithm)
user_resputation_list.each do |user_id, reputation|
- 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 using rescue
in its modifier form. Open
@assignment = Assignment.find(flash[:assignment_id]) rescue nil
- Read upRead up
- Exclude checks
This cop checks for uses of rescue in its modifier form.
Example:
# bad
some_method rescue handle_error
# good
begin
some_method
rescue
handle_error
end
Redundant curly braces around a hash parameter. Open
post_req = Net::HTTP::Post.new(reputation_web_service_path, { 'Content-Type' => 'application/json', 'charset' => 'utf-8' })
- Read upRead up
- Exclude checks
This cop checks for braces around the last parameter in a method call
if the last parameter is a hash.
It supports braces
, no_braces
and context_dependent
styles.
Example: EnforcedStyle: braces
# The `braces` style enforces braces around all method
# parameters that are hashes.
# bad
some_method(x, y, a: 1, b: 2)
# good
some_method(x, y, {a: 1, b: 2})
Example: EnforcedStyle: no_braces (default)
# The `no_braces` style checks that the last parameter doesn't
# have braces around it.
# bad
some_method(x, y, {a: 1, b: 2})
# good
some_method(x, y, a: 1, b: 2)
Example: EnforcedStyle: context_dependent
# The `context_dependent` style checks that the last parameter
# doesn't have braces around it, but requires braces if the
# second to last parameter is also a hash literal.
# bad
some_method(x, y, {a: 1, b: 2})
some_method(x, y, {a: 1, b: 2}, a: 1, b: 2)
# good
some_method(x, y, a: 1, b: 2)
some_method(x, y, {a: 1, b: 2}, {a: 1, b: 2})
Avoid using rescue
in its modifier form. Open
@another_assignment = Assignment.find(flash[:another_assignment_id]) rescue nil
- Read upRead up
- Exclude checks
This cop checks for uses of rescue in its modifier form.
Example:
# bad
some_method rescue handle_error
# good
begin
some_method
rescue
handle_error
end
Redundant begin
block detected. Open
begin
- Read upRead up
- Exclude checks
This cop checks for redundant begin
blocks.
Currently it checks for code like this:
Example:
def redundant
begin
ala
bala
rescue StandardError => e
something
end
end
def preferred
ala
bala
rescue StandardError => e
something
end