Completed
Pull Request — master (#366)
by Beñat
05:23
created

StreamName   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 39
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A setName() 0 5 1
A checkNameIsValid() 0 6 2
A name() 0 4 1
A aggregateId() 0 4 1
A __toString() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of the Kreta package.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 * (c) Gorka Laucirica <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace Kreta\SharedKernel\Event;
16
17
use Kreta\SharedKernel\Domain\Model\Identity\Id;
18
19
class StreamName
20
{
21
    private $name;
22
    private $aggregateId;
23
24
    public function __construct(Id $aggregateId, string $name)
25
    {
26
        $this->setName($name);
27
        $this->aggregateId = $aggregateId;
28
    }
29
30
    private function setName(string $name) : void
31
    {
32
        $this->checkNameIsValid($name);
33
        $this->name = $name;
34
    }
35
36
    private function checkNameIsValid(string $name) : void
37
    {
38
        if ('' === $name) {
39
            throw new StreamNameIsEmpty();
40
        }
41
    }
42
43
    public function name() : string
44
    {
45
        return sprintf('%s-%s', $this->name, $this->aggregateId()->id());
46
    }
47
48
    public function aggregateId() : Id
49
    {
50
        return $this->aggregateId;
51
    }
52
53
    public function __toString() : string
54
    {
55
        return (string) $this->name();
56
    }
57
}
58