Class has too many lines. [207/100] Open
class QuestionnairesController < ApplicationController
include AuthorizationHelper
before_action [:create_questionnaire, :save], only: [:list]
include QuestionnaireHelper
include QuestionHelper
- 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 add_new_questions is too high. [53.27/15] Open
def add_new_questions
questionnaire_id = params[:id]
# If the questionnaire is being used in the active period of an assignment, delete existing responses before adding new questions
if AnswerHelper.check_and_delete_responses(questionnaire_id)
flash[:success] = 'You have successfully added a new question. Any existing reviews for the questionnaire have 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. [35/10] Open
def add_new_questions
questionnaire_id = params[:id]
# If the questionnaire is being used in the active period of an assignment, delete existing responses before adding new questions
if AnswerHelper.check_and_delete_responses(questionnaire_id)
flash[:success] = 'You have successfully added a new question. Any existing reviews for the questionnaire have been deleted!'
- 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 create is too high. [40.34/15] Open
def create
if params[:questionnaire][:name].blank?
flash[:error] = 'A rubric or survey must have a title.'
redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]
else
- 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 is too high. [36.72/15] Open
def update
# If 'Add' or 'Edit/View advice' is clicked, redirect appropriately
if params[:add_new_questions]
permitted_params = params.permit(:id, new_question: params[:new_question].keys)
redirect_to action: 'add_new_questions', id: permitted_params[:id], question: permitted_params[:new_question]
- 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. [25/10] Open
def delete
@questionnaire = Questionnaire.find(params[:id])
if @questionnaire
begin
name = @questionnaire.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.
Method has too many lines. [23/10] Open
def create
if params[:questionnaire][:name].blank?
flash[:error] = 'A rubric or survey must have a title.'
redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]
else
- 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 is too high. [27.22/15] Open
def delete
@questionnaire = Questionnaire.find(params[:id])
if @questionnaire
begin
name = @questionnaire.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
Assignment Branch Condition size for action_allowed? is too high. [24.06/15] Open
def action_allowed?
case params[:action]
when 'edit'
@questionnaire = Questionnaire.find(params[:id])
current_user_has_admin_privileges? ||
- 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. [18/10] Open
def update
# If 'Add' or 'Edit/View advice' is clicked, redirect appropriately
if params[:add_new_questions]
permitted_params = params.permit(:id, new_question: params[:new_question].keys)
redirect_to action: 'add_new_questions', id: permitted_params[:id], question: permitted_params[:new_question]
- 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 copy is too high. [20.64/15] Open
def copy
instructor_id = session[:user].instructor_id
@questionnaire = Questionnaire.copy_questionnaire_details(params, instructor_id)
p_folder = TreeFolder.find_by(name: @questionnaire.display_type)
parent = FolderNode.find_by(node_object_id: p_folder.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. [14/10] Open
def save_all_questions
questionnaire_id = params[:id]
begin
if params[:save]
update_questionnaire_questions
- 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 add_new_questions is too high. [8/6] Open
def add_new_questions
questionnaire_id = params[:id]
# If the questionnaire is being used in the active period of an assignment, delete existing responses before adding new questions
if AnswerHelper.check_and_delete_responses(questionnaire_id)
flash[:success] = 'You have successfully added a new question. Any existing reviews for the questionnaire have been deleted!'
- 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_questionnaire_parameters is too high. [17.89/15] Open
def set_questionnaire_parameters(private_flag, display)
@questionnaire.private = private_flag
@questionnaire.name = params[:questionnaire][:name]
@questionnaire.instructor_id = session[:user].id
@questionnaire.min_question_score = params[:questionnaire][:min_question_score]
- 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_new_questions is too high. [9/7] Open
def add_new_questions
questionnaire_id = params[:id]
# If the questionnaire is being used in the active period of an assignment, delete existing responses before adding new questions
if AnswerHelper.check_and_delete_responses(questionnaire_id)
flash[:success] = 'You have successfully added a new question. Any existing reviews for the questionnaire have been deleted!'
- 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 action_allowed? is too high. [8/6] Open
def action_allowed?
case params[:action]
when 'edit'
@questionnaire = Questionnaire.find(params[:id])
current_user_has_admin_privileges? ||
- 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 action_allowed? is too high. [8/7] Open
def action_allowed?
case params[:action]
when 'edit'
@questionnaire = Questionnaire.find(params[:id])
current_user_has_admin_privileges? ||
- 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 save_all_questions is too high. [15.81/15] Open
def save_all_questions
questionnaire_id = params[:id]
begin
if params[:save]
update_questionnaire_questions
- 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 add_new_questions
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def add_new_questions
questionnaire_id = params[:id]
# If the questionnaire is being used in the active period of an assignment, delete existing responses before adding new questions
if AnswerHelper.check_and_delete_responses(questionnaire_id)
flash[:success] = 'You have successfully added a new question. Any existing reviews for the questionnaire have been deleted!'
- 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 add_new_questions
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
def add_new_questions
questionnaire_id = params[:id]
# If the questionnaire is being used in the active period of an assignment, delete existing responses before adding new questions
if AnswerHelper.check_and_delete_responses(questionnaire_id)
flash[:success] = 'You have successfully added a new question. Any existing reviews for the questionnaire have been deleted!'
Method delete
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def delete
@questionnaire = Questionnaire.find(params[:id])
if @questionnaire
begin
name = @questionnaire.name
- 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 create
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def create
if params[:questionnaire][:name].blank?
flash[:error] = 'A rubric or survey must have a title.'
redirect_to controller: 'questionnaires', action: 'new', model: params[:questionnaire][:type], private: params[:questionnaire][:private]
else
- 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
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def update
# If 'Add' or 'Edit/View advice' is clicked, redirect appropriately
if params[:add_new_questions]
permitted_params = params.permit(:id, new_question: params[:new_question].keys)
redirect_to action: 'add_new_questions', id: permitted_params[:id], question: permitted_params[:new_question]
- 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 action_allowed?
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def action_allowed?
case params[:action]
when 'edit'
@questionnaire = Questionnaire.find(params[:id])
current_user_has_admin_privileges? ||
- 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
Extra blank line detected. Open
# Controller for Questionnaire objects
- Read upRead up
- Exclude checks
This cops checks for two or more consecutive blank lines.
Example:
# bad - It has two empty lines.
some_method
# one empty line
# two empty lines
some_method
# good
some_method
# one empty line
some_method
Trailing whitespace detected. Open
# for each of the question, it deletes the advice first
- Exclude checks
Missing top-level class documentation comment. Open
class QuestionnairesController < 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 2 (not 0) spaces for indenting an expression spanning multiple lines. Open
(current_user_is_a?('Instructor') && current_user_id?(@questionnaire.try(:instructor_id))) ||
- Read upRead up
- Exclude checks
This cop checks the indentation of the right hand side operand in binary operations that span more than one line.
Example:
# bad
if a +
b
something
end
# good
if a +
b
something
end
Favor modifier if
usage when having a single-line body. Another good alternative is the usage of control flow &&
/||
. Open
if !question.seq.nil? && question.seq > max_seq
- Read upRead up
- Exclude checks
Checks for if and unless statements that would fit on one line
if written as a modifier if/unless. The maximum line length is
configured in the Metrics/LineLength
cop.
Example:
# bad
if condition
do_stuff(bar)
end
unless qux.empty?
Foo.do_something
end
# good
do_stuff(bar) if condition
Foo.do_something unless qux.empty?
Use %i
or %I
for an array of symbols. Open
before_action [:create_questionnaire, :save], only: [:list]
- Read upRead up
- Exclude checks
This cop can check for array literals made up of symbols that are not using the %i() syntax.
Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.
Configuration option: MinSize
If set, arrays with fewer elements than this value will not trigger the
cop. For example, a MinSize of
3` will not enforce a style on an array
of 2 or fewer elements.
Example: EnforcedStyle: percent (default)
# good
%i[foo bar baz]
# bad
[:foo, :bar, :baz]
Example: EnforcedStyle: brackets
# good
[:foo, :bar, :baz]
# bad
%i[foo bar baz]
Use 2 (not 0) spaces for indenting an expression spanning multiple lines. Open
(current_user_is_a?('Teaching Assistant') && Ta.find(session[:user].id).is_instructor_or_co_ta?(@questionnaire)) ||
- Read upRead up
- Exclude checks
This cop checks the indentation of the right hand side operand in binary operations that span more than one line.
Example:
# bad
if a +
b
something
end
# good
if a +
b
something
end
Use 2 (not 0) spaces for indenting an expression spanning multiple lines. Open
(current_user_is_a?('Instructor') && Ta.get_my_instructors(@questionnaire.try(:instructor_id)).include?(session[:user].id))
- Read upRead up
- Exclude checks
This cop checks the indentation of the right hand side operand in binary operations that span more than one line.
Example:
# bad
if a +
b
something
end
# good
if a +
b
something
end
Use &&
instead of and
. Open
redirect_to controller: 'questions', action: 'save_questions', questionnaire_id: @questionnaire.id, questionnaire_type: @questionnaire.type and return unless @questionnaire.id.nil? || @questionnaire.id <= 0
- Read upRead up
- Exclude checks
This cop checks for uses of and
and or
, and suggests using &&
and
|| instead
. It can be configured to check only in conditions, or in
all contexts.
Example: EnforcedStyle: always (default)
# bad
foo.save and return
# bad
if foo and bar
end
# good
foo.save && return
# good
if foo && bar
end
Example: EnforcedStyle: conditionals
# bad
if foo and bar
end
# good
foo.save && return
# good
foo.save and return
# good
if foo && bar
end