lib/dm_courier/message_helper.rb
Method attachments
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
Open
def attachments(filter = {})
Enumerator.new do |y|
attachments = mail.attachments
attachments = if filter[:inline]
attachments.select(&:inline?)
- 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
Favor a normal if-statement over a modifier clause in a multiline statement. Open
Open
attachments = if filter[:inline]
attachments.select(&:inline?)
else
attachments.reject(&:inline?)
end if filter.key?(:inline)
- Read upRead up
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond
This conditional expression can just be replaced by value.to_s == "true"
. Open
Open
value.to_s == "true" ? true : false
- Read upRead up
- Exclude checks
This cop checks for redundant returning of true/false in conditionals.
Example:
# bad
x == y ? true : false
# bad
if x == y
true
else
false
end
# good
x == y
# bad
x == y ? false : true
# good
x != y
Favor a normal if-statement over a modifier clause in a multiline statement. Open
Open
json
.merge!(Hash[
params[:string].map { |name, key| [name.to_sym, return_string_value(key.to_sym)] }
]) if params.key?(:string)
- Read upRead up
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond
Favor a normal if-statement over a modifier clause in a multiline statement. Open
Open
json
.merge!(Hash[
params[:nil_true_false].map { |name, key| [name.to_sym, nil_true_false?(key.to_sym)] }
]) if params.key?(:nil_true_false)
- Read upRead up
- Exclude checks
Checks for uses of if/unless modifiers with multiple-lines bodies.
Example:
# bad
{
result: 'this should not happen'
} unless cond
# good
{ result: 'ok' } if cond