Assignment Branch Condition size for participants_popup is too high. [61.85/15] Open
def participants_popup
@sum = 0
@count = 0
@participantid = params[:id]
@uid = Participant.find(params[:id]).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
Assignment Branch Condition size for team_users_popup is too high. [61.26/15] Open
def team_users_popup
@sum = 0
@team = Team.find(params[:id])
@assignment = Assignment.find(@team.parent_id)
@team_users = TeamsUser.where(team_id: params[: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
Assignment Branch Condition size for build_tone_analysis_heatmap is too high. [45.67/15] Open
def build_tone_analysis_heatmap
@heatmap_urls = []
keys = @review_final_versions.keys
- 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
Block has too many lines. [79/25] Open
keys.each_with_index do |key, round|
next if @sentiment_summary[round].nil?
content = []
v_label = []
h_label = []
- 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.
Assignment Branch Condition size for build_tone_analysis_report is too high. [39.9/15] Open
def build_tone_analysis_report
uri = WEBSERVICE_CONFIG['sentiment_webservice_url'] + "analyze_reviews_bulk"
index = 0
@sentiment_summary = []
keys = @review_final_versions.keys
- 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 build_tone_analysis_heatmap
has 85 lines of code (exceeds 25 allowed). Consider refactoring. Open
def build_tone_analysis_heatmap
@heatmap_urls = []
keys = @review_final_versions.keys
Assignment Branch Condition size for author_feedback_popup is too high. [26.25/15] Open
def author_feedback_popup
@response_id = params[:response_id]
@reviewee_id = params[:reviewee_id]
unless @response_id.nil?
first_question_in_questionnaire = Answer.where(response_id: @response_id).first.question_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 build_tone_analysis_heatmap
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
def build_tone_analysis_heatmap
@heatmap_urls = []
keys = @review_final_versions.keys
- 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 self_review_popup is too high. [21.73/15] Open
def self_review_popup
@response_id = params[:response_id]
@user_fullname = params[:user_fullname]
unless @response_id.nil?
first_question_in_questionnaire = Answer.where(response_id: @response_id).first.question_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 build_tone_analysis_report
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def build_tone_analysis_report
uri = WEBSERVICE_CONFIG['sentiment_webservice_url'] + "analyze_reviews_bulk"
index = 0
@sentiment_summary = []
keys = @review_final_versions.keys
- 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 popup_controller.rb
has 260 lines of code (exceeds 250 allowed). Consider refactoring. Open
class PopupController < ApplicationController
def action_allowed?
['Super-Administrator',
'Administrator',
'Instructor',
Cyclomatic complexity for build_tone_analysis_heatmap is too high. [10/6] Open
def build_tone_analysis_heatmap
@heatmap_urls = []
keys = @review_final_versions.keys
- 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 build_tone_analysis_report
has 45 lines of code (exceeds 25 allowed). Consider refactoring. Open
def build_tone_analysis_report
uri = WEBSERVICE_CONFIG['sentiment_webservice_url'] + "analyze_reviews_bulk"
index = 0
@sentiment_summary = []
keys = @review_final_versions.keys
Method participants_popup
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def participants_popup
@sum = 0
@count = 0
@participantid = params[:id]
@uid = Participant.find(params[:id]).user_id
Block has too many lines. [35/25] Open
keys.each do |key|
questionnaire = Questionnaire.find(@review_final_versions[key][:questionnaire_id])
questions = Question.where(questionnaire_id: questionnaire.id)
# Loops by each question per review round
- 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.
Method team_users_popup
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def team_users_popup
@sum = 0
@team = Team.find(params[:id])
@assignment = Assignment.find(@team.parent_id)
@team_users = TeamsUser.where(team_id: params[: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 participants_popup
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def participants_popup
@sum = 0
@count = 0
@participantid = params[:id]
@uid = Participant.find(params[:id]).user_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
Identical blocks of code found in 2 locations. Consider refactoring. Open
unless @response_id.nil?
first_question_in_questionnaire = Answer.where(response_id: @response_id).first.question_id
questionnaire_id = Question.find(first_question_in_questionnaire).questionnaire_id
questionnaire = Questionnaire.find(questionnaire_id)
@maxscore = questionnaire.max_question_score
- 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 43.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
unless @response_id.nil?
first_question_in_questionnaire = Answer.where(response_id: @response_id).first.question_id
questionnaire_id = Question.find(first_question_in_questionnaire).questionnaire_id
questionnaire = Questionnaire.find(questionnaire_id)
@maxscore = questionnaire.max_question_score
- 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 43.
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
Line is too long. [162/160] Open
heatmap_json = RestClient.post WEBSERVICE_CONFIG['heatmap_webservice_url'], contents.to_json, content_type: 'application/json; charset=UTF-8', accept: :json
- Exclude checks
Operator =
should be surrounded by a single space. Open
uri = WEBSERVICE_CONFIG['sentiment_webservice_url'] + "analyze_reviews_bulk"
- Read upRead up
- Exclude checks
Checks that operators have space around them, except for ** which should not have surrounding space.
Example:
# bad
total = 3*4
"apple"+"juice"
my_number = 38/4
a ** b
# good
total = 3 * 4
"apple" + "juice"
my_number = 38 / 4
a**b
Use a guard clause instead of wrapping the code inside a conditional expression. Open
unless params[:id2].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
Favor unless
over if
for negative conditions. Open
if !reviews.empty?
index = 0
revs = {
reviews: reviews
}
- Read upRead up
- Exclude checks
Checks for uses of if with a negated condition. Only ifs without else are considered. There are three different styles:
- both
- prefix
- postfix
Example: EnforcedStyle: both (default)
# enforces `unless` for `prefix` and `postfix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# bad
bar if !foo
# good
bar unless foo
Example: EnforcedStyle: prefix
# enforces `unless` for just `prefix` conditionals
# bad
if !foo
bar
end
# good
unless foo
bar
end
# good
bar if !foo
Example: EnforcedStyle: postfix
# enforces `unless` for just `postfix` conditionals
# bad
bar if !foo
# good
bar unless foo
# good
if !foo
bar
end
Extra empty line detected at method body beginning. Open
@heatmap_urls = []
- Read upRead up
- Exclude checks
This cops checks if empty lines exist around the bodies of methods.
Example:
# good
def foo
# ...
end
# bad
def bar
# ...
end
Use a guard clause instead of wrapping the code inside a conditional expression. Open
unless @response_id.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
Unnecessary spacing detected. Open
uri = WEBSERVICE_CONFIG['sentiment_webservice_url'] + "analyze_reviews_bulk"
- Read upRead up
- Exclude checks
This cop checks for extra/unnecessary whitespace.
Example:
# good if AllowForAlignment is true
name = "RuboCop"
# Some comment and an empty line
website += "/bbatsov/rubocop" unless cond
puts "rubocop" if debug
# bad for any configuration
set_app("RuboCop")
website = "https://github.com/bbatsov/rubocop"