Updated

app/jobs / archive_petition_job.rb

D
118 lines of codes
2 methods
94.5 complexity/method
10 churn
188.94 complexity
95 duplications
require 'tempfile' class ArchivePetitionJob < ApplicationJob
  1. ArchivePetitionJob has no descriptive comment
queue_as :high_priority def perform(petition)
  1. ArchivePetitionJob#perform has a flog score of 188
  2. ArchivePetitionJob#perform has approx 70 statements
unless petition.archived? || parliament.petitions.exists?(petition.id)
  1. ArchivePetitionJob#perform calls 'parliament.petitions' 2 times Locations: 0 1
  2. ArchivePetitionJob#perform calls 'petition.id' 2 times Locations: 0 1
archived_petition = parliament.petitions.create! do |p|
  1. ArchivePetitionJob#perform calls 'parliament.petitions' 2 times Locations: 0 1
  2. ArchivePetitionJob#perform has the variable name 'p'
p.id = petition.id
  1. ArchivePetitionJob#perform calls 'petition.id' 2 times Locations: 0 1
  2. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.action = petition.action
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.background = petition.background
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.additional_details = petition.additional_details
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.state = petition.state
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.debate_state = petition.debate_state
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.special_consideration = petition.special_consideration
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.opened_at = petition.opened_at
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.closed_at = petition.closed_at
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.rejected_at = petition.rejected_at
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.stopped_at = petition.stopped_at
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.signature_count = petition.signature_count
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.moderation_threshold_reached_at = petition.moderation_threshold_reached_at
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.moderation_lag = petition.moderation_lag
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.last_signed_at = petition.last_signed_at
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.response_threshold_reached_at = petition.response_threshold_reached_at
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.government_response_at = petition.government_response_at
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.debate_threshold_reached_at = petition.debate_threshold_reached_at
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.scheduled_debate_date = petition.scheduled_debate_date
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.debate_outcome_at = petition.debate_outcome_at
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.created_at = petition.created_at
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.updated_at = petition.updated_at
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
if receipt = petition.email_requested_receipt p.email_requested_for_government_response_at = receipt.government_response
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.email_requested_for_debate_scheduled_at = receipt.debate_scheduled
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.email_requested_for_debate_outcome_at = receipt.debate_outcome
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
p.email_requested_for_petition_email_at = receipt.petition_email
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
end if note = petition.note p.build_note do |n|
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  2. ArchivePetitionJob#perform contains iterators nested 2 deep Locations: 0 1 2 3 4 5
  3. ArchivePetitionJob#perform has the variable name 'n'
n.details = note.details n.created_at = note.created_at n.updated_at = note.updated_at end end if rejection = petition.rejection p.build_rejection do |r|
  1. Similar code found in 2 nodes Locations: 0 1
  2. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  3. ArchivePetitionJob#perform contains iterators nested 2 deep Locations: 0 1 2 3 4 5
  4. ArchivePetitionJob#perform has the variable name 'r' Locations: 0 1
r.code = rejection.code r.details = rejection.details r.created_at = rejection.created_at r.updated_at = rejection.updated_at end end petition.emails.each do |email| p.emails.build do |e|
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  2. ArchivePetitionJob#perform contains iterators nested 3 deep
  3. ArchivePetitionJob#perform has the variable name 'e'
e.subject = email.subject
  1. Similar code found in 2 nodes Locations: 0 1
e.body = email.body e.sent_by = email.sent_by e.created_at = email.created_at e.updated_at = email.updated_at end end if government_response = petition.government_response p.build_government_response do |r|
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  2. ArchivePetitionJob#perform contains iterators nested 2 deep Locations: 0 1 2 3 4 5
  3. ArchivePetitionJob#perform has the variable name 'r' Locations: 0 1
r.responded_on = government_response.responded_on
  1. Similar code found in 2 nodes Locations: 0 1
r.summary = government_response.summary r.details = government_response.details r.created_at = government_response.created_at r.updated_at = government_response.updated_at end end if debate_outcome = petition.debate_outcome p.build_debate_outcome do |o|
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  2. ArchivePetitionJob#perform contains iterators nested 2 deep Locations: 0 1 2 3 4 5
  3. ArchivePetitionJob#perform has the variable name 'o'
o.debated = debate_outcome.debated o.debated_on = debate_outcome.debated_on o.transcript_url = debate_outcome.transcript_url o.video_url = debate_outcome.video_url o.debate_pack_url = debate_outcome.debate_pack_url o.overview = debate_outcome.overview o.created_at = debate_outcome.created_at o.updated_at = debate_outcome.updated_at if debate_outcome.commons_image? tempfile = Tempfile.new("commons_image") debate_outcome.commons_image.copy_to_local_file(:original, tempfile.path) tempfile.rewind o.commons_image = tempfile o.commons_image_file_name = debate_outcome.commons_image_file_name end end end constituencies = petition.signatures_by_constituency unless constituencies.empty?
  1. Similar code found in 2 nodes Locations: 0 1
p.signatures_by_constituency = Hash[constituencies.map { |c| [c.constituency_id, c.signature_count] }]
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  2. ArchivePetitionJob#perform contains iterators nested 2 deep Locations: 0 1 2 3 4 5
  3. ArchivePetitionJob#perform has the variable name 'c'
end locations = petition.signatures_by_country unless locations.empty?
  1. Similar code found in 2 nodes Locations: 0 1
p.signatures_by_country = Hash[locations.map { |l| [l.location_code, l.signature_count] }]
  1. ArchivePetitionJob#perform refers to 'p' more than self (maybe move it to another class?) Locations: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
  2. ArchivePetitionJob#perform contains iterators nested 2 deep Locations: 0 1 2 3 4 5
  3. ArchivePetitionJob#perform has the variable name 'l'
end end ArchiveSignaturesJob.perform_later(petition, archived_petition) end end private def parliament
  1. ArchivePetitionJob#parliament doesn't depend on instance state (maybe move it to another class?)
Parliament.instance end end