EventCollector::clear()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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