discourse/discourse

View on GitHub
app/models/user.rb

Summary

Maintainability
F
1 wk
Test Coverage

Class User has 173 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 1224 lines of code (exceeds 250 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

      Method publish_notifications_state has 39 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 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

        Consider simplifying this complex logical expression.
        Open

            if title_changed? && !new_record? && user_profile
              badge_matching_title = title && badges.find do |badge|
                badge.allow_title? && (badge.display_name == title || badge.name == title)
              end
              user_profile.update(
        Severity: Major
        Found in app/models/user.rb - About 40 mins to fix

          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