Passed
Push — master ( 1457de...9c6417 )
by Tomasz
02:07
created

Profile::getVersion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
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\Domain\Profile;
15
16
use Assert\Assertion;
17
18
class Profile
19
{
20
    private const SEPARATOR = ':';
21
22
    /** @var string */
23
    private $name;
24
25
    /** @var string */
26
    private $version;
27
28
    private function __construct(string $name, string $version)
29
    {
30
        $this->name = $name;
31
        $this->version = $version;
32
    }
33
34
    public static function createFromParts(string $name, string $version): self
35
    {
36
        Assertion::regex($name, sprintf('/^[^%s]*$/', self::SEPARATOR));
37
        Assertion::regex($version, sprintf('/^[^%s]*$/', self::SEPARATOR));
38
39
        return new self($name, $version);
40
    }
41
42
    public static function createFromName(string $fullName): self
43
    {
44
        $parts = explode(self::SEPARATOR, $fullName);
45
        Assertion::count($parts, 2);
46
47
        $name = $parts[0];
48
        $version = $parts[1];
49
50
        Assertion::regex($name, sprintf('/^[^%s]*$/', self::SEPARATOR));
51
        Assertion::regex($version, sprintf('/^[^%s]*$/', self::SEPARATOR));
52
53
        return new self($name, $version);
54
    }
55
56
    public function equal(self $profile): bool
57
    {
58
        return $this->name === $profile->name
59
            && $this->version === $profile->version;
60
    }
61
62
    public function __toString(): string
63
    {
64
        return $this->name . self::SEPARATOR . $this->version;
65
    }
66
67
    public function getName(): string
68
    {
69
        return $this->name;
70
    }
71
72
    public function getVersion(): string
73
    {
74
        return $this->version;
75
    }
76
}
77