Showing 45 of 45 total issues
Method generate_reminders
has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring. Open
def self.generate_reminders(court_dates, court_locations, court_date_csv, options = {})
time_zone_offset = '-0600' # Make sure this is by instance eventually
total_rrs = 0
Message.transaction do
Rails.logger.tagged('court reminders') do
- 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
Function clientListInit
has 62 lines of code (exceeds 25 allowed). Consider refactoring. Open
function clientListInit() {
var clientSearchOptions = {
valueNames: [
{ attr: 'data-category-order', name: 'category-order' },
{ attr: 'data-fullname', name: 'fullname' },
Similar blocks of code found in 2 locations. Consider refactoring. Open
$('#schedule-later-form').click(function() {
checked = ($(this).find(":checkbox:checked").length > 0);
$('#send_later').prop('disabled', !checked);
$('#send_later').toggleClass('button--disabled', !checked);
});
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 82.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
$('#survey').click(function() {
checked = ($(this).find(":checkbox:checked").length > 0);
$('#deactivate_client').prop('disabled', !checked);
$('#deactivate_client').toggleClass('button--disabled', !checked);
});
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 82.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Class GcfFormBuilder
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class GcfFormBuilder < ActionView::Helpers::FormBuilder
# rubocop:disable Metrics/ParameterLists
def gcf_input_field(method, label_text, type: 'text', notes: [], options: {}, classes: [], prefix: nil, autofocus: nil, icon: nil)
classes = classes.append(%w[text-input])
<<-HTML.html_safe
Class Message
has 22 methods (exceeds 20 allowed). Consider refactoring. Open
class Message < ApplicationRecord
include Rails.application.routes.url_helpers
belongs_to :reporting_relationship, class_name: 'ReportingRelationship', foreign_key: 'reporting_relationship_id'
belongs_to :original_reporting_relationship, class_name: 'ReportingRelationship', foreign_key: 'original_reporting_relationship_id'
Method track
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def self.track(distinct_id:, label:, user_agent: nil, data: {})
if MIXPANEL_TRACKER.present?
if user_agent
client = DeviceDetector.new(user_agent)
data[:client_bot_name] = client.bot_name
- 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
Similar blocks of code found in 2 locations. Consider refactoring. Open
if(this.files[0].size > 5000000) {
$('span.image-help-text').text('You can only send files <5MB in size');
$('#file-name-preview').addClass('warning');
$('#image-cancel i').removeClass('icon-close').addClass('icon-warning');
$('#message_attachments_0_media').val('');
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 72.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (!validFileType(this.files[0])) {
$('span.image-help-text').text('You can only send .gif, .png, and .jpg files');
$('#file-name-preview').addClass('warning');
$('#image-cancel i').removeClass('icon-close').addClass('icon-warning');
$('#message_attachments_0_media').val('');
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 72.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Method generate_reminders
has 42 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.generate_reminders(court_dates, court_locations, court_date_csv, options = {})
time_zone_offset = '-0600' # Make sure this is by instance eventually
total_rrs = 0
Message.transaction do
Rails.logger.tagged('court reminders') do
Method incoming_voice
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
def incoming_voice
voice_client = VoiceService.new
client = Client.find_by(phone_number: params['From'])
client_id = client.try(:id) || 'no client'
department = Department.find_by(phone_number: params['To'])
Method create_from_twilio!
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
def self.create_from_twilio!(twilio_params)
from_phone_number = twilio_params[:From]
to_phone_number = twilio_params[:To]
department = Department.find_by(phone_number: to_phone_number)
Method create
has 41 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
@reporting_relationship = ReportingRelationship
.find_by(user: current_user.id, client_id: reporting_relationship_params['client_id'])
@client = Client.find(reporting_relationship_params['client_id'])
@transfer_reporting_relationship = ReportingRelationship.find_or_initialize_by(reporting_relationship_params)
Method create
has 40 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
rr_current = ReportingRelationship.find_by(
user: current_user,
client: Client.find(merge_params[:client_id])
)
Method create
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
send_at = if params[:commit] == 'Schedule messages'
DateParser.parse(mass_message_params[:send_at][:date], mass_message_params[:send_at][:time])
else
Time.zone.now
Method create
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
def create
client = current_user.clients.find params[:client_id]
rr = ReportingRelationship.find_by(user: current_user, client: client)
send_at = message_params[:send_at].present? ? DateParser.parse(message_params[:send_at][:date], message_params[:send_at][:time]) : Time.zone.now
valid_attachments = true
Method perform
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def perform(message:)
status_callback = Rails.application.routes.url_helpers.incoming_sms_status_url
return if message.sent || (message.send_at > Time.zone.now)
message.reporting_relationship.update!(last_contacted_at: message.send_at)
- 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 update
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
def update
rr_id = params['id']
target_user_id = params['reporting_relationship']['user']['id']
transfer_note = params['transfer']['note']
department_id = params['reporting_relationship']['user']['department_id']
Method transfer_messages
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def transfer_messages(client:, old_users:, new_user:)
original_rrs = ReportingRelationship.where(client: client, user: old_users)
original_messages = Message.where(reporting_relationship: original_rrs).scheduled
new_rr = ReportingRelationship.find_by(client: client, user: new_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 perform
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
def perform(message:)
status_callback = Rails.application.routes.url_helpers.incoming_sms_status_url
return if message.sent || (message.send_at > Time.zone.now)
message.reporting_relationship.update!(last_contacted_at: message.send_at)