Method help_menu_form_field_changed
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def help_menu_form_field_changed
assert_privileges("region_edit")
return unless load_edit('customize_help_menu')
- Read upRead up
- Create a ticketCreate a ticket
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 settings_update_help_menu
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def settings_update_help_menu
assert_privileges("region_edit")
return unless load_edit('customize_help_menu')
- Read upRead up
- Create a ticketCreate a ticket
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 immutable Array literals in loops. It is better to extract it into a local variable or a constant. Open
%i[title href type].map do |field|
- Create a ticketCreate a ticket
- Exclude checks
Do not shadow rescued Exceptions. Open
rescue Psych::SyntaxError, StandardError
add_flash(_('Invalid configuration parameters.'), :error)
success = false
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
Checks for a rescued exception that get shadowed by a less specific exception being rescued before a more specific exception is rescued.
An exception is considered shadowed if it is rescued after its
ancestor is, or if it and its ancestor are both rescued in the
same rescue
statement. In both cases, the more specific rescue is
unnecessary because it is covered by rescuing the less specific
exception. (ie. rescue Exception, StandardError
has the same behavior
whether StandardError
is included or not, because all StandardError
s
are rescued by rescue Exception
).
Example:
# bad
begin
something
rescue Exception
handle_exception
rescue StandardError
handle_standard_error
end
# bad
begin
something
rescue Exception, StandardError
handle_error
end
# good
begin
something
rescue StandardError
handle_standard_error
rescue Exception
handle_exception
end
# good, however depending on runtime environment.
#
# This is a special case for system call errors.
# System dependent error code depends on runtime environment.
# For example, whether `Errno::EAGAIN` and `Errno::EWOULDBLOCK` are
# the same error code or different error code depends on environment.
# This good case is for `Errno::EAGAIN` and `Errno::EWOULDBLOCK` with
# the same error code.
begin
something
rescue Errno::EAGAIN, Errno::EWOULDBLOCK
handle_standard_error
end