sanger/sequencescape

View on GitHub
app/models/user.rb

Summary

Maintainability
A
2 hrs
Test Coverage
A
91%

Class User has 24 methods (exceeds 20 allowed). Consider refactoring.
Open

class User < ApplicationRecord # rubocop:todo Metrics/ClassLength
  include Authentication
  extend EventfulRecord
  include Uuid::Uuidable
  include Swipecardable
Severity: Minor
Found in app/models/user.rb - About 2 hrs to fix

    User has at least 19 methods
    Open

    class User < ApplicationRecord # rubocop:todo Metrics/ClassLength
    Severity: Minor
    Found in app/models/user.rb by reek

    Too Many Methods is a special case of LargeClass.

    Example

    Given this configuration

    TooManyMethods:
      max_methods: 3

    and this code:

    class TooManyMethods
      def one; end
      def two; end
      def three; end
      def four; end
    end

    Reek would emit the following warning:

    test.rb -- 1 warning:
      [1]:TooManyMethods has at least 4 methods (TooManyMethods)

    User#self.sequencescape calls 'configatron.sequencescape_email' 2 times
    Open

        find_or_create_by!(login: configatron.sequencescape_email, email: configatron.sequencescape_email)
    Severity: Minor
    Found in app/models/user.rb by reek

    Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

    Reek implements a check for Duplicate Method Call.

    Example

    Here's a very much simplified and contrived example. The following method will report a warning:

    def double_thing()
      @other.thing + @other.thing
    end

    One quick approach to silence Reek would be to refactor the code thus:

    def double_thing()
      thing = @other.thing
      thing + thing
    end

    A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

    class Other
      def double_thing()
        thing + thing
      end
    end

    The approach you take will depend on balancing other factors in your code.

    User#password is a writable attribute
    Open

      attr_accessor :password
    Severity: Minor
    Found in app/models/user.rb by reek

    A class that publishes a setter for an instance variable invites client classes to become too intimate with its inner workings, and in particular with its representation of state.

    The same holds to a lesser extent for getters, but Reek doesn't flag those.

    Example

    Given:

    class Klass
      attr_accessor :dummy
    end

    Reek would emit the following warning:

    reek test.rb
    
    test.rb -- 1 warning:
      [2]:Klass declares the writable attribute dummy (Attribute)

    User#new_api_key has the variable name 'k'
    Open

        k = Digest::SHA1.hexdigest(Time.zone.now.to_s + rand(12_341_234).to_s)[1..length]
    Severity: Minor
    Found in app/models/user.rb by reek

    An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

    Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

    User#new_api_key has the variable name 'u'
    Open

        u = Digest::SHA1.hexdigest(login)[0..12]
    Severity: Minor
    Found in app/models/user.rb by reek

    An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

    Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

    There are no issues that match your filters.

    Category
    Status