Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| UuidV7Generator | |
100.00% |
5 / 5 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| generate | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| from | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Phexium\Plugin\IdGenerator\Adapter; |
| 11 | |
| 12 | use LogicException; |
| 13 | use Override; |
| 14 | use Phexium\Domain\Id\UuidV7; |
| 15 | use Phexium\Plugin\IdGenerator\Port\IdGeneratorInterface; |
| 16 | use Ramsey\Uuid\Uuid; |
| 17 | |
| 18 | final readonly class UuidV7Generator implements IdGeneratorInterface |
| 19 | { |
| 20 | #[Override] |
| 21 | public function generate(): UuidV7 |
| 22 | { |
| 23 | $uuid = Uuid::uuid7(); |
| 24 | |
| 25 | return UuidV7::from($uuid->toString()); |
| 26 | } |
| 27 | |
| 28 | #[Override] |
| 29 | public function from(int|string $id): UuidV7 |
| 30 | { |
| 31 | if (is_int($id)) { |
| 32 | throw new LogicException('UuidV7 generator cannot create UUIDs from integers. Use string UUIDs instead.'); |
| 33 | } |
| 34 | |
| 35 | return UuidV7::from($id); |
| 36 | } |
| 37 | } |