Uuid5   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 12
dl 0
loc 37
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 8 2
A __construct() 0 10 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\Uuid5 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\UuidInterface;
12
13
/**
14
 * Uses a version 5 (name-based) UUID based on the SHA-1 hash of a
15
 * namespace ID and a name
16
 *
17
 * @Annotation
18
 * @NamedArgumentConstructor()
19
 * @Target({"CLASS"})
20
 */
21
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE), NamedArgumentConstructor]
22
final class Uuid5 extends Uuid
23
{
24
    /**
25
     * @param non-empty-string|UuidInterface $namespace The namespace (must be a valid UUID)
0 ignored issues
show
Documentation Bug introduced by
The doc comment non-empty-string|UuidInterface at position 0 could not be parsed: Unknown type name 'non-empty-string' at position 0 in non-empty-string|UuidInterface.
Loading history...
26
     * @param non-empty-string $name The name to use for creating a UUID
27
     * @param non-empty-string $field Uuid property name
28
     * @param non-empty-string|null $column Uuid column name
29
     * @param bool $nullable Indicates whether to generate a new UUID or not
30
     *
31
     * @see \Ramsey\Uuid\UuidFactoryInterface::uuid5()
32
     */
33
    public function __construct(
34
        private string|UuidInterface $namespace,
35
        private string $name,
36
        string $field = 'uuid',
37
        ?string $column = null,
38
        bool $nullable = false
39
    ) {
40
        $this->field = $field;
41
        $this->column = $column;
42
        $this->nullable = $nullable;
43
    }
44
45
    protected function getListenerClass(): string
46
    {
47
        return Listener::class;
48
    }
49
50
    #[ArrayShape(['field' => 'string', 'namespace' => 'string', 'name' => 'string', 'nullable' => 'bool'])]
51
    protected function getListenerArgs(): array
52
    {
53
        return [
54
            'field' => $this->field,
55
            'namespace' => $this->namespace instanceof UuidInterface ? (string) $this->namespace : $this->namespace,
56
            'name' => $this->name,
57
            'nullable' => $this->nullable
58
        ];
59
    }
60
}
61