Uuid7   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 13
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 5 3
A __construct() 0 4 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