Uuid2   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 22
dl 0
loc 59
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getListenerClass() 0 3 1
A getListenerArgs() 0 19 3
A __construct() 0 12 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\Uuid2 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
use Ramsey\Uuid\Type\Integer as IntegerObject;
13
14
/**
15
 * Uses a version 2 (DCE Security) UUID from a local domain, local
16
 * identifier, host ID, clock sequence, and the current time
17
 *
18
 * @Annotation
19
 * @NamedArgumentConstructor()
20
 * @Target({"CLASS"})
21
 */
22
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE), NamedArgumentConstructor]
23
final class Uuid2 extends Uuid
24
{
25
    /**
26
     * @param int $localDomain The local domain to use when generating bytes,
27
     *     according to DCE Security
28
     * @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...
29
     * @param non-empty-string|null $column Uuid column name
30
     * @param IntegerObject|string|null $localIdentifier The local identifier for the
31
     *     given domain; this may be a UID or GID on POSIX systems, if the local
32
     *     domain is person or group, or it may be a site-defined identifier
33
     *     if the local domain is org
34
     * @param Hexadecimal|string|null $node A 48-bit number representing the hardware
35
     *     address
36
     * @param int|null $clockSeq A 14-bit number used to help avoid duplicates
37
     *     that could arise when the clock is set backwards in time or if the
38
     *     node ID changes
39
     * @param bool $nullable Indicates whether to generate a new UUID or not
40
     *
41
     * @see \Ramsey\Uuid\UuidFactoryInterface::uuid2()
42
     */
43
    public function __construct(
44
        private int $localDomain,
45
        string $field = 'uuid',
46
        ?string $column = null,
47
        private IntegerObject|string|null $localIdentifier = null,
48
        private Hexadecimal|string|null $node = null,
49
        private ?int $clockSeq = null,
50
        bool $nullable = false
51
    ) {
52
        $this->field = $field;
53
        $this->column = $column;
54
        $this->nullable = $nullable;
55
    }
56
57
    protected function getListenerClass(): string
58
    {
59
        return Listener::class;
60
    }
61
62
    #[ArrayShape([
63
        'field' => 'string',
64
        'localDomain' => 'int',
65
        'localIdentifier' => 'string|null',
66
        'node' => 'string|null',
67
        'clockSeq' => 'int|null',
68
        'nullable' => 'bool'
69
    ])]
70
    protected function getListenerArgs(): array
71
    {
72
        return [
73
            'field' => $this->field,
74
            'localDomain' => $this->localDomain,
75
            'localIdentifier' => $this->localIdentifier instanceof IntegerObject
76
                ? (string) $this->localIdentifier
77
                : $this->localIdentifier,
78
            'node' => $this->node instanceof Hexadecimal ? (string) $this->node : $this->node,
79
            'clockSeq' => $this->clockSeq,
80
            'nullable' => $this->nullable
81
        ];
82
    }
83
}
84