testmycode/tmc-server

View on GitHub
app/models/user.rb

Summary

Maintainability
C
1 day
Test Coverage

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

class User < ApplicationRecord
  include Comparable
  include Gravtastic
  include Swagger::Blocks
  gravtastic
Severity: Minor
Found in app/models/user.rb - About 5 hrs to fix

    File user.rb has 289 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class User < ApplicationRecord
      include Comparable
      include Gravtastic
      include Swagger::Blocks
      gravtastic
    Severity: Minor
    Found in app/models/user.rb - About 2 hrs to fix

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

        def self.filter_by(filter_params)
          users = includes(:user_field_values)
      
          users = users.where(administrator: false) unless filter_params['include_administrators']
      
      
      Severity: Minor
      Found in app/models/user.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

      Method courses_with_submissions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

        def courses_with_submissions
          exercises = Exercise.arel_table
          submissions = Submission.arel_table
          query = submissions_exercises_and_points_for_user
          without_disabled(query)
      Severity: Minor
      Found in app/models/user.rb - About 35 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 reject_common_login_mistakes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
      Open

          def reject_common_login_mistakes
            return if login.blank?
            errors.add(:login, 'may not be your email address. Keep in mind that your username is public to everyone.') if login.include?('@')
            errors.add(:login, 'may not be a number. Use the organizational identifier field for your student number.') if login.scan(/\D/).empty?
            errors.add(:email, 'may not end with "@ad.helsinki.fi". You cannot receive any emails with this address -- it\'s only used for your webmail login. Figure out what your real email address is and try again. It is usually of the form firstname.lastname@helsinki.fi but verify this first.') if email.end_with?('@ad.helsinki.fi')
      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

      There are no issues that match your filters.

      Category
      Status