Completed
Push — master ( 36d9c1...0b1be7 )
by Julián
05:28
created

ObjectIdIdentity::fromString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
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 Gears\Identity\AbstractIdentity;
17
use Gears\Identity\Exception\InvalidIdentityException;
18
use MongoDB\BSON\ObjectId;
19
use MongoDB\Driver\Exception\InvalidArgumentException;
20
21
/**
22
 * Mongo ObjectId identity.
23
 */
24
class ObjectIdIdentity extends AbstractIdentity
25
{
26
    /**
27
     * {@inheritdoc}
28
     *
29
     * @throws InvalidIdentityException
30
     */
31
    final public static function fromString(string $value)
32
    {
33
        try {
34
            new ObjectId($value);
35
        } catch (InvalidArgumentException $exception) {
0 ignored issues
show
Bug introduced by
The class MongoDB\Driver\Exception\InvalidArgumentException does not exist. Did you forget a USE statement, or did you not list all dependencies?

Scrutinizer analyzes your composer.json/composer.lock file if available to determine the classes, and functions that are defined by your dependencies.

It seems like the listed class was neither found in your dependencies, nor was it found in the analyzed files in your repository. If you are using some other form of dependency management, you might want to disable this analysis.

Loading history...
36
            throw new InvalidIdentityException(
37
                \sprintf('Provided identity value "%s" is not a valid Mongo ObjectId', $value),
38
                0,
39
                $exception
40
            );
41
        }
42
43
        return new static($value);
44
    }
45
}
46