GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( d795b6...2a6b46 )
by joseph
21:47
created

UuidFactory   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 30.76%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 91
ccs 8
cts 26
cp 0.3076
rs 10
wmc 8

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A createOrderedTimeFactory() 0 9 1
A getUuidFactory() 0 3 1
A getOrderedTimeFactory() 0 3 1
A getOrderedTimeUuidFromString() 0 14 2
A getUuid() 0 3 1
A getOrderedTimeUuid() 0 3 1
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Factories;
4
5
use Exception;
6
use InvalidArgumentException;
7
use Ramsey\Uuid\Codec\OrderedTimeCodec;
8
use Ramsey\Uuid\UuidInterface;
9
10
class UuidFactory
11
{
12
13
    /**
14
     * @var \Ramsey\Uuid\UuidFactory
15
     */
16
    private $orderedTimeFactory;
17
    /**
18
     * @var \Ramsey\Uuid\UuidFactory
19
     */
20
    private $uuidFactory;
21
22
    public function __construct(\Ramsey\Uuid\UuidFactory $uuidFactory)
23
    {
24
25
        $this->orderedTimeFactory = $this->createOrderedTimeFactory($uuidFactory);
26
        $this->uuidFactory        = $uuidFactory;
27
    }
28
29
    private function createOrderedTimeFactory(\Ramsey\Uuid\UuidFactory $uuidFactory): \Ramsey\Uuid\UuidFactory
30
    {
31
        $this->orderedTimeFactory = clone $uuidFactory;
32
        $codec                    = new OrderedTimeCodec(
33
            $this->orderedTimeFactory->getUuidBuilder()
34
        );
35
        $this->orderedTimeFactory->setCodec($codec);
36
37
        return $this->orderedTimeFactory;
38
    }
39
40
    /**
41
     * Get a UUID interface from an ordered time UUID string
42
     *
43
     * @param string $uuidString
44
     *
45
     * @return UuidInterface
46
     */
47 1
    public function getOrderedTimeUuidFromString(string $uuidString): UuidInterface
48
    {
49 1
        $uuid = $this->orderedTimeFactory->fromString($uuidString);
50 1
        if (1 !== $uuid->getVersion()) {
51
            throw new InvalidArgumentException(
52
                'UUID version is invalid, shoudl be version 1 when creating from string ' .
53
                $uuidString
54
                .
55
                "\n\n Make sure when querying the db you are using `bin_to_uuid(id, true)` "
56
                . "\ni.e passing in the second param to true to make MySQL use ordered time\n"
57
            );
58
        }
59
60 1
        return $uuid;
61
    }
62
63
    /**
64
     * This is used to get ordered time UUIDs as used in:
65
     * \EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\PrimaryKey\UuidFieldTrait
66
     *
67
     * @return UuidInterface
68
     * @throws Exception
69
     */
70 2
    public function getOrderedTimeUuid(): UuidInterface
71
    {
72 2
        return $this->orderedTimeFactory->uuid1();
73
    }
74
75
    /**
76
     * This is used to generate standard UUIDs, as used in
77
     * \EdmondsCommerce\DoctrineStaticMeta\Entity\Fields\Traits\PrimaryKey\NonBinaryUuidFieldTrait
78
     *
79
     * @return UuidInterface
80
     * @throws Exception
81
     */
82 1
    public function getUuid(): UuidInterface
83
    {
84 1
        return $this->uuidFactory->uuid4();
85
    }
86
87
    /**
88
     * @return \Ramsey\Uuid\UuidFactory
89
     */
90
    public function getOrderedTimeFactory(): \Ramsey\Uuid\UuidFactory
91
    {
92
        return $this->orderedTimeFactory;
93
    }
94
95
    /**
96
     * @return \Ramsey\Uuid\UuidFactory
97
     */
98
    public function getUuidFactory(): \Ramsey\Uuid\UuidFactory
99
    {
100
        return $this->uuidFactory;
101
    }
102
}
103