Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| TimestampIdGenerator | |
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
3 | |
100.00% |
1 / 1 |
| generate | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| from | |
100.00% |
1 / 1 |
|
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 Override; |
| 13 | use Phexium\Domain\Id\TimestampId; |
| 14 | use Phexium\Plugin\IdGenerator\Port\IdGeneratorInterface; |
| 15 | |
| 16 | final readonly class TimestampIdGenerator implements IdGeneratorInterface |
| 17 | { |
| 18 | #[Override] |
| 19 | public function generate(): TimestampId |
| 20 | { |
| 21 | $microtime = microtime(true); |
| 22 | |
| 23 | $timestamp = (int) ($microtime * 1000000); |
| 24 | |
| 25 | return new TimestampId($timestamp); |
| 26 | } |
| 27 | |
| 28 | #[Override] |
| 29 | public function from(int|string $id): TimestampId |
| 30 | { |
| 31 | return new TimestampId(is_int($id) ? $id : (int) $id); |
| 32 | } |
| 33 | } |