Total Complexity | 10 |
Total Lines | 79 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
18 | final class AggregateEventArrayStream implements AggregateEventStream |
||
19 | { |
||
20 | /** |
||
21 | * @var AggregateEvent[] |
||
22 | */ |
||
23 | private $events = []; |
||
24 | |||
25 | /** |
||
26 | * AggregateEventArrayStream constructor. |
||
27 | * |
||
28 | * @param (AggregateEvent|mixed)[] $events |
||
29 | * |
||
30 | * @throws InvalidAggregateEventException |
||
31 | */ |
||
32 | public function __construct(array $events) |
||
33 | { |
||
34 | foreach ($events as $event) { |
||
35 | if (!$event instanceof AggregateEvent) { |
||
36 | throw new InvalidAggregateEventException(\sprintf( |
||
37 | 'Aggregate event stream only accepts "%s", "%s" given', |
||
38 | AggregateEvent::class, |
||
39 | \is_object($event) ? \get_class($event) : \gettype($event) |
||
40 | )); |
||
41 | } |
||
42 | |||
43 | $this->events[] = $event; |
||
44 | } |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * {@inheritdoc} |
||
49 | * |
||
50 | * @return AggregateEvent |
||
51 | */ |
||
52 | public function current(): AggregateEvent |
||
53 | { |
||
54 | return \current($this->events); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | public function next(): void |
||
61 | { |
||
62 | \next($this->events); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | * |
||
68 | * @return string|int|null |
||
69 | */ |
||
70 | public function key() |
||
71 | { |
||
72 | return \key($this->events); |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | public function valid(): bool |
||
79 | { |
||
80 | return \key($this->events) !== null; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | public function rewind(): void |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * {@inheritdoc} |
||
93 | */ |
||
94 | public function count(): int |
||
97 | } |
||
98 | } |
||
99 |