Domain   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 13
dl 0
loc 53
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getName() 0 3 1
A fromString() 0 6 1
A getUuid() 0 3 1
A build() 0 3 1
A getValue() 0 3 1
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 $string
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