Passed
Push — master ( 25e5cd...485fad )
by Thorsten
01:51
created

AggregateAlias::__toString()   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 AggregateAlias 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 $alias;
20
21 5
    public static function fromNative($alias): ValueObjectInterface
22
    {
23 5
        Assertion::string($alias);
24 5
        return new static(trim($alias));
25
    }
26
27 1
    public static function makeEmpty(): ValueObjectInterface
28
    {
29 1
        throw new \Exception('Creating empty aggregate aliases is not supported.');
30
    }
31
32 2
    public function toNative()
33
    {
34 2
        return $this->alias;
35
    }
36
37 1
    public function equals(ValueObjectInterface $alias): bool
38
    {
39 1
        Assertion::isInstanceOf($alias, static::class);
40 1
        return $this->alias === $alias->toNative();
41
    }
42
43 1
    public function isEmpty(): bool
44
    {
45 1
        return false;
46
    }
47
48 2
    public function __toString(): string
49
    {
50 2
        return $this->alias;
51
    }
52
53 5
    private function __construct(string $alias)
54
    {
55 5
        Assertion::notEmpty($alias);
56 5
        $this->alias = $alias;
57 5
    }
58
}
59