Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve MethodLength Rubocop Disables - Part 1 #18300

Merged
merged 7 commits into from
Sep 6, 2024
38 changes: 22 additions & 16 deletions app/services/form1010cg/auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,32 +50,18 @@ def record_submission_attempt
increment self.class.metrics.submission.attempt
end

# rubocop:disable Metrics/MethodLength
def record_caregivers(claim)
secondaries_count = 0
%w[one two].each do |attr|
secondaries_count += 1 if claim.public_send("secondary_caregiver_#{attr}_data").present?
end

if claim.primary_caregiver_data.present?
case secondaries_count
when 0
increment(self.class.metrics.submission.caregivers.primary_no_secondary)
when 1
increment(self.class.metrics.submission.caregivers.primary_one_secondary)
when 2
increment(self.class.metrics.submission.caregivers.primary_two_secondary)
end
increment_primary_caregiver_data(secondaries_count)
else
case secondaries_count
when 1
increment(self.class.metrics.submission.caregivers.no_primary_one_secondary)
when 2
increment(self.class.metrics.submission.caregivers.no_primary_two_secondary)
end
increment_no_primary_caregiver_data(secondaries_count)
end
end
# rubocop:enable Metrics/MethodLength

def record_submission_failure_client_data(errors:, claim_guid: nil)
increment self.class.metrics.submission.failure.client.data
Expand Down Expand Up @@ -108,6 +94,26 @@ def log_mpi_search_result(claim_guid:, form_subject:, result:)

private

def increment_primary_caregiver_data(secondaries_count)
case secondaries_count
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
when 0
increment(self.class.metrics.submission.caregivers.primary_no_secondary)
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
when 1
increment(self.class.metrics.submission.caregivers.primary_one_secondary)
when 2
increment(self.class.metrics.submission.caregivers.primary_two_secondary)
end
end

def increment_no_primary_caregiver_data(secondaries_count)
case secondaries_count
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
when 1
increment(self.class.metrics.submission.caregivers.no_primary_one_secondary)
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
when 2
increment(self.class.metrics.submission.caregivers.no_primary_two_secondary)
end
end

def increment(stat)
StatsD.increment stat
end
Expand Down
26 changes: 14 additions & 12 deletions app/sidekiq/central_mail/submit_central_form686c_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ def to_faraday_upload(file_path)
)
end

# rubocop:disable Metrics/MethodLength
def process_pdf(pdf_path, timestamp = nil, form_id = nil)
stamped_path1 = PDFUtilities::DatestampPdf.new(pdf_path).run(text: 'VA.GOV', x: 5, y: 5, timestamp:)
stamped_path2 = PDFUtilities::DatestampPdf.new(stamped_path1).run(
Expand All @@ -152,21 +151,11 @@ def process_pdf(pdf_path, timestamp = nil, form_id = nil)
text_only: true
)
if form_id.present?
PDFUtilities::DatestampPdf.new(stamped_path2).run(
text: 'Application Submitted on va.gov',
x: form_id == '686C-674' ? 400 : 300,
y: form_id == '686C-674' ? 675 : 775,
text_only: true, # passing as text only because we override how the date is stamped in this instance
timestamp:,
page_number: form_id == '686C-674' ? 6 : 0,
template: "lib/pdf_fill/forms/pdfs/#{form_id}.pdf",
multistamp: true
)
stamped_pdf_with_form(form_id, stamped_path2)
else
stamped_path2
end
end
# rubocop:enable Metrics/MethodLength

def get_hash_and_pages(file_path)
{
Expand Down Expand Up @@ -240,6 +229,19 @@ def send_confirmation_email(user)

private

def stamped_pdf_with_form(form_id, path)
PDFUtilities::DatestampPdf.new(path).run(
text: 'Application Submitted on va.gov',
x: form_id == '686C-674' ? 400 : 300,
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
y: form_id == '686C-674' ? 675 : 775,
text_only: true, # passing as text only because we override how the date is stamped in this instance
timestamp:,
page_number: form_id == '686C-674' ? 6 : 0,
template: "lib/pdf_fill/forms/pdfs/#{form_id}.pdf",
multistamp: true
)
end

def log_cmp_response(response)
log_message_to_sentry("vre-central-mail-response: #{response}", :info, {}, { team: 'vfs-ebenefits' })
end
Expand Down
19 changes: 12 additions & 7 deletions app/sidekiq/copay_notifications/mcp_notification_email_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,8 @@ class McpNotificationEmailJob
include SentryLogging
sidekiq_options retry: 14

def perform(vet360_id, template_id, backup_email = nil, personalisation = nil) # rubocop:disable Metrics/MethodLength
person_resp = if Flipper.enabled?(:va_v3_contact_information_service)
VAProfile::V2::ContactInformation::Service.get_person(vet360_id)
else
VAProfile::ContactInformation::Service.get_person(vet360_id)
end

def perform(vet360_id, template_id, backup_email = nil, personalisation = nil)
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
person_resp = person_response(vet360_id)
email_address = person_resp.person&.emails&.first&.email_address || backup_email

if email_address
Expand Down Expand Up @@ -51,5 +46,15 @@ def send_email(email, template_id, personalisation)
}.compact
)
end

private

def person_response(vet360_id)
if Flipper.enabled?(:va_v3_contact_information_service)
VAProfile::V2::ContactInformation::Service.get_person(vet360_id)
else
VAProfile::ContactInformation::Service.get_person(vet360_id)
end
end
end
end
70 changes: 34 additions & 36 deletions app/sidekiq/cypress_viewport_updater/cypress_config_js_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ def initialize
super(github_path: 'config/cypress.config.js', name: 'cypress.config.js')
end

# rubocop:disable Metrics/MethodLength
def update(viewports:)
viewport_type = nil
viewport_idx = nil
skip_next_line = false
lines = raw_content.split("\n")
self.updated_content = "#{process_lines(lines, viewports)}\n"
self
end

self.updated_content = "#{lines.each_with_object([]).with_index do |(line, new_lines), idx|
if skip_next_line
skip_next_line = false
next
end
private

def process_lines(lines, viewports)
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
viewport_type, viewport_idx = nil
skip_next_line = false

lines.each_with_object([]).with_index do |(line, new_lines), idx|
next if skip_next_line.tap { skip_next_line = false }

if (type = VIEWPORT_TYPES.keys.select { |t| line.include?(t.to_s) }.first)
viewport_type = VIEWPORT_TYPES[type]
Expand All @@ -46,42 +48,38 @@ def update(viewports:)
rewrite_line(line:, new_value: viewports.desktop[0].height, prop: 'viewportHeight')
elsif (prop = VIEWPORT_PROPS.select { |p| line.include?(p.to_s) }.first)
viewport_idx += 1 if prop == 'height:'
if prop == 'devicesWithViewport:' && lines[idx + 1].exclude?('percentTraffic:')
skip_next_line = true
end
rewrite_line(line:,
new_value: viewports
.send(viewport_type)[prop == 'height:' ? viewport_idx - 1 : viewport_idx]
.send(prop.chomp(':')),
prop:)
skip_next_line = true if prop_with_viewport(prop) && line_excludes_traffic(lines, idx)
viewport_prop_new_line(viewports, line, prop, viewport_type, viewport_idx)
end

new_lines.push(new_line.nil? ? line : new_line)
end.flatten.join("\n")}\n"

self
end.flatten.join("\n")
end
# rubocop:enable Metrics/MethodLength

private
def viewport_prop_new_line(viewports, line, prop, viewport_type, viewport_idx)
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
viewport_type_index = prop == 'height:' ? viewport_idx - 1 : viewport_idx
stevenjcumming marked this conversation as resolved.
Show resolved Hide resolved
new_value = viewports.send(viewport_type)[viewport_type_index].send(prop.chomp(':'))
rewrite_line(line:, new_value:, prop:)
end

def rewrite_line(line:, new_value:, prop:)
line_parts = line.split(':')
line_prefix = line.split(':')[0]
wrapped_value = WRAP_VALUE_IN_QUOTES.include?(prop) ? "'#{new_value}'" : new_value.to_s
new_line = "#{line_prefix}: #{wrapped_value},"

return new_line if new_line.length <= 80

new_line = if WRAP_VALUE_IN_QUOTES.include?(prop)
line_parts[0] + ": '#{new_value}',"
else
line_parts[0] + ": #{new_value},"
end
[
"#{line_prefix}:",
"#{line_prefix.match(/^\s+/)[0]} #{wrapped_value},"
]
end

if new_line.length > 80
return [
"#{line_parts[0]}:",
"#{line_parts[0].match(/^\s+/)[0]} #{new_line.split(': ')[1]}"
]
end
def prop_with_viewport(prop)
prop == 'devicesWithViewport:'
end

new_line
def line_excludes_traffic(lines, idx)
lines[idx + 1].exclude?('percentTraffic:')
end
end
end
Loading