Passed
Push — master ( 134841...7712b0 )
by Mr
02:17
created

AggregateId::equals()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
ccs 3
cts 3
cp 1
crap 1
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/event-sourcing project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\EventSourcing\Aggregate;
10
11
use Daikon\Interop\Assertion;
12
13
class AggregateId implements AggregateIdInterface
14
{
15
    public const PATTERN = '/^.*$/';
16
17
    private string $id;
18
19
    /**
20
     * @param string $id
21
     * @return static
22
     */
23 8
    public static function fromNative($id): self
24
    {
25 8
        Assertion::regex($id, static::PATTERN, 'Invalid id format.');
26 8
        return new static($id);
27
    }
28
29 6
    public function toNative(): string
30
    {
31 6
        return $this->id;
32
    }
33
34
    /** @param static $comparator */
35 4
    public function equals($comparator): bool
36
    {
37 4
        Assertion::isInstanceOf($comparator, static::class);
38 4
        return $this->toNative() === $comparator->toNative();
39
    }
40
41 6
    public function __toString(): string
42
    {
43 6
        return $this->id;
44
    }
45
46 8
    private function __construct(string $id)
47
    {
48 8
        $this->id = $id;
49 8
    }
50
}
51