Uuid7   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
dl 0
loc 31
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getListenerClass() 0 3 1
A getListenerArgs() 0 6 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\Uuid7 as Listener;
8
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
9
use Doctrine\Common\Annotations\Annotation\Target;
10
use JetBrains\PhpStorm\ArrayShape;
11
12
/**
13
 * Uses a version 7 (Unix Epoch Time) UUID
14
 *
15
 * @Annotation
16
 * @NamedArgumentConstructor()
17
 * @Target({"CLASS"})
18
 */
19
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE), NamedArgumentConstructor]
20
final class Uuid7 extends Uuid
21
{
22
    /**
23
     * @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...
24
     * @param non-empty-string|null $column Uuid column name
25
     * @param bool $nullable Indicates whether to generate a new UUID or not
26
     *
27
     * @see \Ramsey\Uuid\UuidFactoryInterface::uuid7()
28
     */
29
    public function __construct(
30
        string $field = 'uuid',
31
        ?string $column = null,
32
        bool $nullable = false
33
    ) {
34
        $this->field = $field;
35
        $this->column = $column;
36
        $this->nullable = $nullable;
37
    }
38
39
    protected function getListenerClass(): string
40
    {
41
        return Listener::class;
42
    }
43
44
    #[ArrayShape(['field' => 'string', 'nullable' => 'bool'])]
45
    protected function getListenerArgs(): array
46
    {
47
        return [
48
            'field' => $this->field,
49
            'nullable' => $this->nullable
50
        ];
51
    }
52
}
53