infusionvlc/infusion

View on GitHub
app/controllers/sessions_controller.rb

Summary

Maintainability
A
1 hr
Test Coverage

Method has too many lines. [28/20]
Open

  def create
    auth = request.env['omniauth.auth']
    @identity = Identity.find_with_omniauth(auth)

    if @identity.nil?

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.

Perceived complexity for create is too high. [10/7]
Open

  def create
    auth = request.env['omniauth.auth']
    @identity = Identity.find_with_omniauth(auth)

    if @identity.nil?

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Method create has 28 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def create
    auth = request.env['omniauth.auth']
    @identity = Identity.find_with_omniauth(auth)

    if @identity.nil?
Severity: Minor
Found in app/controllers/sessions_controller.rb - About 1 hr to fix

    Method create has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

      def create
        auth = request.env['omniauth.auth']
        @identity = Identity.find_with_omniauth(auth)
    
        if @identity.nil?
    Severity: Minor
    Found in app/controllers/sessions_controller.rb - About 45 mins 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

    Prefer to_s over string interpolation.
    Open

            redirect_to meetups_path, notice: "#{I18n.t 'user.already_linked'}"

    This cop checks for strings that are just an interpolated expression.

    Example:

    # bad
    "#{@var}"
    
    # good
    @var.to_s
    
    # good if @var is already a String
    @var

    Prefer to_s over string interpolation.
    Open

              redirect_to meetups_path, flash: { error: "#{I18n.t 'user.error_sign_up'}" }

    This cop checks for strings that are just an interpolated expression.

    Example:

    # bad
    "#{@var}"
    
    # good
    @var.to_s
    
    # good if @var is already a String
    @var

    Convert if nested inside else to elsif.
    Open

          if @identity.user.present?

    If the else branch of a conditional consists solely of an if node, it can be combined with the else to become an elsif. This helps to keep the nesting level from getting too deep.

    Example:

    # bad
    if condition_a
      action_a
    else
      if condition_b
        action_b
      else
        action_c
      end
    end
    
    # good
    if condition_a
      action_a
    elsif condition_b
      action_b
    else
      action_c
    end

    Convert if nested inside else to elsif.
    Open

            if User.find_by_email(auth[:info][:email])

    If the else branch of a conditional consists solely of an if node, it can be combined with the else to become an elsif. This helps to keep the nesting level from getting too deep.

    Example:

    # bad
    if condition_a
      action_a
    else
      if condition_b
        action_b
      else
        action_c
      end
    end
    
    # good
    if condition_a
      action_a
    elsif condition_b
      action_b
    else
      action_c
    end

    Line is too long. [86/80]
    Open

              redirect_to meetups_path, flash: { error: "#{I18n.t 'user.error_sign_up'}" }

    Prefer to_s over string interpolation.
    Open

            redirect_to meetups_path, notice: "#{I18n.t 'user.logged_in'}"

    This cop checks for strings that are just an interpolated expression.

    Example:

    # bad
    "#{@var}"
    
    # good
    @var.to_s
    
    # good if @var is already a String
    @var

    Extra empty line detected at class body beginning.
    Open

    
      # POST /sessions

    This cops checks if empty lines around the bodies of classes match the configuration.

    Example: EnforcedStyle: empty_lines

    # good
    
    class Foo
    
      def bar
        # ...
      end
    
    end

    Example: EnforcedStyle: emptylinesexcept_namespace

    # good
    
    class Foo
      class Bar
    
        # ...
    
      end
    end

    Example: EnforcedStyle: emptylinesspecial

    # good
    class Foo
    
      def bar; end
    
    end

    Example: EnforcedStyle: noemptylines (default)

    # good
    
    class Foo
      def bar
        # ...
      end
    end

    Favor modifier if usage when having a single-line body. Another good alternative is the usage of control flow &&/||.
    Open

        if @identity.nil?

    Checks for if and unless statements that would fit on one line if written as a modifier if/unless. The maximum line length is configured in the Metrics/LineLength cop.

    Example:

    # bad
    if condition
      do_stuff(bar)
    end
    
    unless qux.empty?
      Foo.do_something
    end
    
    # good
    do_stuff(bar) if condition
    Foo.do_something unless qux.empty?

    Prefer to_s over string interpolation.
    Open

            redirect_to meetups_path, notice: "#{I18n.t 'user.linked'}"

    This cop checks for strings that are just an interpolated expression.

    Example:

    # bad
    "#{@var}"
    
    # good
    @var.to_s
    
    # good if @var is already a String
    @var

    Prefer to_s over string interpolation.
    Open

              redirect_to meetups_path, notice: "#{I18n.t 'user.logged_in'}"

    This cop checks for strings that are just an interpolated expression.

    Example:

    # bad
    "#{@var}"
    
    # good
    @var.to_s
    
    # good if @var is already a String
    @var

    Prefer single-quoted strings when you don't need string interpolation or special symbols.
    Open

        redirect_to meetups_path, notice: "Signed out!"

    Checks if uses of quotes match the configured preference.

    Example: EnforcedStyle: single_quotes (default)

    # bad
    "No special symbols"
    "No string interpolation"
    "Just text"
    
    # good
    'No special symbols'
    'No string interpolation'
    'Just text'
    "Wait! What's #{this}!"

    Example: EnforcedStyle: double_quotes

    # bad
    'Just some text'
    'No special chars or interpolation'
    
    # good
    "Just some text"
    "No special chars or interpolation"
    "Every string in #{project} uses double_quotes"

    There are no issues that match your filters.

    Category
    Status