| Total Complexity | 4 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 8 | class ClientIdSession implements ClientIdRepository |
||
| 9 | { |
||
| 10 | private Store $session; |
||
| 11 | private string $key; |
||
| 12 | |||
| 13 | public function __construct(Store $session, string $key) |
||
| 14 | { |
||
| 15 | $this->session = $session; |
||
| 16 | $this->key = $key; |
||
| 17 | } |
||
| 18 | |||
| 19 | /** |
||
| 20 | * Stores the Client ID in the session. |
||
| 21 | */ |
||
| 22 | public function update(string $clientId): void |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Gets the Client ID from the session or generates one. |
||
| 29 | */ |
||
| 30 | public function get(): ?string |
||
| 31 | { |
||
| 32 | return $this->session->get($this->key, fn () => $this->generateId()); |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Generates a UUID and stores it in the session. |
||
| 37 | */ |
||
| 38 | private function generateId(): string |
||
| 41 | } |
||
| 42 | } |
||
| 43 |