expertiza/expertiza

View on GitHub
app/models/user.rb

Summary

Maintainability
C
7 hrs
Test Coverage
F
49%

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

class User < ApplicationRecord
  enum locale: Locale.code_name_to_db_encoding(Locale.available_locale_preferences)
  acts_as_authentic do |config|
    config.validates_uniqueness_of_email_field_options = { if: -> { false } } # Don't validate email uniqueness
    config.crypto_provider = Authlogic::CryptoProviders::Sha1
Severity: Minor
Found in app/models/user.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 User has 32 methods (exceeds 20 allowed). Consider refactoring.
Open

class User < ApplicationRecord
  enum locale: Locale.code_name_to_db_encoding(Locale.available_locale_preferences)
  acts_as_authentic do |config|
    config.validates_uniqueness_of_email_field_options = { if: -> { false } } # Don't validate email uniqueness
    config.crypto_provider = Authlogic::CryptoProviders::Sha1
Severity: Minor
Found in app/models/user.rb - About 4 hrs to fix

    Assignment Branch Condition size for export is too high. [34.58/15]
    Open

      def self.export(csv, _parent_id, options)
        users = User.all
        users.each do |user|
          tcsv = []
          tcsv.push(user.name, user.fullname, user.email) if options['personal_details'] == 'true'
    Severity: Minor
    Found in app/models/user.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Assignment Branch Condition size for export_fields is too high. [19/15]
    Open

      def self.export_fields(options)
        fields = []
        fields.push('name', 'full name', 'email') if options['personal_details'] == 'true'
        fields.push('role') if options['role'] == 'true'
        fields.push('parent') if options['parent'] == 'true'
    Severity: Minor
    Found in app/models/user.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Assignment Branch Condition size for get_user_list is too high. [18.47/15]
    Open

      def get_user_list
        user_list = []
        # If the user is a super admin, fetch all users
        user_list = SuperAdministrator.get_user_list if role.super_admin?
    
    
    Severity: Minor
    Found in app/models/user.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Method has too many lines. [12/10]
    Open

      def get_user_list
        user_list = []
        # If the user is a super admin, fetch all users
        user_list = SuperAdministrator.get_user_list if role.super_admin?
    
    
    Severity: Minor
    Found in app/models/user.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.

    Method has too many lines. [12/10]
    Open

      def self.import(row_hash, _row_header, session, _id = nil)
        raise ArgumentError, "Only #{row_hash.length} column(s) is(are) found. It must contain at least username, full name, email." if row_hash.length < 3
    
        user = User.find_by_name(row_hash[:username])
        if user.nil?
    Severity: Minor
    Found in app/models/user.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.

    Method has too many lines. [11/10]
    Open

      def self.export(csv, _parent_id, options)
        users = User.all
        users.each do |user|
          tcsv = []
          tcsv.push(user.name, user.fullname, user.email) if options['personal_details'] == 'true'
    Severity: Minor
    Found in app/models/user.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 export_fields is too high. [7/6]
    Open

      def self.export_fields(options)
        fields = []
        fields.push('name', 'full name', 'email') if options['personal_details'] == 'true'
        fields.push('role') if options['role'] == 'true'
        fields.push('parent') if options['parent'] == 'true'
    Severity: Minor
    Found in app/models/user.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.

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

      def get_user_list
        user_list = []
        # If the user is a super admin, fetch all users
        user_list = SuperAdministrator.get_user_list if role.super_admin?
    
    
    Severity: Minor
    Found in app/models/user.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.

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

      def self.export(csv, _parent_id, options)
        users = User.all
        users.each do |user|
          tcsv = []
          tcsv.push(user.name, user.fullname, user.email) if options['personal_details'] == 'true'
    Severity: Minor
    Found in app/models/user.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 has too many lines. [11/10]
    Open

      def generate_keys
        # check if we are replacing a digital certificate already generated
        replacing_key = true unless digital_certificate.nil?
    
        # generate the new key pair
    Severity: Minor
    Found in app/models/user.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.

    Assignment Branch Condition size for import is too high. [15.36/15]
    Open

      def self.import(row_hash, _row_header, session, _id = nil)
        raise ArgumentError, "Only #{row_hash.length} column(s) is(are) found. It must contain at least username, full name, email." if row_hash.length < 3
    
        user = User.find_by_name(row_hash[:username])
        if user.nil?
    Severity: Minor
    Found in app/models/user.rb by rubocop

    This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric

    Method get_user_list has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

      def get_user_list
        user_list = []
        # If the user is a super admin, fetch all users
        user_list = SuperAdministrator.get_user_list if role.super_admin?
    
    
    Severity: Minor
    Found in app/models/user.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

    Method export has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.export(csv, _parent_id, options)
        users = User.all
        users.each do |user|
          tcsv = []
          tcsv.push(user.name, user.fullname, user.email) if options['personal_details'] == 'true'
    Severity: Minor
    Found in app/models/user.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

    Method export_fields has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.export_fields(options)
        fields = []
        fields.push('name', 'full name', 'email') if options['personal_details'] == 'true'
        fields.push('role') if options['role'] == 'true'
        fields.push('parent') if options['parent'] == 'true'
    Severity: Minor
    Found in app/models/user.rb - About 25 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

    Method generate_keys has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

      def generate_keys
        # check if we are replacing a digital certificate already generated
        replacing_key = true unless digital_certificate.nil?
    
        # generate the new key pair
    Severity: Minor
    Found in app/models/user.rb - About 25 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

    Do not prefix reader method names with get_.
    Open

      def get_instructor
    Severity: Minor
    Found in app/models/user.rb by rubocop

    This cop makes sure that accessor methods are named properly.

    Example:

    # bad
    def set_attribute(value)
    end
    
    # good
    def attribute=(value)
    end
    
    # bad
    def get_attribute
    end
    
    # good
    def attribute
    end

    Do not introduce global variables.
    Open

        anonymized_view_starter_ips = $redis.get('anonymized_view_starter_ips') || ''
    Severity: Minor
    Found in app/models/user.rb by rubocop

    This cops looks for uses of global variables. It does not report offenses for built-in global variables. Built-in global variables are allowed by default. Additionally users can allow additional variables via the AllowedVariables option.

    Note that backreferences like $1, $2, etc are not global variables.

    Example:

    # bad
    $foo = 2
    bar = $foo + 5
    
    # good
    FOO = 2
    foo = 2
    $stdin.read

    Do not prefix writer method names with set_.
    Open

      def set_instructor(new_assignment)
    Severity: Minor
    Found in app/models/user.rb by rubocop

    This cop makes sure that accessor methods are named properly.

    Example:

    # bad
    def set_attribute(value)
    end
    
    # good
    def attribute=(value)
    end
    
    # bad
    def get_attribute
    end
    
    # good
    def attribute
    end

    Do not prefix reader method names with get_.
    Open

      def get_user_list
    Severity: Minor
    Found in app/models/user.rb by rubocop

    This cop makes sure that accessor methods are named properly.

    Example:

    # bad
    def set_attribute(value)
    end
    
    # good
    def attribute=(value)
    end
    
    # bad
    def get_attribute
    end
    
    # good
    def attribute
    end

    Missing top-level class documentation comment.
    Open

    class User < ApplicationRecord
    Severity: Minor
    Found in app/models/user.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

    There are no issues that match your filters.

    Category
    Status