refactor: adopt PHP 8.4 array_any for filter invariants
This commit is contained in:
parent
59ceab8185
commit
3d4302b49c
2 changed files with 8 additions and 5 deletions
|
|
@ -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.');
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue