Issues (10)

src/Listener/Uuid6.php (1 issue)

Labels
Severity
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\Type\Hexadecimal;
10
use Ramsey\Uuid\Uuid;
11
12
final class Uuid6
13
{
14 8
    public function __construct(
15
        private string $field = 'uuid',
16
        private Hexadecimal|string|null $node = null,
17
        private ?int $clockSeq = null,
18
        private bool $nullable = false
19 8
    ) {
20
    }
21 8
22
    #[Listen(OnCreate::class)]
23
    public function __invoke(OnCreate $event): void
24 8
    {
25
        if ($this->nullable || isset($event->state->getData()[$this->field])) {
26
            return;
27
        }
28 8
29 8
        if (\is_string($this->node)) {
30
            $this->node = new Hexadecimal($this->node);
31 8
        }
32
33
        $event->state->register($this->field, Uuid::uuid6($this->node, $this->clockSeq));
0 ignored issues
show
It seems like $this->node can also be of type string; however, parameter $node of Ramsey\Uuid\Uuid::uuid6() does only seem to accept Ramsey\Uuid\Type\Hexadecimal|null, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        $event->state->register($this->field, Uuid::uuid6(/** @scrutinizer ignore-type */ $this->node, $this->clockSeq));
Loading history...
34
    }
35
}
36