discourse/discourse

View on GitHub
app/models/user.rb

Summary

Maintainability
F
6 days
Test Coverage

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

class User < ActiveRecord::Base
  include Searchable
  include Roleable
  include HasCustomFields
  include SecondFactorManager
Severity: Major
Found in app/models/user.rb - About 3 days to fix

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

    require_dependency 'jobs/base'
    require_dependency 'email'
    require_dependency 'email_token'
    require_dependency 'email_validator'
    require_dependency 'trust_level'
    Severity: Major
    Found in app/models/user.rb - About 2 days to fix

      Method publish_notifications_state has 41 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def publish_notifications_state
          # publish last notification json with the message so we can apply an update
          notification = notifications.visible.order('notifications.created_at desc').first
          json = NotificationSerializer.new(notification).as_json if notification
      
      
      Severity: Minor
      Found in app/models/user.rb - About 1 hr to fix

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

          def update_posts_read!(num_posts, opts = {})
            now = opts[:at] || Time.zone.now
            _retry = opts[:retry] || false
        
            if user_visit = visit_record_for(now.to_date)
        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 whitelisted_user_custom_fields has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
        Open

          def self.whitelisted_user_custom_fields(guardian)
            fields = []
        
            plugin_public_user_custom_fields.each do |k, v|
              fields << k if v.enabled?
        Severity: Minor
        Found in app/models/user.rb - About 55 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 username_validator has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
        Open

          def username_validator
            username_format_validator || begin
              if will_save_change_to_username?
                existing = DB.query(
                  USERNAME_EXISTS_SQL,
        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 set_random_avatar has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

          def set_random_avatar
            if SiteSetting.selectable_avatars_enabled? && SiteSetting.selectable_avatars.present?
              urls = SiteSetting.selectable_avatars.split("\n")
              if urls.present?
                if upload = Upload.find_by(url: urls.sample)
        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 set_default_categories_preferences has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

          def set_default_categories_preferences
            return if self.staged?
        
            values = []
        
        
        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