Passed
Push — master ( 33ccda...6d1632 )
by Thorsten
01:57
created

AggregateId::isEmpty()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 4
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 4
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * This file is part of the daikon-cqrs/cqrs 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
declare(strict_types=1);
10
11
namespace Daikon\EventSourcing\Aggregate;
12
13
use Assert\Assertion;
14
use Daikon\Entity\ValueObject\ValueObjectInterface;
15
16 View Code Duplication
final class AggregateId implements AggregateIdInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    /** @var string */
19
    private $id;
20
21 9
    public static function fromNative($id): ValueObjectInterface
22
    {
23 9
        return new self(trim($id));
24
    }
25
26 1
    public static function makeEmpty(): ValueObjectInterface
27
    {
28 1
        throw new \Exception("Creating empty aggregate-ids is not supported.");
29
    }
30
31 4
    public function toNative()
32
    {
33 4
        return $this->id;
34
    }
35
36 1
    public function equals(ValueObjectInterface $streamId): bool
37
    {
38 1
        Assertion::isInstanceOf($streamId, static::class);
39 1
        return $this->id === $streamId->toNative();
40
    }
41
42 1
    public function isEmpty(): bool
43
    {
44 1
        return false;
45
    }
46
47 2
    public function __toString(): string
48
    {
49 2
        return $this->id;
50
    }
51
52 9
    private function __construct(string $id)
53
    {
54 9
        Assertion::notEmpty($id);
55 9
        $this->id = $id;
56 9
    }
57
}
58