StreamMap   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 30
ccs 0
cts 14
cp 0
rs 10
c 0
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A unregister() 0 3 1
A makeEmpty() 0 3 1
A toNative() 0 8 2
A register() 0 3 1
A __construct() 0 3 1
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