zammad/zammad

View on GitHub
app/models/user.rb

Summary

Maintainability
F
5 days
Test Coverage

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

class User < ApplicationModel
  include CanBeImported
  include HasActivityStreamLog
  include ChecksClientNotification
  include HasHistory
Severity: Major
Found in app/models/user.rb - About 1 day to fix

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

    class User < ApplicationModel
      include CanBeImported
      include HasActivityStreamLog
      include ChecksClientNotification
      include HasHistory
    Severity: Major
    Found in app/models/user.rb - About 1 day to fix

      Method name_guess has a Cognitive Complexity of 36 (exceeds 5 allowed). Consider refactoring.
      Open

        def self.name_guess(string, email = nil)
          return if string.blank? && email.blank?
      
          string.strip!
          firstname = ''
      Severity: Minor
      Found in app/models/user.rb - About 5 hrs 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 destroy_move_dependency_ownership has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

        def destroy_move_dependency_ownership
          result = Models.references(self.class.to_s, id)
      
          user_columns = %w[created_by_id updated_by_id out_of_office_replacement_id origin_by_id owner_id archived_by_id published_by_id internal_by_id]
          result.each do |class_name, references|
      Severity: Minor
      Found in app/models/user.rb - About 4 hrs 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 validate_agent_limit_by_role has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

        def validate_agent_limit_by_role(role)
          return true if Setting.get('system_agent_limit').blank?
          return true if active != true
          return true if role.active != true
          return true if !role.with_permission?('ticket.agent')
      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 name_guess has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.name_guess(string, email = nil)
          return if string.blank? && email.blank?
      
          string.strip!
          firstname = ''
      Severity: Minor
      Found in app/models/user.rb - About 1 hr to fix

        Method destroy_move_dependency_ownership has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def destroy_move_dependency_ownership
            result = Models.references(self.class.to_s, id)
        
            user_columns = %w[created_by_id updated_by_id out_of_office_replacement_id origin_by_id owner_id archived_by_id published_by_id internal_by_id]
            result.each do |class_name, references|
        Severity: Minor
        Found in app/models/user.rb - About 1 hr to fix

          Method create_from_hash! has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.create_from_hash!(hash)
          
              url = ''
              hash['info']['urls']&.each_value do |local_url|
                next if local_url.blank?
          Severity: Minor
          Found in app/models/user.rb - About 1 hr to fix

            Method with_permissions has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def self.with_permissions(keys)
                if keys.class != Array
                  keys = [keys]
                end
                permission_ids = []
            Severity: Minor
            Found in app/models/user.rb - About 1 hr to fix

              Method with_permissions has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.with_permissions(keys)
                  if keys.class != Array
                    keys = [keys]
                  end
                  permission_ids = []
              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 validate_roles has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def validate_roles(role)
                  return true if !role_ids # we need role_ids for checking in role_ids below, in this method
                  return true if role.preferences[:not].blank?
              
                  role.preferences[:not].each do |local_role_name|
              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 validate_preferences has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def validate_preferences
                  return true if !changes
                  return true if !changes['preferences']
                  return true if preferences.blank?
                  return true if !preferences[:notification_sound]
              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 check_login has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def check_login
              
                  # use email as login if not given
                  if login.blank?
                    self.login = email
              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 check_name has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def check_name
                  self.firstname = sanitize_name(firstname)
                  self.lastname  = sanitize_name(lastname)
              
                  return if firstname.present? && lastname.present?
              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 create_from_hash! has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                def self.create_from_hash!(hash)
              
                  url = ''
                  hash['info']['urls']&.each_value do |local_url|
                    next if local_url.blank?
              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

              Avoid too many return statements within this method.
              Open

                  return if !User.exists?(email: email.downcase.strip)
              Severity: Major
              Found in app/models/user.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                      return true
                Severity: Major
                Found in app/models/user.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                      return true if !preferences[:notification_sound][:enabled]
                  Severity: Major
                  Found in app/models/user.rb - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status