app/services/redemption_batch_updater.rb
Method update
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
Open
def update
# Transactionally add one or more vouchertypes to multiple showdates.
# If errors, collate them intelligently and fail.
# If +valid_voucher_params+ includes a key
# <tt>:before_showtime => val</tt>, then each valid voucher's end-sales should be overridden to be
- 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
Unused block argument - v
. If it's necessary, use _
or _v
as an argument name to indicate that it won't be used. Open
Open
args.reject! { |k,v| k =~ /end_sales/ } if preserve[:end_sales]
- 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
Unused block argument - v
. If it's necessary, use _
or _v
as an argument name to indicate that it won't be used. Open
Open
args.reject! { |k,v| k =~ /start_sales/ } if preserve[:start_sales]
- 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