EventCollector   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 25
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A takeFrom() 0 4 1
A add() 0 4 2
A all() 0 3 1
A clear() 0 3 1
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