diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8143bf4..7aa9c09 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -15,10 +15,10 @@ jobs: strategy: matrix: - php-version: ['7.4', '8.0', '8.1'] + php-version: ['8.0', '8.1', '8.2', '8.3'] mqtt-broker: ['mosquitto-1.6', 'mosquitto-2.0', 'hivemq', 'emqx', 'rabbitmq'] include: - - php-version: '8.1' + - php-version: '8.3' mqtt-broker: 'mosquitto-2.0' run-sonarqube-analysis: true diff --git a/composer.json b/composer.json index 0d0cddb..1c21492 100644 --- a/composer.json +++ b/composer.json @@ -27,7 +27,7 @@ } }, "require": { - "php": "^7.4|^8.0", + "php": "^8.0", "psr/log": "^1.1|^2.0|^3.0", "myclabs/php-enum": "^1.7" }, diff --git a/src/Concerns/GeneratesRandomClientIds.php b/src/Concerns/GeneratesRandomClientIds.php index 8e019ee..3c2369b 100644 --- a/src/Concerns/GeneratesRandomClientIds.php +++ b/src/Concerns/GeneratesRandomClientIds.php @@ -13,8 +13,6 @@ trait GeneratesRandomClientIds { /** * Generates a random client id in the form of an md5 hash. - * - * @return string */ protected function generateRandomClientId(): string { diff --git a/src/Concerns/OffersHooks.php b/src/Concerns/OffersHooks.php index fb8afe5..ff8e5e8 100644 --- a/src/Concerns/OffersHooks.php +++ b/src/Concerns/OffersHooks.php @@ -28,8 +28,6 @@ trait OffersHooks /** * Needs to be called in order to initialize the trait. - * - * @return void */ protected function initializeEventHandlers(): void { @@ -59,9 +57,6 @@ protected function initializeEventHandlers(): void * ``` * * Multiple event handlers can be registered at the same time. - * - * @param \Closure $callback - * @return MqttClient */ public function registerLoopEventHandler(\Closure $callback): MqttClient { @@ -77,9 +72,6 @@ public function registerLoopEventHandler(\Closure $callback): MqttClient * * This does not affect other registered event handlers. It is possible * to unregister all registered event handlers by passing null as callback. - * - * @param \Closure|null $callback - * @return MqttClient */ public function unregisterLoopEventHandler(\Closure $callback = null): MqttClient { @@ -96,9 +88,6 @@ public function unregisterLoopEventHandler(\Closure $callback = null): MqttClien /** * Runs all registered loop event handlers with the given parameters. * Each event handler is executed in a try-catch block to avoid spilling exceptions. - * - * @param float $elapsedTime - * @return void */ private function runLoopEventHandlers(float $elapsedTime): void { @@ -134,9 +123,6 @@ private function runLoopEventHandlers(float $elapsedTime): void * ``` * * Multiple event handlers can be registered at the same time. - * - * @param \Closure $callback - * @return MqttClient */ public function registerPublishEventHandler(\Closure $callback): MqttClient { @@ -152,9 +138,6 @@ public function registerPublishEventHandler(\Closure $callback): MqttClient * * This does not affect other registered event handlers. It is possible * to unregister all registered event handlers by passing null as callback. - * - * @param \Closure|null $callback - * @return MqttClient */ public function unregisterPublishEventHandler(\Closure $callback = null): MqttClient { @@ -171,13 +154,6 @@ public function unregisterPublishEventHandler(\Closure $callback = null): MqttCl /** * Runs all the registered publish event handlers with the given parameters. * Each event handler is executed in a try-catch block to avoid spilling exceptions. - * - * @param string $topic - * @param string $message - * @param int|null $messageId - * @param int $qualityOfService - * @param bool $retain - * @return void */ private function runPublishEventHandlers(string $topic, string $message, ?int $messageId, int $qualityOfService, bool $retain): void { @@ -214,9 +190,6 @@ private function runPublishEventHandlers(string $topic, string $message, ?int $m * ``` * * Multiple event handlers can be registered at the same time. - * - * @param \Closure $callback - * @return MqttClient */ public function registerMessageReceivedEventHandler(\Closure $callback): MqttClient { @@ -231,9 +204,6 @@ public function registerMessageReceivedEventHandler(\Closure $callback): MqttCli * * This does not affect other registered event handlers. It is possible * to unregister all registered event handlers by passing null as callback. - * - * @param \Closure|null $callback - * @return MqttClient */ public function unregisterMessageReceivedEventHandler(\Closure $callback = null): MqttClient { @@ -250,12 +220,6 @@ public function unregisterMessageReceivedEventHandler(\Closure $callback = null) /** * Runs all the registered message received event handlers with the given parameters. * Each event handler is executed in a try-catch block to avoid spilling exceptions. - * - * @param string $topic - * @param string $message - * @param int $qualityOfService - * @param bool $retained - * @return void */ private function runMessageReceivedEventHandlers(string $topic, string $message, int $qualityOfService, bool $retained): void { @@ -293,9 +257,6 @@ private function runMessageReceivedEventHandlers(string $topic, string $message, * ``` * * Multiple event handlers can be registered at the same time. - * - * @param \Closure $callback - * @return MqttClient */ public function registerConnectedEventHandler(\Closure $callback): MqttClient { @@ -310,9 +271,6 @@ public function registerConnectedEventHandler(\Closure $callback): MqttClient * * This does not affect other registered event handlers. It is possible * to unregister all registered event handlers by passing null as callback. - * - * @param \Closure|null $callback - * @return MqttClient */ public function unregisterConnectedEventHandler(\Closure $callback = null): MqttClient { @@ -329,9 +287,6 @@ public function unregisterConnectedEventHandler(\Closure $callback = null): Mqtt /** * Runs all the registered connected event handlers. * Each event handler is executed in a try-catch block to avoid spilling exceptions. - * - * @param bool $isAutoReconnect - * @return void */ private function runConnectedEventHandlers(bool $isAutoReconnect): void { diff --git a/src/Concerns/TranscodesData.php b/src/Concerns/TranscodesData.php index 9e73575..1c89f41 100644 --- a/src/Concerns/TranscodesData.php +++ b/src/Concerns/TranscodesData.php @@ -19,9 +19,6 @@ trait TranscodesData * \x00\x0bhello world * * where \x00\0x0b is the hex representation of 00000000 00001011 = 11 - * - * @param string $data - * @return string */ protected function buildLengthPrefixedString(string $data): string { @@ -35,9 +32,6 @@ protected function buildLengthPrefixedString(string $data): string /** * Converts the given string to a number, assuming it is an MSB encoded message id. * MSB means preceding characters have higher value. - * - * @param string $encodedMessageId - * @return int */ protected function decodeMessageId(string $encodedMessageId): int { @@ -53,9 +47,6 @@ protected function decodeMessageId(string $encodedMessageId): int /** * Encodes the given message identifier as string. - * - * @param int $messageId - * @return string */ protected function encodeMessageId(int $messageId): string { @@ -65,9 +56,6 @@ protected function encodeMessageId(int $messageId): string /** * Encodes the length of a message as string, so it can be transmitted * over the wire. - * - * @param int $length - * @return string */ protected function encodeMessageLength(int $length): string { diff --git a/src/Concerns/ValidatesConfiguration.php b/src/Concerns/ValidatesConfiguration.php index 078086e..8f62d23 100644 --- a/src/Concerns/ValidatesConfiguration.php +++ b/src/Concerns/ValidatesConfiguration.php @@ -21,8 +21,6 @@ trait ValidatesConfiguration * which means they are misconfigured, an exception containing information about * the configuration error is thrown. * - * @param ConnectionSettings $settings - * @return void * @throws ConfigurationInvalidException */ protected function ensureConnectionSettingsAreValid(ConnectionSettings $settings): void diff --git a/src/Concerns/WorksWithBuffers.php b/src/Concerns/WorksWithBuffers.php index a95da80..df29a4d 100644 --- a/src/Concerns/WorksWithBuffers.php +++ b/src/Concerns/WorksWithBuffers.php @@ -13,10 +13,6 @@ trait WorksWithBuffers { /** * Pops the first $limit bytes from the given buffer and returns them. - * - * @param string $buffer - * @param int $limit - * @return string */ protected function pop(string &$buffer, int $limit): string { diff --git a/src/ConnectionSettings.php b/src/ConnectionSettings.php index 490711d..864522f 100644 --- a/src/ConnectionSettings.php +++ b/src/ConnectionSettings.php @@ -41,7 +41,6 @@ class ConnectionSettings /** * The username used for authentication when connecting to the broker. * - * @param string|null $username * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setUsername(?string $username): ConnectionSettings @@ -53,9 +52,6 @@ public function setUsername(?string $username): ConnectionSettings return $copy; } - /** - * @return string|null - */ public function getUsername(): ?string { return $this->username; @@ -64,7 +60,6 @@ public function getUsername(): ?string /** * The password used for authentication when connecting to the broker. * - * @param string|null $password * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setPassword(?string $password): ConnectionSettings @@ -76,9 +71,6 @@ public function setPassword(?string $password): ConnectionSettings return $copy; } - /** - * @return string|null - */ public function getPassword(): ?string { return $this->password; @@ -91,7 +83,6 @@ public function getPassword(): ?string * * Note: This setting has no effect on subscriptions, only on the publishing of messages. * - * @param bool $useBlockingSocket * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function useBlockingSocket(bool $useBlockingSocket): ConnectionSettings @@ -103,9 +94,6 @@ public function useBlockingSocket(bool $useBlockingSocket): ConnectionSettings return $copy; } - /** - * @return bool - */ public function shouldUseBlockingSocket(): bool { return $this->useBlockingSocket; @@ -115,7 +103,6 @@ public function shouldUseBlockingSocket(): bool * The connect timeout is the maximum amount of seconds the client will try to establish * a socket connection with the broker. The value cannot be less than 1 second. * - * @param int $connectTimeout * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setConnectTimeout(int $connectTimeout): ConnectionSettings @@ -127,9 +114,6 @@ public function setConnectTimeout(int $connectTimeout): ConnectionSettings return $copy; } - /** - * @return int - */ public function getConnectTimeout(): int { return $this->connectTimeout; @@ -140,7 +124,6 @@ public function getConnectTimeout(): int * If no data is read or sent for the given amount of seconds, the socket will be closed. * The value cannot be less than 1 second. * - * @param int $socketTimeout * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setSocketTimeout(int $socketTimeout): ConnectionSettings @@ -152,9 +135,6 @@ public function setSocketTimeout(int $socketTimeout): ConnectionSettings return $copy; } - /** - * @return int - */ public function getSocketTimeout(): int { return $this->socketTimeout; @@ -164,7 +144,6 @@ public function getSocketTimeout(): int * The resend timeout is the number of seconds the client will wait before sending a duplicate * of pending messages without acknowledgement. The value cannot be less than 1 second. * - * @param int $resendTimeout * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setResendTimeout(int $resendTimeout): ConnectionSettings @@ -176,9 +155,6 @@ public function setResendTimeout(int $resendTimeout): ConnectionSettings return $copy; } - /** - * @return int - */ public function getResendTimeout(): int { return $this->resendTimeout; @@ -189,7 +165,6 @@ public function getResendTimeout(): int * until it sends a keep alive signal (ping) to the broker. The value cannot be less than 1 second * and may not be higher than 65535 seconds. A reasonable value is 10 seconds (the default). * - * @param int $keepAliveInterval * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setKeepAliveInterval(int $keepAliveInterval): ConnectionSettings @@ -201,9 +176,6 @@ public function setKeepAliveInterval(int $keepAliveInterval): ConnectionSettings return $copy; } - /** - * @return int - */ public function getKeepAliveInterval(): int { return $this->keepAliveInterval; @@ -214,7 +186,6 @@ public function getKeepAliveInterval(): int * if it notices a disconnect while sending data. * The setting cannot be used together with the clean session flag. * - * @param bool $reconnectAutomatically * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setReconnectAutomatically(bool $reconnectAutomatically): ConnectionSettings @@ -226,9 +197,6 @@ public function setReconnectAutomatically(bool $reconnectAutomatically): Connect return $copy; } - /** - * @return bool - */ public function shouldReconnectAutomatically(): bool { return $this->reconnectAutomatically; @@ -238,7 +206,6 @@ public function shouldReconnectAutomatically(): bool * Defines the maximum number of reconnect attempts until the client gives up. This setting * is only relevant if {@see setReconnectAutomatically()} is set to true. * - * @param int $maxReconnectAttempts * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setMaxReconnectAttempts(int $maxReconnectAttempts): ConnectionSettings @@ -250,9 +217,6 @@ public function setMaxReconnectAttempts(int $maxReconnectAttempts): ConnectionSe return $copy; } - /** - * @return int - */ public function getMaxReconnectAttempts(): int { return $this->maxReconnectAttempts; @@ -262,7 +226,6 @@ public function getMaxReconnectAttempts(): int * Defines the delay between reconnect attempts in milliseconds. * This setting is only relevant if {@see setReconnectAutomatically()} is set to true. * - * @param int $delayBetweenReconnectAttempts * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setDelayBetweenReconnectAttempts(int $delayBetweenReconnectAttempts): ConnectionSettings @@ -274,9 +237,6 @@ public function setDelayBetweenReconnectAttempts(int $delayBetweenReconnectAttem return $copy; } - /** - * @return int - */ public function getDelayBetweenReconnectAttempts(): int { return $this->delayBetweenReconnectAttempts; @@ -289,7 +249,6 @@ public function getDelayBetweenReconnectAttempts(): int * A last will message will only be published if both this setting as well as the last will * message are configured. * - * @param string|null $lastWillTopic * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setLastWillTopic(?string $lastWillTopic): ConnectionSettings @@ -301,9 +260,6 @@ public function setLastWillTopic(?string $lastWillTopic): ConnectionSettings return $copy; } - /** - * @return string|null - */ public function getLastWillTopic(): ?string { return $this->lastWillTopic; @@ -316,7 +272,6 @@ public function getLastWillTopic(): ?string * A last will message will only be published if both this setting as well as the last will * topic are configured. * - * @param string|null $lastWillMessage * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setLastWillMessage(?string $lastWillMessage): ConnectionSettings @@ -328,9 +283,6 @@ public function setLastWillMessage(?string $lastWillMessage): ConnectionSettings return $copy; } - /** - * @return string|null - */ public function getLastWillMessage(): ?string { return $this->lastWillMessage; @@ -338,8 +290,6 @@ public function getLastWillMessage(): ?string /** * Determines whether the client has a last will. - * - * @return bool */ public function hasLastWill(): bool { @@ -350,7 +300,6 @@ public function hasLastWill(): bool * The quality of service level the last will message of the client will be published with, * if it gets triggered. * - * @param int $lastWillQualityOfService * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setLastWillQualityOfService(int $lastWillQualityOfService): ConnectionSettings @@ -362,9 +311,6 @@ public function setLastWillQualityOfService(int $lastWillQualityOfService): Conn return $copy; } - /** - * @return int - */ public function getLastWillQualityOfService(): int { return $this->lastWillQualityOfService; @@ -375,7 +321,6 @@ public function getLastWillQualityOfService(): int * triggered. Using this setting can be handy to signal that a client is offline by publishing * a retained offline state in the last will and an online state as first message on connect. * - * @param bool $lastWillRetain * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setRetainLastWill(bool $lastWillRetain): ConnectionSettings @@ -387,9 +332,6 @@ public function setRetainLastWill(bool $lastWillRetain): ConnectionSettings return $copy; } - /** - * @return bool - */ public function shouldRetainLastWill(): bool { return $this->lastWillRetain; @@ -399,7 +341,6 @@ public function shouldRetainLastWill(): bool * This flag determines if TLS should be used for the connection. The port which is used to * connect to the broker must support TLS connections. * - * @param bool $useTls * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setUseTls(bool $useTls): ConnectionSettings @@ -411,9 +352,6 @@ public function setUseTls(bool $useTls): ConnectionSettings return $copy; } - /** - * @return bool - */ public function shouldUseTls(): bool { return $this->useTls; @@ -422,7 +360,6 @@ public function shouldUseTls(): bool /** * This flag determines if the peer certificate is verified, if TLS is used. * - * @param bool $tlsVerifyPeer * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setTlsVerifyPeer(bool $tlsVerifyPeer): ConnectionSettings @@ -434,9 +371,6 @@ public function setTlsVerifyPeer(bool $tlsVerifyPeer): ConnectionSettings return $copy; } - /** - * @return bool - */ public function shouldTlsVerifyPeer(): bool { return $this->tlsVerifyPeer; @@ -445,7 +379,6 @@ public function shouldTlsVerifyPeer(): bool /** * This flag determines if the peer name is verified, if TLS is used. * - * @param bool $tlsVerifyPeerName * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setTlsVerifyPeerName(bool $tlsVerifyPeerName): ConnectionSettings @@ -457,9 +390,6 @@ public function setTlsVerifyPeerName(bool $tlsVerifyPeerName): ConnectionSetting return $copy; } - /** - * @return bool - */ public function shouldTlsVerifyPeerName(): bool { return $this->tlsVerifyPeerName; @@ -470,7 +400,6 @@ public function shouldTlsVerifyPeerName(): bool * Setting this to TRUE implies a security risk and should be avoided for production * scenarios and public services. * - * @param bool $tlsSelfSignedAllowed * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setTlsSelfSignedAllowed(bool $tlsSelfSignedAllowed): ConnectionSettings @@ -482,9 +411,6 @@ public function setTlsSelfSignedAllowed(bool $tlsSelfSignedAllowed): ConnectionS return $copy; } - /** - * @return bool - */ public function isTlsSelfSignedAllowed(): bool { return $this->tlsSelfSignedAllowed; @@ -494,7 +420,6 @@ public function isTlsSelfSignedAllowed(): bool * The path to a Certificate Authority certificate which is used to verify the peer * certificate, if TLS is used. * - * @param string|null $tlsCertificateAuthorityFile * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setTlsCertificateAuthorityFile(?string $tlsCertificateAuthorityFile): ConnectionSettings @@ -506,9 +431,6 @@ public function setTlsCertificateAuthorityFile(?string $tlsCertificateAuthorityF return $copy; } - /** - * @return string|null - */ public function getTlsCertificateAuthorityFile(): ?string { return $this->tlsCertificateAuthorityFile; @@ -523,7 +445,6 @@ public function getTlsCertificateAuthorityFile(): ?string * openssl_x509_parse() function, which returns an array. The hash can be found in the * array under the key "hash". * - * @param string|null $tlsCertificateAuthorityPath * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setTlsCertificateAuthorityPath(?string $tlsCertificateAuthorityPath): ConnectionSettings @@ -535,9 +456,6 @@ public function setTlsCertificateAuthorityPath(?string $tlsCertificateAuthorityP return $copy; } - /** - * @return string|null - */ public function getTlsCertificateAuthorityPath(): ?string { return $this->tlsCertificateAuthorityPath; @@ -551,7 +469,6 @@ public function getTlsCertificateAuthorityPath(): ?string * file or in a separate file ({@see ConnectionSettings::setTlsClientCertificateKeyFile()}). * A passphrase can be configured using {@see ConnectionSettings::setTlsClientCertificateKeyPassphrase()}. * - * @param string|null $tlsClientCertificateFile * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setTlsClientCertificateFile(?string $tlsClientCertificateFile): ConnectionSettings @@ -563,9 +480,6 @@ public function setTlsClientCertificateFile(?string $tlsClientCertificateFile): return $copy; } - /** - * @return string|null - */ public function getTlsClientCertificateFile(): ?string { return $this->tlsClientCertificateFile; @@ -577,7 +491,6 @@ public function getTlsClientCertificateFile(): ?string * This option requires {@see ConnectionSettings::setTlsClientCertificateFile()} * to be used as well. * - * @param string|null $tlsClientCertificateKeyFile * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setTlsClientCertificateKeyFile(?string $tlsClientCertificateKeyFile): ConnectionSettings @@ -589,9 +502,6 @@ public function setTlsClientCertificateKeyFile(?string $tlsClientCertificateKeyF return $copy; } - /** - * @return string|null - */ public function getTlsClientCertificateKeyFile(): ?string { return $this->tlsClientCertificateKeyFile; @@ -606,7 +516,6 @@ public function getTlsClientCertificateKeyFile(): ?string * * Please be aware that your passphrase is not stored in secure memory when using this option. * - * @param string|null $tlsClientCertificateKeyPassphrase * @return ConnectionSettings A copy of the original object with the new setting applied. */ public function setTlsClientCertificateKeyPassphrase(?string $tlsClientCertificateKeyPassphrase): ConnectionSettings @@ -618,9 +527,6 @@ public function setTlsClientCertificateKeyPassphrase(?string $tlsClientCertifica return $copy; } - /** - * @return string|null - */ public function getTlsClientCertificateKeyPassphrase(): ?string { return $this->tlsClientCertificateKeyPassphrase; diff --git a/src/Contracts/MessageProcessor.php b/src/Contracts/MessageProcessor.php index 2464dda..ee1611d 100644 --- a/src/Contracts/MessageProcessor.php +++ b/src/Contracts/MessageProcessor.php @@ -26,22 +26,14 @@ interface MessageProcessor * If no message could be parsed, the result is false and the required bytes parameter indicates * how many bytes are missing for the message to be complete. If this parameter is set to -1, * it means we have no (or not yet) knowledge about the required bytes. - * - * @param string $buffer - * @param int $bufferLength - * @param string|null $message - * @param int $requiredBytes - * @return bool */ - public function tryFindMessageInBuffer(string $buffer, int $bufferLength, string &$message = null, int &$requiredBytes = -1): bool; + public function tryFindMessageInBuffer(string $buffer, int $bufferLength, ?string &$message = null, int &$requiredBytes = -1): bool; /** * Parses and validates the given message based on its message type and contents. * If no valid message could be found in the data, and no further action is required by the caller, * null is returned. * - * @param string $message - * @return Message|null * @throws InvalidMessageException * @throws ProtocolViolationException * @throws MqttClientException @@ -51,103 +43,67 @@ public function parseAndValidateMessage(string $message): ?Message; /** * Builds a connect message from the given connection settings, taking the protocol * specifics into account. - * - * @param ConnectionSettings $connectionSettings - * @param bool $useCleanSession - * @return string */ public function buildConnectMessage(ConnectionSettings $connectionSettings, bool $useCleanSession = false): string; /** * Builds a ping request message. - * - * @return string */ public function buildPingRequestMessage(): string; /** * Builds a ping response message. - * - * @return string */ public function buildPingResponseMessage(): string; /** * Builds a disconnect message. - * - * @return string */ public function buildDisconnectMessage(): string; /** * Builds a subscribe message from the given parameters. * - * @param int $messageId * @param Subscription[] $subscriptions - * @param bool $isDuplicate - * @return string */ public function buildSubscribeMessage(int $messageId, array $subscriptions, bool $isDuplicate = false): string; /** * Builds an unsubscribe message from the given parameters. * - * @param int $messageId * @param string[] $topics - * @param bool $isDuplicate - * @return string */ public function buildUnsubscribeMessage(int $messageId, array $topics, bool $isDuplicate = false): string; /** * Builds a publish message based on the given parameters. - * - * @param string $topic - * @param string $message - * @param int $qualityOfService - * @param bool $retain - * @param int|null $messageId - * @param bool $isDuplicate - * @return string */ public function buildPublishMessage( string $topic, string $message, int $qualityOfService, bool $retain, - int $messageId = null, - bool $isDuplicate = false + ?int $messageId = null, + bool $isDuplicate = false, ): string; /** * Builds a publish acknowledgement for the given message identifier. - * - * @param int $messageId - * @return string */ public function buildPublishAcknowledgementMessage(int $messageId): string; /** * Builds a publish received message for the given message identifier. - * - * @param int $messageId - * @return string */ public function buildPublishReceivedMessage(int $messageId): string; /** * Builds a publish release message for the given message identifier. - * - * @param int $messageId - * @return string */ public function buildPublishReleaseMessage(int $messageId): string; /** * Builds a publish complete message for the given message identifier. - * - * @param int $messageId - * @return string */ public function buildPublishCompleteMessage(int $messageId): string; @@ -156,7 +112,6 @@ public function buildPublishCompleteMessage(int $messageId): string; * connection could be established successfully according to the response. Throws an * exception if the broker responded with an error. * - * @param string $message * @throws ConnectingToBrokerFailedException */ public function handleConnectAcknowledgement(string $message): void; diff --git a/src/Contracts/MqttClient.php b/src/Contracts/MqttClient.php index f110407..4584fac 100644 --- a/src/Contracts/MqttClient.php +++ b/src/Contracts/MqttClient.php @@ -25,21 +25,14 @@ interface MqttClient * If no custom settings are passed, the client will use the default settings. * See {@see ConnectionSettings} for more details about the defaults. * - * @param ConnectionSettings|null $settings - * @param bool $useCleanSession - * @return void * @throws ConfigurationInvalidException * @throws ConnectingToBrokerFailedException */ - public function connect( - ConnectionSettings $settings = null, - bool $useCleanSession = false - ): void; + public function connect(ConnectionSettings $settings = null, bool $useCleanSession = false): void; /** * Sends a disconnect message to the broker and closes the socket. * - * @return void * @throws DataTransferException */ public function disconnect(): void; @@ -52,8 +45,6 @@ public function disconnect(): void; * an indication whether the client is in a connected state or not. * * This information may be useful in applications where multiple parts use the client. - * - * @return bool */ public function isConnected(): bool; @@ -61,11 +52,6 @@ public function isConnected(): bool; * Publishes the given message on the given topic. If the additional quality of service * and retention flags are set, the message will be published using these settings. * - * @param string $topic - * @param string $message - * @param int $qualityOfService - * @param bool $retain - * @return void * @throws DataTransferException * @throws RepositoryException */ @@ -95,20 +81,14 @@ public function publish(string $topic, string $message, int $qualityOfService = * If no callback is passed, a subscription will still be made. Received messages are delivered only to * event handlers for received messages though. * - * @param string $topicFilter - * @param callable|null $callback - * @param int $qualityOfService - * @return void * @throws DataTransferException * @throws RepositoryException */ - public function subscribe(string $topicFilter, callable $callback = null, int $qualityOfService = 0): void; + public function subscribe(string $topicFilter, ?callable $callback = null, int $qualityOfService = 0): void; /** * Unsubscribe from the given topic. * - * @param string $topicFilter - * @return void * @throws DataTransferException * @throws RepositoryException */ @@ -120,8 +100,6 @@ public function unsubscribe(string $topicFilter): void; * * Sending multiple interrupt signals has no effect, unless the client exits the loop, * which resets the signal for another loop. - * - * @return void */ public function interrupt(): void; @@ -139,16 +117,12 @@ public function interrupt(): void; * a maximum of $queueWaitLimit seconds until we give up. We do not exit after the * given amount of time if there are open topic subscriptions though. * - * @param bool $allowSleep - * @param bool $exitWhenQueuesEmpty - * @param int|null $queueWaitLimit - * @return void * @throws DataTransferException * @throws InvalidMessageException * @throws MqttClientException * @throws ProtocolViolationException */ - public function loop(bool $allowSleep = true, bool $exitWhenQueuesEmpty = false, int $queueWaitLimit = null): void; + public function loop(bool $allowSleep = true, bool $exitWhenQueuesEmpty = false, ?int $queueWaitLimit = null): void; /** * Runs an event loop iteration that handles messages from the server and calls the registered @@ -159,10 +133,6 @@ public function loop(bool $allowSleep = true, bool $exitWhenQueuesEmpty = false, * Note: To ensure the event handlers called by this method will receive the correct elapsed time, * the caller is responsible to provide the correct starting time of the loop as returned by `microtime(true)`. * - * @param float $loopStartedAt - * @param bool $allowSleep - * @param int $sleepMicroseconds - * @return void * @throws DataTransferException * @throws InvalidMessageException * @throws MqttClientException @@ -172,36 +142,26 @@ public function loopOnce(float $loopStartedAt, bool $allowSleep = false, int $sl /** * Returns the host used by the client to connect to. - * - * @return string */ public function getHost(): string; /** * Returns the port used by the client to connect to. - * - * @return int */ public function getPort(): int; /** * Returns the identifier used by the client. - * - * @return string */ public function getClientId(): string; /** * Returns the total number of received bytes, across reconnects. - * - * @return int */ public function getReceivedBytes(): int; /** * Returns the total number of sent bytes, across reconnects. - * - * @return int */ public function getSentBytes(): int; @@ -225,9 +185,6 @@ public function getSentBytes(): int; * ``` * * Multiple event handlers can be registered at the same time. - * - * @param \Closure $callback - * @return MqttClient */ public function registerLoopEventHandler(\Closure $callback): MqttClient; @@ -237,9 +194,6 @@ public function registerLoopEventHandler(\Closure $callback): MqttClient; * * This does not affect other registered event handlers. It is possible * to unregister all registered event handlers by passing null as callback. - * - * @param \Closure|null $callback - * @return MqttClient */ public function unregisterLoopEventHandler(\Closure $callback = null): MqttClient; @@ -266,9 +220,6 @@ public function unregisterLoopEventHandler(\Closure $callback = null): MqttClien * ``` * * Multiple event handlers can be registered at the same time. - * - * @param \Closure $callback - * @return MqttClient */ public function registerPublishEventHandler(\Closure $callback): MqttClient; @@ -278,9 +229,6 @@ public function registerPublishEventHandler(\Closure $callback): MqttClient; * * This does not affect other registered event handlers. It is possible * to unregister all registered event handlers by passing null as callback. - * - * @param \Closure|null $callback - * @return MqttClient */ public function unregisterPublishEventHandler(\Closure $callback = null): MqttClient; @@ -305,9 +253,6 @@ public function unregisterPublishEventHandler(\Closure $callback = null): MqttCl * ``` * * Multiple event handlers can be registered at the same time. - * - * @param \Closure $callback - * @return MqttClient */ public function registerMessageReceivedEventHandler(\Closure $callback): MqttClient; @@ -316,9 +261,6 @@ public function registerMessageReceivedEventHandler(\Closure $callback): MqttCli * * This does not affect other registered event handlers. It is possible * to unregister all registered event handlers by passing null as callback. - * - * @param \Closure|null $callback - * @return MqttClient */ public function unregisterMessageReceivedEventHandler(\Closure $callback = null): MqttClient; } diff --git a/src/Contracts/Repository.php b/src/Contracts/Repository.php index 5d7bee6..6335e28 100644 --- a/src/Contracts/Repository.php +++ b/src/Contracts/Repository.php @@ -31,8 +31,6 @@ interface Repository * Re-initializes the repository by deleting all persisted data and restoring the original state, * which was given when the repository was first created. This is used when a clean session * is requested by a client during connection. - * - * @return bool */ public function reset(): void; @@ -40,23 +38,17 @@ public function reset(): void; * Returns a new message id. The message id might have been used before, * but it is currently not being used (i.e. in a resend queue). * - * @return int * @throws RepositoryException */ public function newMessageId(): int; /** * Returns the number of pending outgoing messages. - * - * @return int */ public function countPendingOutgoingMessages(): int; /** * Gets a pending outgoing message with the given message identifier, if found. - * - * @param int $messageId - * @return PendingMessage|null */ public function getPendingOutgoingMessage(int $messageId): ?PendingMessage; @@ -67,7 +59,6 @@ public function getPendingOutgoingMessage(int $messageId): ?PendingMessage; * * The messages are returned in the same order they were added to the repository. * - * @param DateTime|null $dateTime * @return PendingMessage[] */ public function getPendingOutgoingMessagesLastSentBefore(DateTime $dateTime = null): array; @@ -75,8 +66,6 @@ public function getPendingOutgoingMessagesLastSentBefore(DateTime $dateTime = nu /** * Adds a pending outgoing message to the repository. * - * @param PendingMessage $message - * @return void * @throws PendingMessageAlreadyExistsException */ public function addPendingOutgoingMessage(PendingMessage $message): void; @@ -88,8 +77,6 @@ public function addPendingOutgoingMessage(PendingMessage $message): void; * otherwise `true` is returned if the message was marked as received, and `false` * in case it was already marked as received. * - * @param int $messageId - * @return bool * @throws PendingMessageNotFoundException */ public function markPendingOutgoingPublishedMessageAsReceived(int $messageId): bool; @@ -100,32 +87,22 @@ public function markPendingOutgoingPublishedMessageAsReceived(int $messageId): b * If a pending message with the given identifier is found and * successfully removed from the repository, `true` is returned. * Otherwise `false` will be returned. - * - * @param int $messageId - * @return bool */ public function removePendingOutgoingMessage(int $messageId): bool; /** * Returns the number of pending incoming messages. - * - * @return int */ public function countPendingIncomingMessages(): int; /** * Gets a pending incoming message with the given message identifier, if found. - * - * @param int $messageId - * @return PendingMessage|null */ public function getPendingIncomingMessage(int $messageId): ?PendingMessage; /** * Adds a pending outgoing message to the repository. * - * @param PendingMessage $message - * @return void * @throws PendingMessageAlreadyExistsException */ public function addPendingIncomingMessage(PendingMessage $message): void; @@ -136,31 +113,22 @@ public function addPendingIncomingMessage(PendingMessage $message): void; * If a pending message with the given identifier is found and * successfully removed from the repository, `true` is returned. * Otherwise `false` will be returned. - * - * @param int $messageId - * @return bool */ public function removePendingIncomingMessage(int $messageId): bool; /** * Returns the number of registered subscriptions. - * - * @return int */ public function countSubscriptions(): int; /** * Adds a subscription to the repository. - * - * @param Subscription $subscription - * @return void */ public function addSubscription(Subscription $subscription): void; /** * Gets all subscriptions matching the given topic. * - * @param string $topicName * @return Subscription[] */ public function getSubscriptionsMatchingTopic(string $topicName): array; @@ -170,9 +138,6 @@ public function getSubscriptionsMatchingTopic(string $topicName): array; * * Returns `true` if a topic subscription existed and has been removed. * Otherwise, `false` is returned. - * - * @param string $topicFilter - * @return bool */ public function removeSubscription(string $topicFilter): bool; } diff --git a/src/Exceptions/ClientNotConnectedToBrokerException.php b/src/Exceptions/ClientNotConnectedToBrokerException.php index 068d29f..0f4f6f8 100644 --- a/src/Exceptions/ClientNotConnectedToBrokerException.php +++ b/src/Exceptions/ClientNotConnectedToBrokerException.php @@ -12,12 +12,10 @@ */ class ClientNotConnectedToBrokerException extends DataTransferException { - const EXCEPTION_CONNECTION_LOST = 0300; + public const EXCEPTION_CONNECTION_LOST = 0300; /** * ClientNotConnectedToBrokerException constructor. - * - * @param string $error */ public function __construct(string $error) { diff --git a/src/Exceptions/ConnectingToBrokerFailedException.php b/src/Exceptions/ConnectingToBrokerFailedException.php index be1e256..d34c7bc 100644 --- a/src/Exceptions/ConnectingToBrokerFailedException.php +++ b/src/Exceptions/ConnectingToBrokerFailedException.php @@ -11,41 +11,33 @@ */ class ConnectingToBrokerFailedException extends MqttClientException { - const EXCEPTION_CONNECTION_FAILED = 0001; - const EXCEPTION_CONNECTION_PROTOCOL_VERSION = 0002; - const EXCEPTION_CONNECTION_IDENTIFIER_REJECTED = 0003; - const EXCEPTION_CONNECTION_BROKER_UNAVAILABLE = 0004; - const EXCEPTION_CONNECTION_INVALID_CREDENTIALS = 0005; - const EXCEPTION_CONNECTION_UNAUTHORIZED = 0006; - const EXCEPTION_CONNECTION_SOCKET_ERROR = 1000; - const EXCEPTION_CONNECTION_TLS_ERROR = 2000; - - private ?string $connectionErrorCode; - private ?string $connectionErrorMessage; + public const EXCEPTION_CONNECTION_FAILED = 0001; + public const EXCEPTION_CONNECTION_PROTOCOL_VERSION = 0002; + public const EXCEPTION_CONNECTION_IDENTIFIER_REJECTED = 0003; + public const EXCEPTION_CONNECTION_BROKER_UNAVAILABLE = 0004; + public const EXCEPTION_CONNECTION_INVALID_CREDENTIALS = 0005; + public const EXCEPTION_CONNECTION_UNAUTHORIZED = 0006; + public const EXCEPTION_CONNECTION_SOCKET_ERROR = 1000; + public const EXCEPTION_CONNECTION_TLS_ERROR = 2000; /** * ConnectingToBrokerFailedException constructor. - * - * @param int $code - * @param string $error - * @param string|null $innerCode - * @param string|null $innerMessage */ - public function __construct(int $code, string $error, string $innerCode = null, string $innerMessage = null) + public function __construct( + int $code, + string $error, + private ?string $connectionErrorCode = null, + private ?string $connectionErrorMessage = null, + ) { parent::__construct( sprintf('[%s] Establishing a connection to the MQTT broker failed: %s', $code, $error), $code ); - - $this->connectionErrorCode = $innerCode; - $this->connectionErrorMessage = $innerMessage; } /** * Retrieves the connection error code. - * - * @return string|null */ public function getConnectionErrorCode(): ?string { @@ -54,8 +46,6 @@ public function getConnectionErrorCode(): ?string /** * Retrieves the connection error message. - * - * @return string|null */ public function getConnectionErrorMessage(): ?string { diff --git a/src/Exceptions/DataTransferException.php b/src/Exceptions/DataTransferException.php index 8bca8c4..68b6a13 100644 --- a/src/Exceptions/DataTransferException.php +++ b/src/Exceptions/DataTransferException.php @@ -11,14 +11,11 @@ */ class DataTransferException extends MqttClientException { - const EXCEPTION_TX_DATA = 0101; - const EXCEPTION_RX_DATA = 0102; + public const EXCEPTION_TX_DATA = 0101; + public const EXCEPTION_RX_DATA = 0102; /** * DataTransferException constructor. - * - * @param int $code - * @param string $error */ public function __construct(int $code, string $error) { diff --git a/src/Exceptions/MqttClientException.php b/src/Exceptions/MqttClientException.php index a2cfa5c..125a57f 100644 --- a/src/Exceptions/MqttClientException.php +++ b/src/Exceptions/MqttClientException.php @@ -13,10 +13,6 @@ class MqttClientException extends \Exception { /** * MqttClientException constructor. - * - * @param string $message - * @param int $code - * @param \Throwable|null $parentException */ public function __construct(string $message = '', int $code = 0, \Throwable $parentException = null) { diff --git a/src/Exceptions/PendingMessageAlreadyExistsException.php b/src/Exceptions/PendingMessageAlreadyExistsException.php index bb20329..f79db1b 100644 --- a/src/Exceptions/PendingMessageAlreadyExistsException.php +++ b/src/Exceptions/PendingMessageAlreadyExistsException.php @@ -13,8 +13,6 @@ class PendingMessageAlreadyExistsException extends RepositoryException { /** * PendingMessageAlreadyExistsException constructor. - * - * @param int $messageId */ public function __construct(int $messageId) { diff --git a/src/Exceptions/PendingMessageNotFoundException.php b/src/Exceptions/PendingMessageNotFoundException.php index ef3fe5a..7817a73 100644 --- a/src/Exceptions/PendingMessageNotFoundException.php +++ b/src/Exceptions/PendingMessageNotFoundException.php @@ -13,8 +13,6 @@ class PendingMessageNotFoundException extends RepositoryException { /** * PendingMessageNotFoundException constructor. - * - * @param int $messageId */ public function __construct(int $messageId) { diff --git a/src/Exceptions/ProtocolNotSupportedException.php b/src/Exceptions/ProtocolNotSupportedException.php index e45273f..4d2e585 100644 --- a/src/Exceptions/ProtocolNotSupportedException.php +++ b/src/Exceptions/ProtocolNotSupportedException.php @@ -13,8 +13,6 @@ class ProtocolNotSupportedException extends MqttClientException { /** * ProtocolNotSupportedException constructor. - * - * @param string $protocol */ public function __construct(string $protocol) { diff --git a/src/Exceptions/ProtocolViolationException.php b/src/Exceptions/ProtocolViolationException.php index 139bec1..485f445 100644 --- a/src/Exceptions/ProtocolViolationException.php +++ b/src/Exceptions/ProtocolViolationException.php @@ -13,8 +13,6 @@ class ProtocolViolationException extends MqttClientException { /** * ProtocolViolationException constructor. - * - * @param string $error */ public function __construct(string $error) { diff --git a/src/Logger.php b/src/Logger.php index 9a2351f..3b4c181 100644 --- a/src/Logger.php +++ b/src/Logger.php @@ -15,30 +15,18 @@ */ class Logger implements LoggerInterface { - private string $host; - private int $port; - private string $clientId; - private ?LoggerInterface $logger; - /** * Logger constructor. * - * @param string $host - * @param int $port - * @param string $clientId * @param LoggerInterface|null $logger */ public function __construct( - string $host, - int $port, - string $clientId, - LoggerInterface $logger = null + private string $host, + private int $port, + private string $clientId, + private ?LoggerInterface $logger = null, ) { - $this->host = $host; - $this->port = $port; - $this->clientId = $clientId; - $this->logger = $logger; } /** @@ -46,7 +34,6 @@ public function __construct( * * @param string $message * @param array $context - * @return void */ public function emergency($message, array $context = []): void { @@ -61,7 +48,6 @@ public function emergency($message, array $context = []): void * * @param string $message * @param array $context - * @return void */ public function alert($message, array $context = []): void { @@ -75,7 +61,6 @@ public function alert($message, array $context = []): void * * @param string $message * @param array $context - * @return void */ public function critical($message, array $context = []): void { @@ -88,7 +73,6 @@ public function critical($message, array $context = []): void * * @param string $message * @param array $context - * @return void */ public function error($message, array $context = []): void { @@ -103,7 +87,6 @@ public function error($message, array $context = []): void * * @param string $message * @param array $context - * @return void */ public function warning($message, array $context = []): void { @@ -115,7 +98,6 @@ public function warning($message, array $context = []): void * * @param string $message * @param array $context - * @return void */ public function notice($message, array $context = []): void { @@ -129,7 +111,6 @@ public function notice($message, array $context = []): void * * @param string $message * @param array $context - * @return void */ public function info($message, array $context = []): void { @@ -141,7 +122,6 @@ public function info($message, array $context = []): void * * @param string $message * @param array $context - * @return void */ public function debug($message, array $context = []): void { @@ -154,7 +134,6 @@ public function debug($message, array $context = []): void * @param mixed $level * @param string $message * @param array $context - * @return void */ public function log($level, $message, array $context = []): void { @@ -167,9 +146,6 @@ public function log($level, $message, array $context = []): void /** * Wraps the given log message by prepending the client id and broker. - * - * @param string $message - * @return string */ protected function wrapLogMessage(string $message): string { @@ -178,9 +154,6 @@ protected function wrapLogMessage(string $message): string /** * Adds global context like host, port and client id to the log context. - * - * @param array $context - * @return array */ protected function mergeContext(array $context): array { diff --git a/src/Message.php b/src/Message.php index 40ee9ad..b64cc1a 100644 --- a/src/Message.php +++ b/src/Message.php @@ -16,9 +16,6 @@ */ class Message { - private MessageType $type; - private int $qualityOfService; - private bool $retained; private ?int $messageId = null; private ?string $topic = null; private ?string $content = null; @@ -28,54 +25,35 @@ class Message /** * Message constructor. - * - * @param MessageType $type - * @param int $qualityOfService - * @param bool $retained */ - public function __construct(MessageType $type, int $qualityOfService = 0, bool $retained = false) + public function __construct( + private MessageType $type, + private int $qualityOfService = 0, + private bool $retained = false, + ) { - $this->type = $type; - $this->qualityOfService = $qualityOfService; - $this->retained = $retained; } - /** - * @return MessageType - */ public function getType(): MessageType { return $this->type; } - /** - * @return int - */ public function getQualityOfService(): int { return $this->qualityOfService; } - /** - * @return bool - */ public function getRetained(): bool { return $this->retained; } - /** - * @return int|null - */ public function getMessageId(): ?int { return $this->messageId; } - /** - * @param int|null $messageId - * @return Message - */ public function setMessageId(?int $messageId): Message { $this->messageId = $messageId; @@ -83,18 +61,11 @@ public function setMessageId(?int $messageId): Message return $this; } - /** - * @return string|null - */ public function getTopic(): ?string { return $this->topic; } - /** - * @param string|null $topic - * @return Message - */ public function setTopic(?string $topic): Message { $this->topic = $topic; @@ -102,18 +73,11 @@ public function setTopic(?string $topic): Message return $this; } - /** - * @return string|null - */ public function getContent(): ?string { return $this->content; } - /** - * @param string|null $content - * @return Message - */ public function setContent(?string $content): Message { $this->content = $content; @@ -131,7 +95,6 @@ public function getAcknowledgedQualityOfServices(): array /** * @param int[] $acknowledgedQualityOfServices - * @return Message */ public function setAcknowledgedQualityOfServices(array $acknowledgedQualityOfServices): Message { diff --git a/src/MessageProcessors/BaseMessageProcessor.php b/src/MessageProcessors/BaseMessageProcessor.php index 68ce447..8a7acbc 100644 --- a/src/MessageProcessors/BaseMessageProcessor.php +++ b/src/MessageProcessors/BaseMessageProcessor.php @@ -16,22 +16,17 @@ */ abstract class BaseMessageProcessor { - use TranscodesData, - WorksWithBuffers; + use TranscodesData; + use WorksWithBuffers; - const QOS_AT_MOST_ONCE = 0; - const QOS_AT_LEAST_ONCE = 1; - const QOS_EXACTLY_ONCE = 2; - - protected LoggerInterface $logger; + public const QOS_AT_MOST_ONCE = 0; + public const QOS_AT_LEAST_ONCE = 1; + public const QOS_EXACTLY_ONCE = 2; /** * BaseMessageProcessor constructor. - * - * @param LoggerInterface $logger */ - public function __construct(LoggerInterface $logger) + public function __construct(protected LoggerInterface $logger) { - $this->logger = $logger; } } diff --git a/src/MessageProcessors/Mqtt311MessageProcessor.php b/src/MessageProcessors/Mqtt311MessageProcessor.php index 6a792f8..5442551 100644 --- a/src/MessageProcessors/Mqtt311MessageProcessor.php +++ b/src/MessageProcessors/Mqtt311MessageProcessor.php @@ -65,9 +65,6 @@ protected function parseAndValidateSubscribeAcknowledgementMessage(string $data) /** * Determines if the given message is a PUBLISH message and contains the unicode null character U+0000. - * - * @param Message|null $message - * @return bool */ private function isPublishMessageWithNullCharacter(?Message $message): bool { diff --git a/src/MessageProcessors/Mqtt31MessageProcessor.php b/src/MessageProcessors/Mqtt31MessageProcessor.php index e8d43de..3da71a8 100644 --- a/src/MessageProcessors/Mqtt31MessageProcessor.php +++ b/src/MessageProcessors/Mqtt31MessageProcessor.php @@ -20,19 +20,12 @@ */ class Mqtt31MessageProcessor extends BaseMessageProcessor implements MessageProcessor { - private string $clientId; - /** * Creates a new message processor instance which supports version 3.1 of the MQTT protocol. - * - * @param string $clientId - * @param LoggerInterface $logger */ - public function __construct(string $clientId, LoggerInterface $logger) + public function __construct(private string $clientId, LoggerInterface $logger) { parent::__construct($logger); - - $this->clientId = $clientId; } /** @@ -131,8 +124,6 @@ public function buildConnectMessage(ConnectionSettings $connectionSettings, bool /** * Returns the encoded protocol name and version, ready to be sent as part of the CONNECT message. - * - * @return string */ protected function getEncodedProtocolNameAndVersion(): string { @@ -153,10 +144,6 @@ protected function getEncodedProtocolNameAndVersion(): string * 7 - username flag * * @link http://public.dhe.ibm.com/software/dw/webservices/ws-mqtt/mqtt-v3r1.html#connect MQTT 3.1 Spec - * - * @param ConnectionSettings $connectionSettings - * @param bool $useCleanSession - * @return int */ protected function buildConnectionFlags(ConnectionSettings $connectionSettings, bool $useCleanSession = false): int { @@ -265,8 +252,6 @@ public function handleConnectAcknowledgement(string $message): void /** * Builds a ping request message. - * - * @return string */ public function buildPingRequestMessage(): string { @@ -276,8 +261,6 @@ public function buildPingRequestMessage(): string /** * Builds a ping response message. - * - * @return string */ public function buildPingResponseMessage(): string { @@ -287,8 +270,6 @@ public function buildPingResponseMessage(): string /** * Builds a disconnect message. - * - * @return string */ public function buildDisconnectMessage(): string { @@ -348,7 +329,7 @@ public function buildPublishMessage( int $qualityOfService, bool $retain, int $messageId = null, - bool $isDuplicate = false + bool $isDuplicate = false, ): string { // Encode the topic as length prefixed string. @@ -481,20 +462,13 @@ public function parseAndValidateMessage(string $message): ?Message * Attempt to decode the given message. If successful, the result is true and the reference * parameters are set accordingly. Otherwise, false is returned and the reference parameters * remain untouched. - * - * @param string $message - * @param int|null $command - * @param int|null $qualityOfService - * @param bool $retained - * @param string|null $data - * @return bool */ protected function tryDecodeMessage( string $message, - int &$command = null, - int &$qualityOfService = null, - bool &$retained = false, - string &$data = null + ?int &$command = null, + ?int &$qualityOfService = null, + ?bool &$retained = null, + ?string &$data = null ): bool { // If we received no input, we can return immediately without doing work. @@ -552,11 +526,6 @@ protected function tryDecodeMessage( * fixed header with command and length. The message structure is: * * [topic-length:topic:message]+ - * - * @param string $data - * @param int $qualityOfServiceLevel - * @param bool $retained - * @return Message|null */ protected function parseAndValidatePublishMessage(string $data, int $qualityOfServiceLevel, bool $retained): ?Message { @@ -594,8 +563,6 @@ protected function parseAndValidatePublishMessage(string $data, int $qualityOfSe * * [message-identifier] * - * @param string $data - * @return Message * @throws InvalidMessageException */ protected function parseAndValidatePublishAcknowledgementMessage(string $data): Message @@ -617,8 +584,6 @@ protected function parseAndValidatePublishAcknowledgementMessage(string $data): * * [message-identifier] * - * @param string $data - * @return Message * @throws InvalidMessageException */ protected function parseAndValidatePublishReceiptMessage(string $data): Message @@ -640,8 +605,6 @@ protected function parseAndValidatePublishReceiptMessage(string $data): Message * * [message-identifier] * - * @param string $data - * @return Message * @throws InvalidMessageException */ protected function parseAndValidatePublishReleaseMessage(string $data): Message @@ -663,8 +626,6 @@ protected function parseAndValidatePublishReleaseMessage(string $data): Message * * [message-identifier] * - * @param string $data - * @return Message * @throws InvalidMessageException */ protected function parseAndValidatePublishCompleteMessage(string $data): Message @@ -688,8 +649,6 @@ protected function parseAndValidatePublishCompleteMessage(string $data): Message * * The order of the received QoS levels matches the order of the sent subscriptions. * - * @param string $data - * @return Message * @throws InvalidMessageException */ protected function parseAndValidateSubscribeAcknowledgementMessage(string $data): Message @@ -720,8 +679,6 @@ protected function parseAndValidateSubscribeAcknowledgementMessage(string $data) * * [message-identifier] * - * @param string $data - * @return Message * @throws InvalidMessageException */ protected function parseAndValidateUnsubscribeAcknowledgementMessage(string $data): Message @@ -739,8 +696,6 @@ protected function parseAndValidateUnsubscribeAcknowledgementMessage(string $dat /** * Parses a received ping request. - * - * @return Message */ protected function parseAndValidatePingRequestMessage(): Message { @@ -749,8 +704,6 @@ protected function parseAndValidatePingRequestMessage(): Message /** * Parses a received ping acknowledgement. - * - * @return Message */ protected function parseAndValidatePingAcknowledgementMessage(): Message { diff --git a/src/MqttClient.php b/src/MqttClient.php index 45a2279..4064804 100644 --- a/src/MqttClient.php +++ b/src/MqttClient.php @@ -36,16 +36,13 @@ class MqttClient implements ClientContract use OffersHooks; use ValidatesConfiguration; - const MQTT_3_1 = '3.1'; - const MQTT_3_1_1 = '3.1.1'; + public const MQTT_3_1 = '3.1'; + public const MQTT_3_1_1 = '3.1.1'; - const QOS_AT_MOST_ONCE = 0; - const QOS_AT_LEAST_ONCE = 1; - const QOS_EXACTLY_ONCE = 2; - const SOCKET_READ_BUFFER_SIZE = 8192; - - private string $host; - private int $port; + public const QOS_AT_MOST_ONCE = 0; + public const QOS_AT_LEAST_ONCE = 1; + public const QOS_EXACTLY_ONCE = 2; + public const SOCKET_READ_BUFFER_SIZE = 8192; private string $clientId; private ConnectionSettings $settings; private string $buffer = ''; @@ -71,18 +68,12 @@ class MqttClient implements ClientContract * your script, all stored data (like resend queues) is lost. * - If no logger is given, log messages are dropped. Any PSR-3 logger will work. * - * @param string $host - * @param int $port - * @param string|null $clientId - * @param string $protocol - * @param Repository|null $repository - * @param LoggerInterface|null $logger * @throws ProtocolNotSupportedException */ public function __construct( - string $host, - int $port = 1883, - string $clientId = null, + private string $host, + private int $port = 1883, + ?string $clientId = null, string $protocol = self::MQTT_3_1, Repository $repository = null, LoggerInterface $logger = null @@ -91,23 +82,14 @@ public function __construct( if (!in_array($protocol, [self::MQTT_3_1, self::MQTT_3_1_1])) { throw new ProtocolNotSupportedException($protocol); } - - $this->host = $host; - $this->port = $port; $this->clientId = $clientId ?? $this->generateRandomClientId(); $this->repository = $repository ?? new MemoryRepository(); $this->logger = new Logger($this->host, $this->port, $this->clientId, $logger); - switch ($protocol) { - case self::MQTT_3_1_1: - $this->messageProcessor = new Mqtt311MessageProcessor($this->clientId, $this->logger); - break; - - case self::MQTT_3_1: - default: - $this->messageProcessor = new Mqtt31MessageProcessor($this->clientId, $this->logger); - break; - } + $this->messageProcessor = match ($protocol) { + self::MQTT_3_1_1 => new Mqtt311MessageProcessor($this->clientId, $this->logger), + default => new Mqtt31MessageProcessor($this->clientId, $this->logger), + }; $this->initializeEventHandlers(); } @@ -115,10 +97,7 @@ public function __construct( /** * {@inheritDoc} */ - public function connect( - ConnectionSettings $settings = null, - bool $useCleanSession = false - ): void + public function connect(ConnectionSettings $settings = null, bool $useCleanSession = false): void { // Always abruptly close any previous connection if we are opening a new one. // The caller should make sure this does not happen. @@ -147,9 +126,6 @@ public function connect( /** * Connect to the MQTT broker using the configured settings. * - * @param bool $useCleanSession - * @param bool $isAutoReconnect - * @return void * @throws ConnectingToBrokerFailedException */ protected function connectInternal(bool $useCleanSession = false, bool $isAutoReconnect = false): void @@ -173,7 +149,6 @@ protected function connectInternal(bool $useCleanSession = false, bool $isAutoRe * * When this method is called, all connection settings have been validated. * - * @return void * @throws ConnectingToBrokerFailedException */ protected function establishSocketConnection(): void @@ -302,11 +277,6 @@ protected function establishSocketConnection(): void /** * Internal parser for SSL-related PHP error messages. - * - * @param array|null $phpError - * @param string|null $tlsErrorCode - * @param string|null $tlsErrorMessage - * @return void */ private function parseTlsErrorMessage(?array $phpError, ?string &$tlsErrorCode = null, ?string &$tlsErrorMessage = null): void { @@ -338,8 +308,6 @@ private function parseTlsErrorMessage(?array $phpError, ?string &$tlsErrorCode = * - Connect request with variable length * - Connect acknowledgement with variable length * - * @param bool $useCleanSession - * @return void * @throws ConnectingToBrokerFailedException */ protected function performConnectionHandshake(bool $useCleanSession = false): void @@ -394,7 +362,7 @@ protected function performConnectionHandshake(bool $useCleanSession = false): vo // We need to set the global buffer to the remaining data we might already have read. $this->buffer = $buffer; - } catch (DataTransferException $e) { + } catch (DataTransferException) { $this->logger->error('While connecting to the broker, a transfer error occurred.'); throw new ConnectingToBrokerFailedException( ConnectingToBrokerFailedException::EXCEPTION_CONNECTION_FAILED, @@ -407,7 +375,6 @@ protected function performConnectionHandshake(bool $useCleanSession = false): vo * Attempts to reconnect to the broker. If a connection cannot be established within the configured number of retries, * the last caught exception is thrown. * - * @return void * @throws ConnectingToBrokerFailedException */ protected function reconnect(): void @@ -492,7 +459,6 @@ public function isConnected(): bool * Ensures the client is connected to a broker (or at least thinks it is). * This method does not account for closed sockets. * - * @return void * @throws ClientNotConnectedToBrokerException */ protected function ensureConnected(): void @@ -546,13 +512,6 @@ public function publish(string $topic, string $message, int $qualityOfService = * This is an internal method used for both, initial publishing of messages as well as * re-publishing in case of timeouts. * - * @param string $topic - * @param string $message - * @param int $qualityOfService - * @param bool $retain - * @param int|null $messageId - * @param bool $isDuplicate - * @return void * @throws DataTransferException */ protected function publishMessage( @@ -560,7 +519,7 @@ protected function publishMessage( string $message, int $qualityOfService, bool $retain, - int $messageId = null, + ?int $messageId = null, bool $isDuplicate = false ): void { @@ -626,8 +585,6 @@ public function unsubscribe(string $topicFilter): void /** * Returns the next time the broker expects to be pinged. - * - * @return float */ protected function nextPingAt(): float { @@ -700,7 +657,6 @@ public function loopOnce(float $loopStartedAt, bool $allowSleep = false, int $sl /** * Processes the incoming message buffer by parsing and handling the messages, until the buffer is empty. * - * @return void * @throws DataTransferException * @throws InvalidMessageException * @throws MqttClientException @@ -735,8 +691,6 @@ private function processMessageBuffer(): void /** * Handles the given message according to its contents. * - * @param Message $message - * @return void * @throws DataTransferException * @throws ProtocolViolationException */ @@ -760,7 +714,7 @@ protected function handleMessage(Message $message): void $message->getRetained() ); $this->repository->addPendingIncomingMessage($pendingMessage); - } catch (PendingMessageAlreadyExistsException $e) { + } catch (PendingMessageAlreadyExistsException) { // We already received and processed this message. } @@ -793,7 +747,7 @@ protected function handleMessage(Message $message): void if ($message->getType()->equals(MessageType::PUBLISH_RECEIPT())) { try { $result = $this->repository->markPendingOutgoingPublishedMessageAsReceived($message->getMessageId()); - } catch (PendingMessageNotFoundException $e) { + } catch (PendingMessageNotFoundException) { // This should never happen as we should have received all PUBREC messages before we see the first // PUBCOMP which actually remove the message. So we do this for safety only. $result = false; @@ -915,8 +869,6 @@ protected function handleMessage(Message $message): void /** * Determines if all queues are empty. - * - * @return bool */ protected function allQueuesAreEmpty(): bool { @@ -926,12 +878,6 @@ protected function allQueuesAreEmpty(): bool /** * Delivers a published message to subscribed callbacks. - * - * @param string $topic - * @param string $message - * @param int $qualityOfServiceLevel - * @param bool $retained - * @return void */ protected function deliverPublishedMessage(string $topic, string $message, int $qualityOfServiceLevel, bool $retained = false): void { @@ -966,7 +912,6 @@ protected function deliverPublishedMessage(string $topic, string $message, int $ /** * Republishes pending messages. * - * @return void * @throws DataTransferException * @throws InvalidMessageException */ @@ -1016,8 +961,6 @@ protected function resendPendingMessages(): void /** * Sends a publish acknowledgement for the given message identifier. * - * @param int $messageId - * @return void * @throws DataTransferException */ protected function sendPublishAcknowledgement(int $messageId): void @@ -1030,8 +973,6 @@ protected function sendPublishAcknowledgement(int $messageId): void /** * Sends a publish received message for the given message identifier. * - * @param int $messageId - * @return void * @throws DataTransferException */ protected function sendPublishReceived(int $messageId): void @@ -1044,8 +985,6 @@ protected function sendPublishReceived(int $messageId): void /** * Sends a publish release message for the given message identifier. * - * @param int $messageId - * @return void * @throws DataTransferException */ protected function sendPublishRelease(int $messageId): void @@ -1058,8 +997,6 @@ protected function sendPublishRelease(int $messageId): void /** * Sends a publish complete message for the given message identifier. * - * @param int $messageId - * @return void * @throws DataTransferException */ protected function sendPublishComplete(int $messageId): void @@ -1072,7 +1009,6 @@ protected function sendPublishComplete(int $messageId): void /** * Sends a ping message to the broker to keep the connection alive. * - * @return void * @throws DataTransferException */ protected function ping(): void @@ -1085,7 +1021,6 @@ protected function ping(): void /** * Sends a disconnect message to the broker. Does not close the socket. * - * @return void * @throws DataTransferException */ protected function sendDisconnect(): void @@ -1102,12 +1037,9 @@ protected function sendDisconnect(): void * than the data, only {@see $length} amount of bytes will be sent. * If configured, this method will try to reconnect in case of transmission errors. * - * @param string $data - * @param int|null $length - * @return void * @throws DataTransferException */ - protected function writeToSocketWithAutoReconnect(string $data, int $length = null): void + protected function writeToSocketWithAutoReconnect(string $data, ?int $length = null): void { try { $this->writeToSocket($data, $length); @@ -1118,7 +1050,7 @@ protected function writeToSocketWithAutoReconnect(string $data, int $length = nu try { $this->reconnect(); - } catch (ConnectingToBrokerFailedException $exception) { + } catch (ConnectingToBrokerFailedException) { $this->logger->error('Automatically reconnecting to the broker while writing data to the socket failed.'); // Throw the original exception. @@ -1134,12 +1066,9 @@ protected function writeToSocketWithAutoReconnect(string $data, int $length = nu * Writes some data to the socket. If a {@see $length} is given, and it is shorter * than the data, only {@see $length} amount of bytes will be sent. * - * @param string $data - * @param int|null $length - * @return void * @throws DataTransferException */ - protected function writeToSocket(string $data, int $length = null): void + protected function writeToSocket(string $data, ?int $length = null): void { $calculatedLength = strlen($data); $length = min($length ?? $calculatedLength, $calculatedLength); @@ -1177,9 +1106,6 @@ protected function writeToSocket(string $data, int $length = null): void * the method will wait until {@see $limit} bytes have been received. * If configured, this method will try to reconnect in case of transmission errors. * - * @param int $limit - * @param bool $withoutBlocking - * @return string * @throws DataTransferException */ protected function readFromSocketWithAutoReconnect(int $limit = self::SOCKET_READ_BUFFER_SIZE, bool $withoutBlocking = false): string @@ -1193,7 +1119,7 @@ protected function readFromSocketWithAutoReconnect(int $limit = self::SOCKET_REA try { $this->reconnect(); - } catch (ConnectingToBrokerFailedException $exception) { + } catch (ConnectingToBrokerFailedException) { $this->logger->error('Automatically reconnecting to the broker while reading data from the socket failed.'); // Throw the original exception. @@ -1210,9 +1136,6 @@ protected function readFromSocketWithAutoReconnect(int $limit = self::SOCKET_REA * a maximum of {@see $limit} bytes will be read and returned. If {@see $withoutBlocking} is set to false, * the method will wait until {@see $limit} bytes have been received. * - * @param int $limit - * @param bool $withoutBlocking - * @return string * @throws DataTransferException */ protected function readFromSocket(int $limit = self::SOCKET_READ_BUFFER_SIZE, bool $withoutBlocking = false): string @@ -1265,8 +1188,6 @@ protected function readFromSocket(int $limit = self::SOCKET_READ_BUFFER_SIZE, bo * that {@see MqttClient::readFromSocketWithAutoReconnect()} is called over and over again, as long as data is * returned. * - * @param bool $withAutoReconnectIfConfigured - * @return string * @throws DataTransferException */ protected function readAllAvailableDataFromSocket(bool $withAutoReconnectIfConfigured = false): string @@ -1290,8 +1211,6 @@ protected function readAllAvailableDataFromSocket(bool $withAutoReconnectIfConfi /** * Closes the socket connection immediately, without flushing queued data. - * - * @return void */ protected function closeSocket(): void { diff --git a/src/PendingMessage.php b/src/PendingMessage.php index 811e4c3..f7eac8b 100644 --- a/src/PendingMessage.php +++ b/src/PendingMessage.php @@ -19,26 +19,19 @@ */ abstract class PendingMessage { - private int $messageId; private int $sendingAttempts = 1; private DateTime $lastSentAt; /** * Creates a new pending message object. - * - * @param int $messageId - * @param DateTime|null $sentAt */ - protected function __construct(int $messageId, DateTime $sentAt = null) + protected function __construct(private int $messageId, DateTime $sentAt = null) { - $this->messageId = $messageId; $this->lastSentAt = $sentAt ?? new DateTime(); } /** * Returns the message identifier. - * - * @return int */ public function getMessageId(): int { @@ -47,8 +40,6 @@ public function getMessageId(): int /** * Returns the date time when the message was last sent. - * - * @return DateTime */ public function getLastSentAt(): DateTime { @@ -57,8 +48,6 @@ public function getLastSentAt(): DateTime /** * Returns the number of times the message has been sent. - * - * @return int */ public function getSendingAttempts(): int { @@ -67,9 +56,6 @@ public function getSendingAttempts(): int /** * Sets the date time when the message was last sent. - * - * @param DateTime|null $value - * @return static */ public function setLastSentAt(DateTime $value = null): self { @@ -80,8 +66,6 @@ public function setLastSentAt(DateTime $value = null): self /** * Increments the sending attempts by one. - * - * @return static */ public function incrementSendingAttempts(): self { diff --git a/src/PublishedMessage.php b/src/PublishedMessage.php index 35e3d72..c2edcdf 100644 --- a/src/PublishedMessage.php +++ b/src/PublishedMessage.php @@ -12,40 +12,24 @@ */ class PublishedMessage extends PendingMessage { - private string $topicName; - private string $message; - private int $qualityOfService; - private bool $retain; private bool $received = false; /** * Creates a new published message object. - * - * @param int $messageId - * @param string $topicName - * @param string $message - * @param int $qualityOfService - * @param bool $retain */ public function __construct( int $messageId, - string $topicName, - string $message, - int $qualityOfService, - bool $retain + private string $topicName, + private string $message, + private int $qualityOfService, + private bool $retain, ) { parent::__construct($messageId); - $this->topicName = $topicName; - $this->message = $message; - $this->qualityOfService = $qualityOfService; - $this->retain = $retain; } /** * Returns the topic name of the published message. - * - * @return string */ public function getTopicName(): string { @@ -54,8 +38,6 @@ public function getTopicName(): string /** * Returns the content of the published message. - * - * @return string */ public function getMessage(): string { @@ -64,8 +46,6 @@ public function getMessage(): string /** * Returns the requested quality of service level. - * - * @return int */ public function getQualityOfServiceLevel(): int { @@ -74,8 +54,6 @@ public function getQualityOfServiceLevel(): int /** * Determines whether this message wants to be retained. - * - * @return bool */ public function wantsToBeRetained(): bool { @@ -84,8 +62,6 @@ public function wantsToBeRetained(): bool /** * Determines whether the message has been confirmed as received. - * - * @return bool */ public function hasBeenReceived(): bool { @@ -95,10 +71,7 @@ public function hasBeenReceived(): bool /** * Marks the published message as received (QoS level 2). * - * Returns `true` if the message was not previously received. Otherwise - * `false` will be returned. - * - * @return bool + * Returns `true` if the message was not previously received. Otherwise `false` will be returned. */ public function markAsReceived(): bool { diff --git a/src/SubscribeRequest.php b/src/SubscribeRequest.php index c794209..c70e1a4 100644 --- a/src/SubscribeRequest.php +++ b/src/SubscribeRequest.php @@ -17,7 +17,6 @@ class SubscribeRequest extends PendingMessage /** * Creates a new subscribe request message. * - * @param int $messageId * @param Subscription[] $subscriptions */ public function __construct(int $messageId, array $subscriptions) diff --git a/src/Subscription.php b/src/Subscription.php index 1ac7b55..7d2265f 100644 --- a/src/Subscription.php +++ b/src/Subscription.php @@ -11,31 +11,22 @@ */ class Subscription { - private string $topicFilter; private string $regexifiedTopicFilter; - private int $qualityOfService; - private ?\Closure $callback; /** * Creates a new subscription object. - * - * @param string $topicFilter - * @param int $qualityOfService - * @param \Closure|null $callback */ - public function __construct(string $topicFilter, int $qualityOfService = 0, ?\Closure $callback = null) + public function __construct( + private string $topicFilter, + private int $qualityOfService = 0, + private ?\Closure $callback = null, + ) { - $this->topicFilter = $topicFilter; - $this->qualityOfService = $qualityOfService; - $this->callback = $callback; - $this->regexifyTopicFilter(); } /** * Converts the topic filter into a regular expression. - * - * @return void */ private function regexifyTopicFilter(): void { @@ -45,7 +36,7 @@ private function regexifyTopicFilter(): void // from the topic filter. To do so, we look for the $share keyword and then try to find the second topic separator to // calculate the substring containing the actual topic filter. // Note: shared subscriptions always have the form: $share// - if (strpos($topicFilter, '$share/') === 0 && ($separatorIndex = strpos($topicFilter, '/', 7)) !== false) { + if (str_starts_with($topicFilter, '$share/') && ($separatorIndex = strpos($topicFilter, '/', 7)) !== false) { $topicFilter = substr($topicFilter, $separatorIndex + 1); } @@ -54,8 +45,6 @@ private function regexifyTopicFilter(): void /** * Returns the topic of the subscription. - * - * @return string */ public function getTopicFilter(): string { @@ -64,9 +53,6 @@ public function getTopicFilter(): string /** * Matches the given topic name matches to the subscription's topic filter. - * - * @param string $topicName - * @return bool */ public function matchesTopic(string $topicName): bool { @@ -84,9 +70,6 @@ public function matchesTopic(string $topicName): bool * Result for invalid topic 'some/topic': [] * * Note: This method should only be called if {@see matchesTopic} returned true. An empty array will be returned otherwise. - * - * @param string $topicName - * @return array */ public function getMatchedWildcards(string $topicName): array { @@ -99,8 +82,6 @@ public function getMatchedWildcards(string $topicName): array /** * Returns the callback for this subscription. - * - * @return \Closure|null */ public function getCallback(): ?\Closure { @@ -109,8 +90,6 @@ public function getCallback(): ?\Closure /** * Returns the requested quality of service level. - * - * @return int */ public function getQualityOfServiceLevel(): int { @@ -119,9 +98,6 @@ public function getQualityOfServiceLevel(): int /** * Sets the actual quality of service level. - * - * @param int $qualityOfService - * @return void */ public function setQualityOfServiceLevel(int $qualityOfService): void { diff --git a/src/UnsubscribeRequest.php b/src/UnsubscribeRequest.php index b97bfe1..030e728 100644 --- a/src/UnsubscribeRequest.php +++ b/src/UnsubscribeRequest.php @@ -17,7 +17,6 @@ class UnsubscribeRequest extends PendingMessage /** * Creates a new unsubscribe request object. * - * @param int $messageId * @param string[] $topicFilters */ public function __construct(int $messageId, array $topicFilters) diff --git a/tests/Feature/ConnectWithInvalidConfigurationTest.php b/tests/Feature/ConnectWithInvalidConfigurationTest.php index 5d8d0cc..eed4ba3 100644 --- a/tests/Feature/ConnectWithInvalidConfigurationTest.php +++ b/tests/Feature/ConnectWithInvalidConfigurationTest.php @@ -186,8 +186,6 @@ public function test_tls_client_certificate_key_file_must_be_set_if_client_certi /** * Performs the actual connection test using the given connection settings. Expects the settings to be invalid. * - * @param ConnectionSettings $connectionSettings - * @return void * @throws ConfigurationInvalidException * @throws ConnectingToBrokerFailedException * @throws ProtocolNotSupportedException diff --git a/tests/Unit/MessageProcessors/Mqtt311MessageProcessorTest.php b/tests/Unit/MessageProcessors/Mqtt311MessageProcessorTest.php index 0cdc445..1cd89d2 100644 --- a/tests/Unit/MessageProcessors/Mqtt311MessageProcessorTest.php +++ b/tests/Unit/MessageProcessors/Mqtt311MessageProcessorTest.php @@ -12,7 +12,7 @@ class Mqtt311MessageProcessorTest extends TestCase { - const CLIENT_ID = 'test-client'; + public const CLIENT_ID = 'test-client'; /** @var Mqtt311MessageProcessor */ protected $messageProcessor; @@ -49,8 +49,6 @@ public function tryFindMessageInBuffer_testDataProvider(): array /** * @dataProvider tryFindMessageInBuffer_testDataProvider * - * @param string $buffer - * @param bool $expectedResult * @param string|null $expectedMessage * @param int|null $expectedRequiredBytes */ @@ -129,10 +127,6 @@ public function buildConnectMessage_testDataProvider(): array /** * @dataProvider buildConnectMessage_testDataProvider - * - * @param ConnectionSettings $connectionSettings - * @param bool $useCleanSession - * @param string $expectedResult */ public function test_buildConnectMessage_builds_correct_message( ConnectionSettings $connectionSettings, @@ -172,9 +166,7 @@ public function buildSubscribeMessage_testDataProvider(): array /** * @dataProvider buildSubscribeMessage_testDataProvider * - * @param int $messageId * @param Subscription[] $subscriptions - * @param string $expectedResult */ public function test_buildSubscribeMessage_builds_correct_message( int $messageId, @@ -214,10 +206,7 @@ public function buildUnsubscribeMessage_testDataProvider(): array /** * @dataProvider buildUnsubscribeMessage_testDataProvider * - * @param int $messageId * @param string[] $topics - * @param bool $isDuplicate - * @param string $expectedResult */ public function test_buildUnsubscribeMessage_builds_correct_message( int $messageId, @@ -254,14 +243,6 @@ public function buildPublishMessage_testDataProvider(): array /** * @dataProvider buildPublishMessage_testDataProvider - * - * @param string $topic - * @param string $message - * @param int $qualityOfService - * @param bool $retain - * @param int $messageId - * @param bool $isDuplicate - * @param string $expectedResult */ public function test_buildPublishMessage_builds_correct_message( string $topic, @@ -306,9 +287,6 @@ public function buildPublishAcknowledgementMessage_testDataProvider(): array /** * @dataProvider buildPublishAcknowledgementMessage_testDataProvider - * - * @param int $messageId - * @param string $expectedResult */ public function test_buildPublishAcknowledgementMessage_builds_correct_message(int $messageId, string $expectedResult): void { @@ -338,9 +316,6 @@ public function buildPublishReceivedMessage_testDataProvider(): array /** * @dataProvider buildPublishReceivedMessage_testDataProvider - * - * @param int $messageId - * @param string $expectedResult */ public function test_buildPublishReceivedMessage_builds_correct_message(int $messageId, string $expectedResult): void { @@ -370,9 +345,6 @@ public function buildPublishCompleteMessage_testDataProvider(): array /** * @dataProvider buildPublishCompleteMessage_testDataProvider - * - * @param int $messageId - * @param string $expectedResult */ public function test_buildPublishCompleteMessage_builds_correct_message(int $messageId, string $expectedResult): void { diff --git a/tests/Unit/MessageProcessors/Mqtt31MessageProcessorTest.php b/tests/Unit/MessageProcessors/Mqtt31MessageProcessorTest.php index c6b27fd..ab6dd2e 100644 --- a/tests/Unit/MessageProcessors/Mqtt31MessageProcessorTest.php +++ b/tests/Unit/MessageProcessors/Mqtt31MessageProcessorTest.php @@ -12,7 +12,7 @@ class Mqtt31MessageProcessorTest extends TestCase { - const CLIENT_ID = 'test-client'; + public const CLIENT_ID = 'test-client'; /** @var Mqtt31MessageProcessor */ protected $messageProcessor; @@ -49,8 +49,6 @@ public function tryFindMessageInBuffer_testDataProvider(): array /** * @dataProvider tryFindMessageInBuffer_testDataProvider * - * @param string $buffer - * @param bool $expectedResult * @param string|null $expectedMessage * @param int|null $expectedRequiredBytes */ @@ -129,10 +127,6 @@ public function buildConnectMessage_testDataProvider(): array /** * @dataProvider buildConnectMessage_testDataProvider - * - * @param ConnectionSettings $connectionSettings - * @param bool $useCleanSession - * @param string $expectedResult */ public function test_buildConnectMessage_builds_correct_message( ConnectionSettings $connectionSettings, @@ -172,9 +166,7 @@ public function buildSubscribeMessage_testDataProvider(): array /** * @dataProvider buildSubscribeMessage_testDataProvider * - * @param int $messageId * @param Subscription[] $subscriptions - * @param string $expectedResult */ public function test_buildSubscribeMessage_builds_correct_message( int $messageId, @@ -214,10 +206,7 @@ public function buildUnsubscribeMessage_testDataProvider(): array /** * @dataProvider buildUnsubscribeMessage_testDataProvider * - * @param int $messageId * @param string[] $topics - * @param bool $isDuplicate - * @param string $expectedResult */ public function test_buildUnsubscribeMessage_builds_correct_message( int $messageId, @@ -254,14 +243,6 @@ public function buildPublishMessage_testDataProvider(): array /** * @dataProvider buildPublishMessage_testDataProvider - * - * @param string $topic - * @param string $message - * @param int $qualityOfService - * @param bool $retain - * @param int $messageId - * @param bool $isDuplicate - * @param string $expectedResult */ public function test_buildPublishMessage_builds_correct_message( string $topic, @@ -306,9 +287,6 @@ public function buildPublishAcknowledgementMessage_testDataProvider(): array /** * @dataProvider buildPublishAcknowledgementMessage_testDataProvider - * - * @param int $messageId - * @param string $expectedResult */ public function test_buildPublishAcknowledgementMessage_builds_correct_message(int $messageId, string $expectedResult): void { @@ -338,9 +316,6 @@ public function buildPublishReceivedMessage_testDataProvider(): array /** * @dataProvider buildPublishReceivedMessage_testDataProvider - * - * @param int $messageId - * @param string $expectedResult */ public function test_buildPublishReceivedMessage_builds_correct_message(int $messageId, string $expectedResult): void { @@ -370,9 +345,6 @@ public function buildPublishCompleteMessage_testDataProvider(): array /** * @dataProvider buildPublishCompleteMessage_testDataProvider - * - * @param int $messageId - * @param string $expectedResult */ public function test_buildPublishCompleteMessage_builds_correct_message(int $messageId, string $expectedResult): void {