Method update
has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring. Open
def update
problem = Problem.find(params[:id])
if !params[:privacy].nil?
authorize! :set_privacy, problem
- 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 has too many lines. [63/30] Open
def update
problem = Problem.find(params[:id])
if !params[:privacy].nil?
authorize! :set_privacy, problem
- 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. [48/30] Open
def create
parent_uid = params[:parent_uid]
if parent_uid
previous_version = Problem.find_by_uid(params[:parent_uid])
if !previous_version
- 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 update is too high. [22/6] Open
def update
problem = Problem.find(params[:id])
if !params[:privacy].nil?
authorize! :set_privacy, problem
- 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 update
has 63 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update
problem = Problem.find(params[:id])
if !params[:privacy].nil?
authorize! :set_privacy, problem
Cyclomatic complexity for create is too high. [11/6] Open
def create
parent_uid = params[:parent_uid]
if parent_uid
previous_version = Problem.find_by_uid(params[:parent_uid])
if !previous_version
- 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 create
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def create
parent_uid = params[:parent_uid]
if parent_uid
previous_version = Problem.find_by_uid(params[:parent_uid])
if !previous_version
- 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
Cyclomatic complexity for set_filters is too high. [9/6] Open
def set_filters
session[:filters] = session[:filters].merge params.slice(:search, :tags, :sort_by)
if session[:filters][:tags].is_a? String
session[:filters][:tags] = self.class.parse_list session[:filters][:tags]
- 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 create
has 48 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
parent_uid = params[:parent_uid]
if parent_uid
previous_version = Problem.find_by_uid(params[:parent_uid])
if !previous_version
Method set_filters
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def set_filters
session[:filters] = session[:filters].merge params.slice(:search, :tags, :sort_by)
if session[:filters][:tags].is_a? String
session[:filters][:tags] = self.class.parse_list session[:filters][:tags]
- 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 set_filters
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
def set_filters
session[:filters] = session[:filters].merge params.slice(:search, :tags, :sort_by)
if session[:filters][:tags].is_a? String
session[:filters][:tags] = self.class.parse_list session[:filters][:tags]
Method update_multiple_tags
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def update_multiple_tags
new_tags = self.class.parse_list params[:tag_names]
selected = params[:checked_problems] ? params[:checked_problems].keys : []
if new_tags == []
flash[:error] = "You need to enter a tag."
- 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 rescuing the Exception
class. Perhaps you meant to rescue StandardError
? Open
rescue Exception => e
if request.xhr?
render :json => {'error' => e.message}
else
flash[:error] = "Error in problem source: #{e.message}. A Question's unique ID may already exist in database."
- Read upRead up
- Exclude checks
This cop checks for rescue blocks targeting the Exception class.
Example:
# bad
begin
do_something
rescue Exception
handle_exception
end
Example:
# good
begin
do_something
rescue ArgumentError
handle_exception
end
Unused block argument - value
. If it's necessary, use _
or _value
as an argument name to indicate that it won't be used. Open
params[:collections].each do |key, value|
- Read upRead up
- Exclude checks
This cop checks for unused block arguments.
Example:
# bad
do_something do |used, unused|
puts used
end
do_something do |bar|
puts :foo
end
define_method(:foo) do |bar|
puts :baz
end
Example:
#good
do_something do |used, _unused|
puts used
end
do_something do
puts :foo
end
define_method(:foo) do |_bar|
puts :baz
end