From 3d4302b49c89c74c0950f05ede7c9ecf68050bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Mon, 17 Aug 2026 09:42:39 +0200 Subject: [PATCH] refactor: adopt PHP 8.4 array_any for filter invariants --- .../Models/ValueObjects/Employees/EmployeeFilter.php | 7 ++++++- src/Domain/Models/ValueObjects/Inco/IncoSheetFilter.php | 6 ++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Domain/Models/ValueObjects/Employees/EmployeeFilter.php b/src/Domain/Models/ValueObjects/Employees/EmployeeFilter.php index d54ad14..acb4d18 100644 --- a/src/Domain/Models/ValueObjects/Employees/EmployeeFilter.php +++ b/src/Domain/Models/ValueObjects/Employees/EmployeeFilter.php @@ -20,7 +20,12 @@ final readonly class EmployeeFilter public ?ServiceId $service = null, public ?\DateTimeInterface $since = null, ) { - if ($establishment === null && empty($sites) && $service === null && $since === null) { + $hasCriterion = array_any( + [$establishment, $service, $since], + static fn (mixed $val): bool => $val !== null + ) || ! empty($sites); + + if (! $hasCriterion) { throw new \DomainException('EmployeeFilter requires at least one filtering criterion.'); } diff --git a/src/Domain/Models/ValueObjects/Inco/IncoSheetFilter.php b/src/Domain/Models/ValueObjects/Inco/IncoSheetFilter.php index 6cc2fc7..a46dadb 100644 --- a/src/Domain/Models/ValueObjects/Inco/IncoSheetFilter.php +++ b/src/Domain/Models/ValueObjects/Inco/IncoSheetFilter.php @@ -15,10 +15,8 @@ final readonly class IncoSheetFilter ) { $this->brands = $brands; - foreach ($this->brands as $brand) { - if (trim($brand) === '') { - throw new \InvalidArgumentException('Every item in brands array must be a non empty string.'); - } + if (array_any($this->brands, static fn (string $brand): bool => trim($brand) === '')) { + throw new \InvalidArgumentException('Every item in brands array must be a non empty string.'); } if (empty($this->brands) && $since === null) {