Issues (10)

src/Uuid1.php (1 issue)

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\Uuid1 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 1 (time-based) 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 Uuid1 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|int|string|null $node A 48-bit number representing the
28
     *     hardware address; this number may be represented as an integer or a
29
     *     hexadecimal string
30
     * @param int|null $clockSeq A 14-bit number used to help avoid duplicates
31
     *     that could arise when the clock is set backwards in time or if the
32
     *     node ID changes
33
     * @param bool $nullable Indicates whether to generate a new UUID or not
34
     *
35
     * @see \Ramsey\Uuid\UuidFactoryInterface::uuid1()
36 16
     */
37
    public function __construct(
38
        string $field = 'uuid',
39
        ?string $column = null,
40
        private Hexadecimal|int|string|null $node = null,
41
        private ?int $clockSeq = null,
42 16
        bool $nullable = false
43 16
    ) {
44 16
        $this->field = $field;
45
        $this->column = $column;
46 16
        $this->nullable = $nullable;
47
    }
48 16
49
    protected function getListenerClass(): string
50
    {
51 16
        return Listener::class;
52
    }
53
54
    #[ArrayShape(['field' => 'string', 'node' => 'int|string|null', 'clockSeq' => 'int|null', 'nullable' => 'bool'])]
55 16
    protected function getListenerArgs(): array
56 16
    {
57 16
        return [
58
            'field' => $this->field,
59
            'node' => $this->node instanceof Hexadecimal ? (string) $this->node : $this->node,
60
            'clockSeq' => $this->clockSeq,
61
            'nullable' => $this->nullable
62
        ];
63
    }
64
}
65