forked from greydnls/spec
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAny.php
More file actions
47 lines (38 loc) · 988 Bytes
/
Any.php
File metadata and controls
47 lines (38 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
declare(strict_types=1);
namespace Bakame\Specification;
use Countable;
use Iterator;
use IteratorAggregate;
/**
* @implements IteratorAggregate<Specification>
*/
final class Any implements Specification, Countable, IteratorAggregate
{
/** @var array<Specification> */
private array $specifications;
final public function __construct(Specification ...$specifications)
{
$this->specifications = $specifications;
}
public function count(): int
{
return count($this->specifications);
}
/**
* @return Iterator<Specification>
*/
public function getIterator(): Iterator
{
yield from $this->specifications;
}
public function isSatisfiedBy(mixed $subject): bool
{
foreach ($this->specifications as $specification) {
if ($specification->isSatisfiedBy($subject)) {
return true;
}
}
return [] === $this->specifications;
}
}