datamolecule/door_mat

View on GitHub
app/models/door_mat/session.rb

Summary

Maintainability
C
7 hrs
Test Coverage

Class Session has 28 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Session < ActiveRecord::Base

    belongs_to :actor
    belongs_to :email

Severity: Minor
Found in app/models/door_mat/session.rb - About 3 hrs to fix

    Method has too many lines. [40/30]
    Open

        def self.from(cookies, request)
          clear_current_session
          session_guid = cookies.encrypted[:session_guid].to_s.strip
          session_key = cookies.encrypted[:session_key].to_s.strip
    
    
    Severity: Minor
    Found in app/models/door_mat/session.rb by rubocop

    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.

    Cyclomatic complexity for from is too high. [13/6]
    Open

        def self.from(cookies, request)
          clear_current_session
          session_guid = cookies.encrypted[:session_guid].to_s.strip
          session_key = cookies.encrypted[:session_key].to_s.strip
    
    
    Severity: Minor
    Found in app/models/door_mat/session.rb by rubocop

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

    Method from has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.from(cookies, request)
          clear_current_session
          session_guid = cookies.encrypted[:session_guid].to_s.strip
          session_key = cookies.encrypted[:session_key].to_s.strip
    
    
    Severity: Minor
    Found in app/models/door_mat/session.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

    Cyclomatic complexity for with_session_for_actor is too high. [7/6]
    Open

        def with_session_for_actor(actor)
          if self.valid? && (actor.nil? || self.actor_id.nil? || self.actor == actor)
            yield(self)
          elsif !actor.nil? && (sub_sessions.has_key? actor.id)
            yield(sub_sessions[actor.id])
    Severity: Minor
    Found in app/models/door_mat/session.rb by rubocop

    This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

    An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

    Method from has 40 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def self.from(cookies, request)
          clear_current_session
          session_guid = cookies.encrypted[:session_guid].to_s.strip
          session_key = cookies.encrypted[:session_key].to_s.strip
    
    
    Severity: Minor
    Found in app/models/door_mat/session.rb - About 1 hr to fix

      Avoid too many return statements within this method.
      Open

                  return nil
      Severity: Major
      Found in app/models/door_mat/session.rb - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                    return nil
        Severity: Major
        Found in app/models/door_mat/session.rb - About 30 mins to fix

          Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?
          Open

              rescue Exception => e
                reset
                DoorMat.configuration.logger.error "ERROR: Failed to initialize session with password for actor #{actor.id} - #{e}"
          
                nil
          Severity: Minor
          Found in app/models/door_mat/session.rb by rubocop

          This cop checks for rescue blocks targeting the Exception class.

          Example:

          # bad
          
          begin
            do_something
          rescue Exception
            handle_exception
          end

          Example:

          # good
          
          begin
            do_something
          rescue ArgumentError
            handle_exception
          end

          Avoid rescuing the Exception class. Perhaps you meant to rescue StandardError?
          Open

              rescue Exception => e
                reset
                DoorMat.configuration.logger.error "ERROR: Failed to unlock session with session_key for actor #{self.actor.id} - #{e}"
                false
          Severity: Minor
          Found in app/models/door_mat/session.rb by rubocop

          This cop checks for rescue blocks targeting the Exception class.

          Example:

          # bad
          
          begin
            do_something
          rescue Exception
            handle_exception
          end

          Example:

          # good
          
          begin
            do_something
          rescue ArgumentError
            handle_exception
          end

          There are no issues that match your filters.

          Category
          Status