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\Type\Integer as IntegerObject; |
||||
11 | use Ramsey\Uuid\Uuid; |
||||
12 | |||||
13 | final class Uuid2 |
||||
14 | { |
||||
15 | 8 | public function __construct( |
|||
16 | private int $localDomain, |
||||
17 | private string $field = 'uuid', |
||||
18 | private IntegerObject|string|null $localIdentifier = null, |
||||
19 | private Hexadecimal|string|null $node = null, |
||||
20 | private ?int $clockSeq = null, |
||||
21 | private bool $nullable = false |
||||
22 | 8 | ) { |
|||
23 | } |
||||
24 | 8 | ||||
25 | #[Listen(OnCreate::class)] |
||||
26 | public function __invoke(OnCreate $event): void |
||||
27 | 8 | { |
|||
28 | if ($this->nullable || isset($event->state->getData()[$this->field])) { |
||||
29 | return; |
||||
30 | 8 | } |
|||
31 | |||||
32 | if (\is_string($this->localIdentifier)) { |
||||
33 | $this->localIdentifier = new IntegerObject($this->localIdentifier); |
||||
34 | 8 | } |
|||
35 | 8 | if (\is_string($this->node)) { |
|||
36 | 8 | $this->node = new Hexadecimal($this->node); |
|||
37 | 8 | } |
|||
38 | |||||
39 | $event->state->register( |
||||
40 | 8 | $this->field, |
|||
41 | Uuid::uuid2($this->localDomain, $this->localIdentifier, $this->node, $this->clockSeq) |
||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
It seems like
$this->localIdentifier can also be of type string ; however, parameter $localIdentifier of Ramsey\Uuid\Uuid::uuid2() does only seem to accept Ramsey\Uuid\Type\Integer|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
Loading history...
|
|||||
42 | ); |
||||
43 | } |
||||
44 | } |
||||
45 |