Bug 39405: (follow-up) Simplify code for choosing the first fine values

This patch avoids the introduction of a `foreach` loop and a `return`
call inside of it, by using grep on the array assignment, and then just
returning the first element on it, if any.

No behavior change is expected.

The code becomes easier to read and spot what is doing.

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
(cherry picked from commit 9345f6d784)
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
This commit is contained in:
Tomas Cohen Arazi 2025-04-01 11:54:30 +02:00 committed by Paul Derscheid
parent 8081b1e3c1
commit 33ad4fa783
No known key found for this signature in database
GPG Key ID: C25F9FD44CED595B
1 changed files with 4 additions and 4 deletions

View File

@ -225,7 +225,7 @@ sub CalcFine {
# Call the plugin hook overwrite_calc_fine of all plugins and return
# the first defined fine.
my @fines = Koha::Plugins->call(
my @fines = grep { defined $_ } Koha::Plugins->call(
'overwrite_calc_fine',
{
itemnumber => $item->{itemnumber},
@ -235,9 +235,9 @@ sub CalcFine {
end_date => $end_date,
}
);
foreach my $fine (@fines) {
return @$fine if ( defined $fine );
}
return @{ $fines[0] }
if scalar @fines;
my $start_date = $due_dt->clone();
# get issuingrules (fines part will be used)