Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
6 / 6 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| Uuid | |
100.00% |
6 / 6 |
|
100.00% |
5 / 5 |
7 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| __toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| generate | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| value | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| equals | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Shared\Domain\ValueObject; |
| 6 | |
| 7 | use InvalidArgumentException; |
| 8 | use Symfony\Component\Uid\Uuid as SymfonyUuid; |
| 9 | |
| 10 | abstract class Uuid |
| 11 | { |
| 12 | final public function __construct(private readonly string $value) |
| 13 | { |
| 14 | if (!SymfonyUuid::isValid($value)) { |
| 15 | throw new InvalidArgumentException(sprintf('<%s> does not allow the value <%s>.', static::class, $value)); |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | public function __toString(): string |
| 20 | { |
| 21 | return $this->value; |
| 22 | } |
| 23 | |
| 24 | public static function generate(): static |
| 25 | { |
| 26 | return new static(SymfonyUuid::v7()->toRfc4122()); |
| 27 | } |
| 28 | |
| 29 | public function value(): string |
| 30 | { |
| 31 | return $this->value; |
| 32 | } |
| 33 | |
| 34 | public function equals(self $other): bool |
| 35 | { |
| 36 | return $this::class === $other::class && $this->value === $other->value; |
| 37 | } |
| 38 | } |