OneStreamPerAggregateStrategy   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 16
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A computeName() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Blixit\EventSourcing\Stream\Strategy;
6
7
use Blixit\EventSourcing\Stream\StreamName;
8
use function sprintf;
9
10
class OneStreamPerAggregateStrategy extends StreamStrategy
11
{
12
    /**
13
     * @param mixed $aggregateId
14
     *
15
     * @throws NamingStrategyException
16
     */
17
    public function computeName(string $aggregateClass, $aggregateId = null) : StreamName
18
    {
19
        if (empty($aggregateId)) {
20
            throw new NamingStrategyException('OneStreamPerAggregateStrategy requires not blank aggregate id');
21
        }
22
        return StreamName::fromString(sprintf(
23
            '%s.%s',
24
            $aggregateClass,
25
            $aggregateId
26
        ));
27
    }
28
}
29