Uuid5   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 4
dl 0
loc 15
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __invoke() 0 5 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cycle\ORM\Entity\Behavior\Uuid\Listener;
6
7
use Cycle\ORM\Entity\Behavior\Attribute\Listen;
8
use Cycle\ORM\Entity\Behavior\Event\Mapper\Command\OnCreate;
9
use Ramsey\Uuid\Uuid;
10
use Ramsey\Uuid\UuidInterface;
11
12
final class Uuid5
13
{
14 8
    public function __construct(
15
        private string|UuidInterface $namespace,
16
        private string $name,
17
        private string $field = 'uuid',
18
        private bool $nullable = false
19 8
    ) {
20
    }
21 8
22
    #[Listen(OnCreate::class)]
23
    public function __invoke(OnCreate $event): void
24 8
    {
25 8
        if (!$this->nullable && !isset($event->state->getData()[$this->field])) {
26
            $event->state->register($this->field, Uuid::uuid5($this->namespace, $this->name));
27 8
        }
28
    }
29
}
30