XidIdentity   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 8
c 1
b 0
f 0
dl 0
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A fromString() 0 13 2
1
<?php
2
3
/*
4
 * identity-extra (https://github.com/phpgears/identity-extra).
5
 * Identity objects for PHP.
6
 *
7
 * @license MIT
8
 * @link https://github.com/phpgears/identity-extra
9
 * @author Julián Gutiérrez <[email protected]>
10
 */
11
12
declare(strict_types=1);
13
14
namespace Gears\Identity\Extra;
15
16
use Fpay\Xid\Exception as XidException;
17
use Fpay\Xid\Generator;
18
use Gears\Identity\AbstractIdentity;
19
use Gears\Identity\Exception\InvalidIdentityException;
20
21
/**
22
 * Globally Unique ID identity.
23
 */
24
class XidIdentity extends AbstractIdentity
25
{
26
    /**
27
     * {@inheritdoc}
28
     *
29
     * @throws InvalidIdentityException
30
     */
31
    final public static function fromString(string $value)
32
    {
33
        try {
34
            Generator::fromString($value);
35
        } catch (XidException $exception) {
36
            throw new InvalidIdentityException(
37
                \sprintf('Provided identity value "%s" is not a valid Xid.', $value),
38
                0,
39
                $exception
40
            );
41
        }
42
43
        return new static($value);
44
    }
45
}
46