Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
Ulid | |
100.00% |
3 / 3 |
|
100.00% |
2 / 2 |
2 | |
100.00% |
1 / 1 |
getRegularExpression | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createRandom | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | namespace Apie\Core\Identifiers; |
3 | |
4 | use Apie\Core\Attributes\Description; |
5 | use Apie\Core\Attributes\FakeMethod; |
6 | use Apie\Core\ValueObjects\Interfaces\HasRegexValueObjectInterface; |
7 | use Apie\Core\ValueObjects\IsStringWithRegexValueObject; |
8 | use Symfony\Component\Uid\Ulid as SymfonyUlid; |
9 | |
10 | #[FakeMethod('createRandom')] |
11 | #[Description('Ulid in base58 format')] |
12 | class Ulid implements HasRegexValueObjectInterface |
13 | { |
14 | use IsStringWithRegexValueObject; |
15 | |
16 | public static function getRegularExpression(): string |
17 | { |
18 | // TODO stricter base58 |
19 | return '/^[a-zA-Z0-9]{22}$/i'; |
20 | } |
21 | |
22 | public static function createRandom(): static |
23 | { |
24 | $ulid = new SymfonyUlid(); |
25 | return static::fromNative($ulid->toBase58()); |
26 | } |
27 | } |