From 33ad4fa783d3c43138d0eabab5ca6c9daa7c8ba2 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 Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer (cherry picked from commit 9345f6d784d2d67a6bcf1ba4cb879f258c03b0d0) Signed-off-by: Paul Derscheid --- C4/Overdues.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/C4/Overdues.pm b/C4/Overdues.pm index 59d027be3e..e1c2c9f28a 100644 --- a/C4/Overdues.pm +++ b/C4/Overdues.pm @@ -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)