Completed
Push — master ( 3a35ab...03a056 )
by Julián
06:43
created

ShortUuidAggregateIdentity   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 19
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromString() 0 11 3
1
<?php
2
3
/*
4
 * aggregate (https://github.com/phpgears/aggregate).
5
 * Aggregate base.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/aggregate
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\Aggregate;
15
16
use Gears\Identity\Exception\InvalidIdentityException;
17
use PascalDeVink\ShortUuid\ShortUuid;
18
use Ramsey\Uuid\Uuid;
19
20
/**
21
 * Base immutable short UUID aggregate identity.
22
 */
23
class ShortUuidAggregateIdentity extends AbstractAggregateIdentity
24
{
25
    /**
26
     * {@inheritdoc}
27
     *
28
     * @throws InvalidIdentityException
29
     */
30
    public static function fromString(string $value)
31
    {
32
        $uuid = (new ShortUuid())->decode($value);
33
        if ($uuid->getVariant() !== Uuid::RFC_4122 || !\in_array($uuid->getVersion(), \range(1, 5), true)) {
34
            throw new InvalidIdentityException(
35
                \sprintf('Provided identity value "%s" is not a valid short UUID', $value)
36
            );
37
        }
38
39
        return new static($value);
40
    }
41
}
42