Updated

app/mailers / petition_mailer.rb

F
179 lines of codes
24 methods
6.5 complexity/method
36 churn
156.13 complexity
356 duplications
class PetitionMailer < ApplicationMailer
  1. PetitionMailer assumes too much for instance variable '@creator'
  2. PetitionMailer assumes too much for instance variable '@debate_outcome'
  3. PetitionMailer assumes too much for instance variable '@email'
  4. PetitionMailer assumes too much for instance variable '@petition'
  5. PetitionMailer assumes too much for instance variable '@signature'
  6. PetitionMailer assumes too much for instance variable '@subject'
  7. PetitionMailer has no descriptive comment
  8. PetitionMailer has at least 12 instance variables
  9. PetitionMailer has at least 24 methods
include ActiveSupport::NumberHelper def email_confirmation_for_signer(signature)
  1. Similar code found in 6 nodes Locations: 0 1 2 3 4 5
@signature, @petition = signature, signature.petition mail to: @signature.email, subject: subject_for(:email_confirmation_for_signer) end def email_duplicate_signatures(signature)
  1. Similar code found in 6 nodes Locations: 0 1 2 3 4 5
@signature, @petition = signature, signature.petition mail to: @signature.email, subject: subject_for(:email_duplicate_signatures) end def email_signer(petition, signature, email)
  1. Similar code found in 4 nodes Locations: 0 1 2 3
  2. PetitionMailer takes parameters ['petition', 'signature'] to 8 methods Locations: 0 1 2 3 4 5 6 7
@petition, @signature, @email = petition, signature, email mail to: @signature.email, subject: subject_for(:email_signer), list_unsubscribe: unsubscribe_url end def email_creator(petition, signature, email)
  1. Similar code found in 4 nodes Locations: 0 1 2 3
  2. PetitionMailer takes parameters ['petition', 'signature'] to 8 methods Locations: 0 1 2 3 4 5 6 7
@petition, @signature, @email = petition, signature, email mail to: @signature.email, subject: subject_for(:email_creator), list_unsubscribe: unsubscribe_url end def special_resend_of_email_confirmation_for_signer(signature)
  1. Similar code found in 6 nodes Locations: 0 1 2 3 4 5
@signature, @petition = signature, signature.petition mail to: @signature.email, subject: subject_for(:special_resend_of_email_confirmation_for_signer) end def notify_creator_that_petition_is_published(signature) @signature, @petition = signature, signature.petition mail to: @signature.email, subject: subject_for(:notify_creator_that_petition_is_published), list_unsubscribe: unsubscribe_url end def notify_sponsor_that_petition_is_published(signature)
  1. Similar code found in 6 nodes Locations: 0 1 2 3 4 5
@signature, @petition = signature, signature.petition mail to: @signature.email, subject: subject_for(:notify_sponsor_that_petition_is_published) end def notify_creator_that_petition_was_rejected(signature)
  1. Similar code found in 2 nodes Locations: 0 1
@signature, @petition, @rejection = signature, signature.petition, signature.petition.rejection
  1. PetitionMailer#notify_creator_that_petition_was_rejected calls 'signature.petition' 2 times
mail to: @signature.email, subject: subject_for(:notify_creator_that_petition_was_rejected) end def notify_sponsor_that_petition_was_rejected(signature)
  1. Similar code found in 2 nodes Locations: 0 1
@signature, @petition, @rejection = signature, signature.petition, signature.petition.rejection
  1. PetitionMailer#notify_sponsor_that_petition_was_rejected calls 'signature.petition' 2 times
mail to: @signature.email, subject: subject_for(:notify_sponsor_that_petition_was_rejected) end def notify_signer_of_threshold_response(petition, signature)
  1. Similar code found in 2 nodes Locations: 0 1
  2. PetitionMailer takes parameters ['petition', 'signature'] to 8 methods Locations: 0 1 2 3 4 5 6 7
@petition, @signature, @government_response = petition, signature, petition.government_response mail to: @signature.email, subject: subject_for(:notify_signer_of_threshold_response), list_unsubscribe: unsubscribe_url end def notify_creator_of_threshold_response(petition, signature)
  1. Similar code found in 2 nodes Locations: 0 1
  2. PetitionMailer takes parameters ['petition', 'signature'] to 8 methods Locations: 0 1 2 3 4 5 6 7
@petition, @signature, @government_response = petition, signature, petition.government_response mail to: @signature.email, subject: subject_for(:notify_creator_of_threshold_response), list_unsubscribe: unsubscribe_url end def notify_creator_of_closing_date_change(signature, dissolution_at = Parliament.dissolution_at) @signature, @petition = signature, signature.petition @closing_time = dissolution_at.strftime('%H:%M%P') @closing_date = dissolution_at.strftime('%-d %B') @last_response_date = dissolution_at.yesterday.strftime('%-d %B') mail to: @signature.email, subject: subject_for(:notify_creator_of_closing_date_change) end def notify_creator_of_sponsored_petition_being_stopped(signature)
  1. Similar code found in 6 nodes Locations: 0 1 2 3 4 5
@signature, @petition = signature, signature.petition mail to: @signature.email, subject: subject_for(:notify_creator_of_sponsored_petition_being_stopped) end def notify_creator_of_validated_petition_being_stopped(signature)
  1. Similar code found in 6 nodes Locations: 0 1 2 3 4 5
@signature, @petition = signature, signature.petition mail to: @signature.email, subject: subject_for(:notify_creator_of_validated_petition_being_stopped) end def gather_sponsors_for_petition(petition, bcc = nil) @petition, @creator = petition, petition.creator mail to: @creator.email, bcc: bcc, subject: subject_for(:gather_sponsors_for_petition) end def notify_signer_of_debate_outcome(petition, signature)
  1. Similar code found in 4 nodes Locations: 0 1 2 3
  2. PetitionMailer takes parameters ['petition', 'signature'] to 8 methods Locations: 0 1 2 3 4 5 6 7
@petition, @debate_outcome, @signature = petition, petition.debate_outcome, signature if @debate_outcome.debated? subject = subject_for(:notify_signer_of_positive_debate_outcome) else subject = subject_for(:notify_signer_of_negative_debate_outcome) end mail to: @signature.email, subject: subject, list_unsubscribe: unsubscribe_url end def notify_creator_of_debate_outcome(petition, signature)
  1. Similar code found in 4 nodes Locations: 0 1 2 3
  2. PetitionMailer takes parameters ['petition', 'signature'] to 8 methods Locations: 0 1 2 3 4 5 6 7
@petition, @debate_outcome, @signature = petition, petition.debate_outcome, signature if @debate_outcome.debated? subject = subject_for(:notify_creator_of_positive_debate_outcome) else subject = subject_for(:notify_creator_of_negative_debate_outcome) end mail to: @signature.email, subject: subject, list_unsubscribe: unsubscribe_url end def notify_signer_of_debate_scheduled(petition, signature)
  1. Similar code found in 4 nodes Locations: 0 1 2 3
  2. PetitionMailer takes parameters ['petition', 'signature'] to 8 methods Locations: 0 1 2 3 4 5 6 7
@petition, @signature = petition, signature mail to: @signature.email, subject: subject_for(:notify_signer_of_debate_scheduled), list_unsubscribe: unsubscribe_url end def notify_creator_of_debate_scheduled(petition, signature)
  1. Similar code found in 4 nodes Locations: 0 1 2 3
  2. PetitionMailer takes parameters ['petition', 'signature'] to 8 methods Locations: 0 1 2 3 4 5 6 7
@petition, @signature = petition, signature mail to: @signature.email, subject: subject_for(:notify_creator_of_debate_scheduled), list_unsubscribe: unsubscribe_url end def notify_creator_that_moderation_is_delayed(signature, subject, body) @petition, @signature = signature.petition, signature @subject, @body = subject, body mail to: @signature.email, subject: subject_for(:notify_creator_that_moderation_is_delayed), list_unsubscribe: unsubscribe_url end private def subject_for(key, options = {}) I18n.t key, i18n_options.merge(options) end def signature_belongs_to_creator? @signature && @signature.creator? end def i18n_options
  1. PetitionMailer#i18n_options has approx 7 statements
{}.tap do |options| options[:scope] = :"petitions.emails.subjects" if defined?(@petition)
  1. Identical code found in 2 nodes Locations: 0 1
options[:count] = @petition.signature_count
  1. PetitionMailer#i18n_options calls '@petition.signature_count' 2 times Locations: 0 1
options[:formatted_count] = number_to_delimited(@petition.signature_count)
  1. PetitionMailer#i18n_options calls '@petition.signature_count' 2 times Locations: 0 1
options[:action] = @petition.action end if defined?(@email) options[:subject] = @email.subject end if defined?(@subject) options[:subject] = @subject end end end def unsubscribe_url "<#{unsubscribe_signature_url(@signature, token: @signature.unsubscribe_token)}>" end end