Profile   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 21
c 1
b 0
f 0
dl 0
loc 61
rs 10

7 Methods

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