StreamMap::makeEmpty()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/event-sourcing project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\EventSourcing\EventStore\Stream;
10
11
use Daikon\DataStructure\TypedMap;
12
use Daikon\EventSourcing\Aggregate\AggregateIdInterface;
13
use Daikon\Interop\MakeEmptyInterface;
14
use Daikon\Interop\ToNativeInterface;
15
16
final class StreamMap extends TypedMap implements MakeEmptyInterface, ToNativeInterface
17
{
18
    public function __construct(iterable $streams = [])
19
    {
20
        $this->init($streams, [StreamInterface::class]);
21
    }
22
23
    public function register(StreamInterface $stream): self
24
    {
25
        return $this->with((string)$stream->getAggregateId(), $stream);
26
    }
27
28
    public function unregister(AggregateIdInterface $aggregateId): self
29
    {
30
        return $this->without((string)$aggregateId);
31
    }
32
33
    public static function makeEmpty(): self
34
    {
35
        return new self;
36
    }
37
38
    public function toNative(): array
39
    {
40
        $this->assertInitialized();
41
        $streams = [];
42
        foreach ($this as $key => $stream) {
43
            $streams[$key] = $stream->toNative();
44
        }
45
        return $streams;
46
    }
47
}
48