18F/e-manifest

View on GitHub
app/services/user_session.rb

Summary

Maintainability
A
3 hrs
Test Coverage

Class has too many lines. [142/100]
Open

class UserSession
  attr_reader :session, :token

  TTL = 4 * 60 * 60
  @@ttl = TTL
Severity: Minor
Found in app/services/user_session.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Class UserSession has 29 methods (exceeds 20 allowed). Consider refactoring.
Open

class UserSession
  attr_reader :session, :token

  TTL = 4 * 60 * 60
  @@ttl = TTL
Severity: Minor
Found in app/services/user_session.rb - About 3 hrs to fix

    Trailing whitespace detected.
    Open

        
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

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

          ""
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    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"

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

      @@namespace = "user_session"
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    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"

    Replace class var @@namespace with a class instance var.
    Open

      @@namespace = "user_session"
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

    Use def with parentheses when there are parameters.
    Open

      def user=user
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

    Example: EnforcedStyle: require_parentheses (default)

    # The `require_parentheses` style requires method definitions
    # to always use parentheses
    
    # bad
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Example: EnforcedStyle: requirenoparentheses

    # The `require_no_parentheses` style requires method definitions
    # to never use parentheses
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end

    Example: EnforcedStyle: requirenoparenthesesexceptmultiline

    # The `require_no_parentheses_except_multiline` style prefers no
    # parantheses when method definition arguments fit on single line,
    # but prefers parantheses when arguments span multiple lines.
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Trailing whitespace detected.
    Open

          @session[:id] = @user.id  
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

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

        if payload
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    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?

    Space inside parentheses detected.
    Open

          User.find( get(:id) )
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    Checks for spaces inside ordinary round parentheses.

    Example:

    # bad
    f( 3)
    g = (a + 3 )
    
    # good
    f(3)
    g = (a + 3)

    Replace class var @@ttl with a class instance var.
    Open

      @@ttl = TTL
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

    Use attr_writer to define trivial writer methods.
    Open

      def user=user
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cop looks for trivial reader/writer methods, that could have been created with the attr_* family of functions automatically.

    Example:

    # bad
    def foo
      @foo
    end
    
    def bar=(val)
      @bar = val
    end
    
    def self.baz
      @baz
    end
    
    # good
    attr_reader :foo
    attr_writer :bar
    
    class << self
      attr_reader :baz
    end

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

        if @user
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    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?

    Trailing whitespace detected.
    Open

     
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    Replace class var @@namespace with a class instance var.
    Open

        @@namespace = namespace
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

    Space inside parentheses detected.
    Open

          User.find( get(:id) )
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    Checks for spaces inside ordinary round parentheses.

    Example:

    # bad
    f( 3)
    g = (a + 3 )
    
    # good
    f(3)
    g = (a + 3)

    Use a guard clause instead of wrapping the code inside a conditional expression.
    Open

        if payload
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    Use a guard clause instead of wrapping the code inside a conditional expression

    Example:

    # bad
    def test
      if something
        work
      end
    end
    
    # good
    def test
      return unless something
      work
    end
    
    # also good
    def test
      work if something
    end
    
    # bad
    if something
      raise 'exception'
    else
      ok
    end
    
    # good
    raise 'exception' if something
    ok

    Redundant self detected.
    Open

        session = self.new(SecureRandom.uuid, user)
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cop checks for redundant uses of self.

    The usage of self is only needed when:

    • Sending a message to same object with zero arguments in presence of a method name clash with an argument or a local variable.

    • Calling an attribute writer to prevent an local variable assignment.

    Note, with using explicit self you can only send messages with public or protected scope, you cannot send private messages this way.

    Note we allow uses of self with operators because it would be awkward otherwise.

    Example:

    # bad
    def foo(bar)
      self.baz
    end
    
    # good
    def foo(bar)
      self.bar  # Resolves name clash with the argument.
    end
    
    def foo
      bar = 1
      self.bar  # Resolves name clash with the local variable.
    end
    
    def foo
      %w[x y z].select do |bar|
        self.bar == bar  # Resolves name clash with argument of the block.
      end
    end

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

          ""
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    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"

    Trailing whitespace detected.
    Open

        
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    Put empty method definitions on a single line.
    Open

      def cdx_roles
    
      end
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cop checks for the formatting of empty method definitions. By default it enforces empty method definitions to go on a single line (compact style), but it can be configured to enforce the end to go on its own line (expanded style).

    Note: A method definition is not considered empty if it contains comments.

    Example: EnforcedStyle: compact (default)

    # bad
    def foo(bar)
    end
    
    def self.foo(bar)
    end
    
    # good
    def foo(bar); end
    
    def foo(bar)
      # baz
    end
    
    def self.foo(bar); end

    Example: EnforcedStyle: expanded

    # bad
    def foo(bar); end
    
    def self.foo(bar); end
    
    # good
    def foo(bar)
    end
    
    def self.foo(bar)
    end

    Use def with parentheses when there are parameters.
    Open

      def self.namespace=namespace
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

    Example: EnforcedStyle: require_parentheses (default)

    # The `require_parentheses` style requires method definitions
    # to always use parentheses
    
    # bad
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Example: EnforcedStyle: requirenoparentheses

    # The `require_no_parentheses` style requires method definitions
    # to never use parentheses
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end

    Example: EnforcedStyle: requirenoparenthesesexceptmultiline

    # The `require_no_parentheses_except_multiline` style prefers no
    # parantheses when method definition arguments fit on single line,
    # but prefers parantheses when arguments span multiple lines.
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Replace class var @@redis with a class instance var.
    Open

        @@redis ||= Redis::Namespace.new(@@namespace.to_sym, redis: Redis.new)
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

    Missing top-level class documentation comment.
    Open

    class UserSession
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

    The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

    Example:

    # bad
    class Person
      # ...
    end
    
    # good
    # Description/Explanation of Person class
    class Person
      # ...
    end

    Extra empty line detected at method body beginning.
    Open

    
      end
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cops checks if empty lines exist around the bodies of methods.

    Example:

    # good
    
    def foo
      # ...
    end
    
    # bad
    
    def bar
    
      # ...
    
    end

    Replace class var @@ttl with a class instance var.
    Open

        @@ttl = seconds.to_i
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cop checks for uses of class variables. Offenses are signaled only on assignment to class variables to reduce the number of offenses that would be reported.

    Use def with parentheses when there are parameters.
    Open

      def self.ttl=seconds
    Severity: Minor
    Found in app/services/user_session.rb by rubocop

    This cops checks for parentheses around the arguments in method definitions. Both instance and class/singleton methods are checked.

    Example: EnforcedStyle: require_parentheses (default)

    # The `require_parentheses` style requires method definitions
    # to always use parentheses
    
    # bad
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    Example: EnforcedStyle: requirenoparentheses

    # The `require_no_parentheses` style requires method definitions
    # to never use parentheses
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end

    Example: EnforcedStyle: requirenoparenthesesexceptmultiline

    # The `require_no_parentheses_except_multiline` style prefers no
    # parantheses when method definition arguments fit on single line,
    # but prefers parantheses when arguments span multiple lines.
    
    # bad
    def bar(num1, num2)
      num1 + num2
    end
    
    def foo descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name
      do_something
    end
    
    # good
    def bar num1, num2
      num1 + num2
    end
    
    def foo(descriptive_var_name,
            another_descriptive_var_name,
            last_descriptive_var_name)
      do_something
    end

    There are no issues that match your filters.

    Category
    Status