File chat.rb
has 459 lines of code (exceeds 250 allowed). Consider refactoring. Open
class Chat < ApplicationModel
include ChecksHtmlSanitized
has_many :sessions, dependent: :destroy
Class Chat
has 24 methods (exceeds 20 allowed). Consider refactoring. Open
class Chat < ApplicationModel
include ChecksHtmlSanitized
has_many :sessions, dependent: :destroy
Method customer_state
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
def customer_state(session_id = nil)
return { state: 'chat_disabled' } if !Setting.get('chat')
# reconnect
if session_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"
Further reading
Method customer_state
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def customer_state(session_id = nil)
return { state: 'chat_disabled' } if !Setting.get('chat')
# reconnect
if session_id
Method agent_state
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.agent_state(user_id)
return { state: 'chat_disabled' } if !Setting.get('chat')
current_user = User.lookup(id: user_id)
return { error: "No such user with id: #{user_id}" } if !current_user
Method broadcast_agent_state_update
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def self.broadcast_agent_state_update(chat_ids, ignore_user_id = nil)
# send broadcast to agents
Chat::Agent.where('active = ? OR updated_at > ?', true, 8.hours.ago).each do |item|
next if item.updated_by_id == ignore_user_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"
Further reading
Avoid deeply nested control flow statements. Open
if session
return {
state: 'reconnect',
session: session,
agent: user,
Method agent_state
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def self.agent_state(user_id)
return { state: 'chat_disabled' } if !Setting.get('chat')
current_user = User.lookup(id: user_id)
return { error: "No such user with id: #{user_id}" } if !current_user
- 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 {
state: 'no_seats_available',
queue: waiting_count,
}
Method agent_active_chat_ids
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self.agent_active_chat_ids(user)
return [] if user.preferences[:chat].blank?
return [] if user.preferences[:chat][:active].blank?
chat_ids = []
- 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 blocked_ip?
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def blocked_ip?(ip)
return false if ip.blank?
return false if block_ip.blank?
ips = block_ip.split(';')
- 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 active_agent_count
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self.active_agent_count(chat_ids, diff = 2.minutes)
count = 0
Chat::Agent.where(active: true).where('updated_at > ?', Time.zone.now - diff).each do |record|
user = User.lookup(id: record.updated_by_id)
next if !user
- 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 active_agents
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self.active_agents(chat_ids, diff = 2.minutes)
users = []
Chat::Agent.where(active: true).where('updated_at > ?', Time.zone.now - diff).each do |record|
user = User.lookup(id: record.updated_by_id)
next if !user
- 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 available_agents_with_concurrent
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def self.available_agents_with_concurrent(chat_ids, diff = 2.minutes)
agents = {}
Chat::Agent.where(active: true).where('updated_at > ?', Time.zone.now - diff).each do |record|
user = User.lookup(id: record.updated_by_id)
next if !user
- 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"