From 40965e7f7c6591b682788a7a8615805dd70dcaf3 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Tue, 1 Apr 2025 11:54:30 +0200 Subject: [PATCH] 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 --- C4/Overdues.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 314928e4230..71509e034bd 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -224,7 +224,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}, @@ -234,9 +234,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(); -- 2.49.0