Passed
Push — master ( 30d3d2...4e3abd )
by Jesse
01:56
created

AccountOverviewCreator   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 21
rs 10
c 1
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A events() 0 3 1
A handle() 0 7 1
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\CardGame\EventHandler;
4
5
use function assert;
6
use Stratadox\CardGame\DomainEvent;
7
use Stratadox\CardGame\Account\VisitorOpenedAnAccount;
8
use Stratadox\CardGame\ReadModel\Account\AccountOverview;
9
use Stratadox\CardGame\ReadModel\Account\AccountOverviews;
10
11
final class AccountOverviewCreator implements EventHandler
12
{
13
    private $accountOverviews;
14
15
    public function __construct(AccountOverviews $accountOverviews)
16
    {
17
        $this->accountOverviews = $accountOverviews;
18
    }
19
20
    public function events(): iterable
21
    {
22
        return [VisitorOpenedAnAccount::class];
23
    }
24
25
    public function handle(DomainEvent $event): void
26
    {
27
        assert($event instanceof VisitorOpenedAnAccount);
28
29
        $this->accountOverviews->add(new AccountOverview(
30
            $event->aggregateId(),
31
            $event->forVisitor()
32
        ));
33
    }
34
}
35