| Total Complexity | 7 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | abstract class AbstractUuid implements UuidProtocol |
||
| 22 | { |
||
| 23 | private UuidInterface $uuid; |
||
| 24 | |||
| 25 | final public function __construct(UuidInterface $uuid) |
||
| 26 | { |
||
| 27 | $this->uuid = $uuid; |
||
| 28 | } |
||
| 29 | |||
| 30 | public static function generate(): IdProtocol |
||
| 31 | { |
||
| 32 | try { |
||
| 33 | return new static(Uuid::uuid4()); |
||
| 34 | } catch (\Throwable $exception) { |
||
| 35 | throw new \RuntimeException('Cannot generate a new uuid.', 0, $exception); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | |||
| 39 | public function toString(): string |
||
| 42 | } |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @param UuidInterface $uuid |
||
| 46 | */ |
||
| 47 | public static function fromUuid(object $uuid): UuidProtocol |
||
| 48 | { |
||
| 49 | if (!$uuid instanceof UuidInterface) { |
||
| 50 | throw new \InvalidArgumentException('UuidInterface type excepted.'); |
||
| 51 | } |
||
| 52 | |||
| 53 | return new static($uuid); |
||
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @return static |
||
| 58 | */ |
||
| 59 | public static function fromString(string $uuid) |
||
| 62 | } |
||
| 63 | } |
||
| 64 |