From 82a4d40890d0cc56274db68cc23509f4fe1dc3a5 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 10 May 2023 19:25:21 +0100 Subject: [PATCH] Bug 12532: (QA follow-up) Clean up notice_email_address Reduce some of the code duplication Signed-off-by: Martin Renvoize Signed-off-by: Tomas Cohen Arazi --- Koha/Patron.pm | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 4ad5a9b315..d9a0f257d1 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1579,33 +1579,32 @@ Returns the empty string if no email address. =cut -sub notice_email_address{ - my ( $self ) = @_; +sub notice_email_address { + my ($self) = @_; my $address; my $guarantor_address; my $which_address = C4::Context->preference("EmailFieldPrimary"); + # if syspref is set to 'first valid' (value == OFF), look up email address if ( $which_address eq 'OFF' ) { $address = $self->first_valid_email_address; - } else { + } + else { $address = $self->$which_address || ''; } my $use_guarantor = C4::Context->preference('RedirectGuaranteeEmail'); if ($use_guarantor) { - my @guarantors = map { $_->guarantors->as_list } $self->guarantor_relationships(); + my @guarantors = + map { $_->guarantors->as_list } $self->guarantor_relationships(); if (@guarantors) { foreach my $guarantor (@guarantors) { - if ( $which_address eq 'OFF' ) { - $guarantor_address = $guarantor->first_valid_email_address; - } else { - $guarantor_address = $guarantor->$which_address || ''; - } - if ($address){ + $guarantor_address = $guarantor->notice_email_address; + if ($address) { $address .= ', '; } - $address .= $guarantor_address if $guarantor_address; + $address .= $guarantor_address if $guarantor_address; } } } -- 2.39.5