CondensedUuidIdentity   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
c 1
b 0
f 0
dl 0
loc 34
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromUuid() 0 5 1
A fromString() 0 13 2
1
<?php
2
3
/*
4
 * identity (https://github.com/phpgears/identity).
5
 * Identity objects for PHP.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/identity
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\Identity;
15
16
use Gears\Identity\Exception\InvalidIdentityException;
17
18
/**
19
 * Condensed UUID identity.
20
 */
21
class CondensedUuidIdentity extends AbstractUuidIdentity
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    final public static function fromString(string $value)
27
    {
28
        try {
29
            static::uuidFromString(\sprintf('%s%s-%s-%s-%s-%s%s%s', ...\str_split($value, 4)));
30
        } catch (\Exception $exception) {
31
            throw new InvalidIdentityException(
32
                \sprintf('Provided identity value "%s" is not a valid condensed UUID.', $value),
33
                0,
34
                $exception
35
            );
36
        }
37
38
        return new static($value);
39
    }
40
41
    /**
42
     * Get identity from UUID string.
43
     *
44
     * @param string $value
45
     *
46
     * @throws InvalidIdentityException
47
     *
48
     * @return mixed|static
49
     */
50
    final public static function fromUuid(string $value)
51
    {
52
        $uuid = static::uuidFromString($value);
53
54
        return new static(\str_replace('-', '', $uuid->toString()));
55
    }
56
}
57