| Total Complexity | 6 |
| Total Lines | 57 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | final class ClientId |
||
| 11 | { |
||
| 12 | /** |
||
| 13 | * This field indicates the name of the clientId that we'll pass on to the broker. |
||
| 14 | * |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | private $clientId; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * QoSLevel constructor. |
||
| 21 | * |
||
| 22 | * @param int $packetIdentifier |
||
| 23 | * @throws \OutOfRangeException |
||
| 24 | */ |
||
| 25 | public function __construct(string $clientId) |
||
| 26 | { |
||
| 27 | if ($clientId !== '') { |
||
| 28 | $this->clientId = $clientId; |
||
| 29 | $clientIdSize = \strlen($this->clientId); |
||
| 30 | $utf8ClientIdSize = \mb_strlen($this->clientId); |
||
| 31 | |||
| 32 | if ($clientIdSize !== $utf8ClientIdSize) { |
||
| 33 | $this->logger->warning('The broker MAY reject the connection because of invalid characters'); |
||
|
|
|||
| 34 | } |
||
| 35 | |||
| 36 | if ($utf8ClientIdSize > 23) { |
||
| 37 | $this->logger->warning('The broker MAY reject the connection because the ClientId is too long'); |
||
| 38 | } |
||
| 39 | } else { |
||
| 40 | /* |
||
| 41 | * If you ever wind up in this situation, search for MQTT-3.1.3-7 on the following document for more |
||
| 42 | * information: http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718067 |
||
| 43 | */ |
||
| 44 | $this->logger->warning('ClientId size is 0 bytes. This has several implications, check comments', [ |
||
| 45 | 'file' => __FILE__, |
||
| 46 | 'line' => __LINE__, |
||
| 47 | ]); |
||
| 48 | $this->cleanSession = true; |
||
| 49 | } |
||
| 50 | |||
| 51 | $this->clientId = $clientId; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Gets the current clientId |
||
| 56 | * |
||
| 57 | * @return string |
||
| 58 | */ |
||
| 59 | public function getClientId(): string |
||
| 62 | } |
||
| 63 | |||
| 64 | public function __toString(): string |
||
| 67 | } |
||
| 68 | } |
||
| 69 |