Client::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 *
4
 * This file is part of the Aggrego.
5
 * (c) Tomasz Kunicki <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 */
11
12
declare(strict_types = 1);
13
14
namespace Aggrego\CommandLogicUnit\EventConsumer;
15
16
use Aggrego\CommandConsumer\Client as CommandConsumerClient;
17
use Aggrego\CommandLogicUnit\EventProcessor\EventProcessor;
18
use Aggrego\EventConsumer\Client as EventConsumerClient;
19
use Aggrego\EventConsumer\Event;
20
use Aggrego\EventConsumer\Exception\UnprocessableEventException;
21
22
class Client implements EventConsumerClient
23
{
24
    /**
25
     * @var EventProcessor
26
     */
27
    private $eventProcessor;
28
29
    /**
30
     * @var CommandConsumerClient
31
     */
32
    private $commandConsumer;
33
34
    public function __construct(
35
        EventProcessor $eventProcessor,
36
        CommandConsumerClient $commandConsumer
37
    ) {
38
        $this->eventProcessor = $eventProcessor;
39
        $this->commandConsumer = $commandConsumer;
40
    }
41
42
    /**
43
     * @param  Event $event
44
     * @throws UnprocessableEventException if event (payload) have invalid structure.
45
     */
46
    public function consume(Event $event): void
47
    {
48
        foreach ($this->eventProcessor->transform($event) as $command) {
49
            $this->commandConsumer->consume($command);
50
        }
51
    }
52
}
53