refactor: adopt PHP 8.4 array_any for filter invariants

This commit is contained in:
Jérémy Munsch 2026-08-17 09:42:39 +02:00
parent 59ceab8185
commit 3d4302b49c
Signed by: forge-joniko
GPG key ID: D7EFE2F5CB6CC0E4
2 changed files with 8 additions and 5 deletions

View file

@ -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.');
}

View file

@ -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) {