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
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
- Read upRead up
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
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
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')
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?
- Read upRead up
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|
Method perform_triggers
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def self.perform_triggers(ticket, article, triggers, item, options = {})
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?
- Read upRead up
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?
Avoid too many return
statements within this method. Open
return if user_ids_ignore.include?(user.id)
Avoid too many return
statements within this method. Open
return if organization.present? && customer.organization_id?(organization.id)
Avoid too many return
statements within this method. Open
return if ticket_count.to_i.zero?
Avoid too many return
statements within this method. Open
return true if owner.active? && owner.permissions?('ticket.agent') && owner.group_access?(group_id, 'full')
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'
- Read upRead up
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)
- Read upRead up
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"