sumoners/dm_courier

View on GitHub
lib/dm_courier/message_helper.rb

Summary

Maintainability
A
1 hr
Test Coverage

Method attachments has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

      def attachments(filter = {})
        Enumerator.new do |y|
          attachments = mail.attachments
          attachments = if filter[:inline]
                          attachments.select(&:inline?)
Severity: Minor
Found in lib/dm_courier/message_helper.rb - About 1 hr to fix

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

          attachments = if filter[:inline]
                          attachments.select(&:inline?)
                        else
                          attachments.reject(&:inline?)
                        end if filter.key?(:inline)
Severity: Minor
Found in lib/dm_courier/message_helper.rb by rubocop

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

        value.to_s == "true" ? true : false
Severity: Minor
Found in lib/dm_courier/message_helper.rb by rubocop

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

        json
          .merge!(Hash[
            params[:string].map { |name, key| [name.to_sym, return_string_value(key.to_sym)] }
          ]) if params.key?(:string)
Severity: Minor
Found in lib/dm_courier/message_helper.rb by rubocop

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

        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)
Severity: Minor
Found in lib/dm_courier/message_helper.rb by rubocop

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

There are no issues that match your filters.

Category
Status