Uuid7::__invoke()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
dl 0
loc 5
rs 10
c 1
b 0
f 0
cc 3
nc 2
nop 1
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
11
final class Uuid7
12
{
13
    public function __construct(
14
        private string $field = 'uuid',
15
        private bool $nullable = false
16
    ) {
17
    }
18
19
    #[Listen(OnCreate::class)]
20
    public function __invoke(OnCreate $event): void
21
    {
22
        if (!$this->nullable && !isset($event->state->getData()[$this->field])) {
23
            $event->state->register($this->field, Uuid::uuid7());
24
        }
25
    }
26
}
27