zammad/zammad

View on GitHub
app/models/ticket.rb

Summary

Maintainability
F
3 days
Test Coverage

File ticket.rb has 516 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class Ticket < ApplicationModel
  include CanBeImported
  include HasActivityStreamLog
  include ChecksClientNotification
  include CanCsvImport
Severity: Major
Found in app/models/ticket.rb - About 1 day to fix

    Method perform_triggers has a Cognitive Complexity of 46 (exceeds 5 allowed). Consider refactoring.
    Open

      def self.perform_triggers(ticket, article, triggers, item, options = {})
        recursive = Setting.get('ticket_trigger_recursive')
        type = options[:type] || item[:type]
        local_options = options.clone
        local_options[:type] = type
    Severity: Minor
    Found in app/models/ticket.rb - About 7 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 merge_to has 77 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def merge_to(data)
    
        # prevent cross merging tickets
        target_ticket = Ticket.find_by(id: data[:ticket_id])
        raise 'no target ticket given' if !target_ticket
    Severity: Major
    Found in app/models/ticket.rb - About 3 hrs to fix

      Method perform_triggers has 75 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def self.perform_triggers(ticket, article, triggers, item, options = {})
          recursive = Setting.get('ticket_trigger_recursive')
          type = options[:type] || item[:type]
          local_options = options.clone
          local_options[:type] = type
      Severity: Major
      Found in app/models/ticket.rb - About 3 hrs to fix

        Method process_pending has 47 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def self.process_pending
            result = []
        
            # process pending action tickets
            pending_action = Ticket::StateType.find_by(name: 'pending action')
        Severity: Minor
        Found in app/models/ticket.rb - About 1 hr to fix

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

            def self.process_auto_unassign
          
              # process pending action tickets
              state_ids = Ticket::State.by_category_ids(:work_on)
              return [] if state_ids.blank?
          Severity: Minor
          Found in app/models/ticket.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 process_escalation has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.process_escalation
              result = []
          
              # fetch all escalated and soon to be escalating tickets
              where('escalation_at <= ?', 15.minutes.from_now).find_each(batch_size: 500) do |ticket|
          Severity: Minor
          Found in app/models/ticket.rb - About 1 hr to fix

            Method perform_triggers has 5 arguments (exceeds 4 allowed). Consider refactoring.
            Open

              def self.perform_triggers(ticket, article, triggers, item, options = {})
            Severity: Minor
            Found in app/models/ticket.rb - About 35 mins to fix

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

                def auto_assign(user)
                  return if !persisted?
                  return if Setting.get('ticket_auto_assignment').blank?
                  return if owner_id != 1
                  return if !TicketPolicy.new(user, self).full?
              Severity: Minor
              Found in app/models/ticket.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 ticket_auto_assignment_selector.blank?
              Severity: Major
              Found in app/models/ticket.rb - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                    return if user_ids_ignore.include?(user.id)
                Severity: Major
                Found in app/models/ticket.rb - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                      return if organization.present? && customer.organization_id?(organization.id)
                  Severity: Major
                  Found in app/models/ticket.rb - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                        return if ticket_count.to_i.zero?
                    Severity: Major
                    Found in app/models/ticket.rb - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                          return true if owner.active? && owner.permissions?('ticket.agent') && owner.group_access?(group_id, 'full')
                      Severity: Major
                      Found in app/models/ticket.rb - About 30 mins to fix

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

                          def check_owner_active
                            return true if Setting.get('import_mode')
                        
                            # only change the owner for non closed Tickets for historical/reporting reasons
                            return true if state.present? && Ticket::StateType.lookup(id: state.state_type_id)&.name == 'closed'
                        Severity: Minor
                        Found in app/models/ticket.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 check_default_organization has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                          def check_default_organization
                            return if !has_attribute?(:organization_id)
                            return if !customer_id
                        
                            customer = User.find_by(id: customer_id)
                        Severity: Minor
                        Found in app/models/ticket.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