Completed
Push — master ( fa909b...9344a1 )
by Beñat
01:48
created

StreamName::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Shared Kernel library.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace LIN3S\SharedKernel\Event;
13
14
use LIN3S\SharedKernel\Domain\Model\DomainEventCollection;
15
use LIN3S\SharedKernel\Domain\Model\Identity\Id;
16
17
/**
18
 * @author Beñat Espiña <[email protected]>
19
 */
20
class StreamName
21
{
22
    private $name;
23
    private $aggregateId;
24
25
    public function __construct(Id $aggregateId, $name)
26
    {
27
        $this->setName($name);
28
        $this->aggregateId = $aggregateId;
29
    }
30
31
    private function setName($name)
32
    {
33
        $this->checkNameIsValid($name);
34
        $this->name = $name;
35
    }
36
37
    private function checkNameIsValid($name)
38
    {
39
        if ('' === $name) {
40
            throw new StreamNameIsEmpty();
41
        }
42
    }
43
44
    public function name()
45
    {
46
        return sprintf('%s-%s', $this->name, $this->aggregateId()->id());
47
    }
48
49
    public function aggregateId()
50
    {
51
        return $this->aggregateId;
52
    }
53
54
    public function __toString()
55
    {
56
        return (string) $this->name();
57
    }
58
}
59