EventCollector::add()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 4
rs 10
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\Infrastructure\DomainEvents;
4
5
use Stratadox\CardGame\DomainEvent;
6
use Stratadox\CardGame\DomainEventRecorder;
7
use Stratadox\CardGame\EventBag;
8
9
final class EventCollector implements EventBag
10
{
11
    private $events = [];
12
13
    public function add(DomainEvent ...$events): void
14
    {
15
        foreach ($events as $event) {
16
            $this->events[] = $event;
17
        }
18
    }
19
20
    public function takeFrom(DomainEventRecorder $recorder): void
21
    {
22
        $this->add(...$recorder->domainEvents());
23
        $recorder->eraseEvents();
24
    }
25
26
    public function clear(): void
27
    {
28
        $this->events = [];
29
    }
30
31
    public function all(): iterable
32
    {
33
        return $this->events;
34
    }
35
}
36