Skip to content

Commit

Permalink
Resolve MethodLength Rubocop Disables - Part 1 (#18300)
Browse files Browse the repository at this point in the history
* resolve Form1010cg::Auditor Metrics/MethodLength

* resolve CentralMail::SubmitCentralForm686cJob Metrics/MethodLength

* resolve CopayNotifications::McpNotificationEmailJob Metrics/MethodLength

* resolve CypressViewportUpdater::CypressConfigJsFile Metrics/MethodLength

* add missing timestamp arguement

* reduce duplicate method call on increment methods
  • Loading branch information
stevenjcumming authored Sep 6, 2024
1 parent 6cdc3b6 commit 135d65c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 71 deletions.
40 changes: 24 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,28 @@ def log_mpi_search_result(claim_guid:, form_subject:, result:)

private

def increment_primary_caregiver_data(secondaries_count)
caregivers = self.class.metrics.submission.caregivers
case secondaries_count
when 0
increment(caregivers.primary_no_secondary)
when 1
increment(caregivers.primary_one_secondary)
when 2
increment(caregivers.primary_two_secondary)
end
end

def increment_no_primary_caregiver_data(secondaries_count)
caregivers = self.class.metrics.submission.caregivers
case secondaries_count
when 1
increment(caregivers.no_primary_one_secondary)
when 2
increment(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, timestamp)
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, timestamp)
PDFUtilities::DatestampPdf.new(path).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
)
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)
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)
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)
viewport_type_index = prop == 'height:' ? viewport_idx - 1 : viewport_idx
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

0 comments on commit 135d65c

Please sign in to comment.