Passed
Push — master ( a1a5b3...2e461e )
by Tomasz
01:31
created

Domain::build()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
/**
3
 *
4
 * This file is part of the Aggrego.
5
 * (c) Tomasz Kunicki <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 */
11
12
declare(strict_types = 1);
13
14
namespace Aggrego\EventConsumer\Event;
15
16
use Assert\Assertion;
17
18
class Domain
19
{
20
    private const SEPARATOR = ':';
21
22
    /** @var Name */
23
    private $name;
24
25
    /** @var Uuid */
26
    private $uuid;
27
28
    public function __construct(Name $name, Uuid $uuid)
29
    {
30
        $this->name = $name;
31
        $this->uuid = $uuid;
32
    }
33
34
    /**
35
     * @param string $value
36
     * @return Domain
37
     * @throws \Assert\AssertionFailedException
38
     */
39
    public static function fromString(string $string): Domain
40
    {
41
        Assertion::notEmpty($string);
42
        list($domainName, $uuid) = explode(self::SEPARATOR, $string);
43
44
        return self::build($domainName, $uuid);
45
    }
46
47
    /**
48
     * @param string $domainName
49
     * @param string $uuid
50
     * @return Domain
51
     * @throws \Assert\AssertionFailedException
52
     */
53
    public static function build(string $domainName, string $uuid): self
54
    {
55
        return new self(new Name($domainName), new Uuid($uuid));
56
    }
57
58
    public function getValue(): string
59
    {
60
        return sprintf('%s:%s', $this->name->getValue(), $this->uuid->getValue());
61
    }
62
63
    public function getName(): Name
64
    {
65
        return $this->name;
66
    }
67
68
    public function getUuid(): Uuid
69
    {
70
        return $this->uuid;
71
    }
72
}
73