Uuid6   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 39
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getListenerArgs() 0 8 2
A __construct() 0 10 1
A getListenerClass() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\ORM\Entity\Behavior\Uuid;
6
7
use Cycle\ORM\Entity\Behavior\Uuid\Listener\Uuid6 as Listener;
8
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
9
use Doctrine\Common\Annotations\Annotation\Target;
10
use JetBrains\PhpStorm\ArrayShape;
11
use Ramsey\Uuid\Type\Hexadecimal;
12
13
/**
14
 * Uses a version 6 (ordered-time) UUID from a host ID, sequence number,
15
 * and the current time
16
 *
17
 * @Annotation
18
 * @NamedArgumentConstructor()
19
 * @Target({"CLASS"})
20
 */
21
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE), NamedArgumentConstructor]
22
final class Uuid6 extends Uuid
23
{
24
    /**
25
     * @param non-empty-string $field Uuid property name
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string.
Loading history...
26
     * @param non-empty-string|null $column Uuid column name
27
     * @param Hexadecimal|string|null $node A 48-bit number representing the hardware
28
     * @param int|null $clockSeq A 14-bit number used to help avoid duplicates
29
     *     that could arise when the clock is set backwards in time or if the
30
     *     node ID changes
31
     * @param bool $nullable Indicates whether to generate a new UUID or not
32
     *
33
     * @see \Ramsey\Uuid\UuidFactoryInterface::uuid6()
34
     */
35
    public function __construct(
36
        string $field = 'uuid',
37
        ?string $column = null,
38
        private Hexadecimal|string|null $node = null,
39
        private ?int $clockSeq = null,
40
        bool $nullable = false
41
    ) {
42
        $this->field = $field;
43
        $this->column = $column;
44
        $this->nullable = $nullable;
45
    }
46
47
    protected function getListenerClass(): string
48
    {
49
        return Listener::class;
50
    }
51
52
    #[ArrayShape(['field' => 'string', 'node' => 'string|null', 'clockSeq' => 'int|null', 'nullable' => 'bool'])]
53
    protected function getListenerArgs(): array
54
    {
55
        return [
56
            'field' => $this->field,
57
            'node' => $this->node instanceof Hexadecimal ? (string) $this->node : $this->node,
58
            'clockSeq' => $this->clockSeq,
59
            'nullable' => $this->nullable
60
        ];
61
    }
62
}
63