Skip to content

Commit 57b554d

Browse files
authored
ConnectionSettings: Immutability documentation (#145)
Added comments to help readers of the ConnectionSettings understand the reason for it's immutable behaviour.
1 parent dc40a6d commit 57b554d

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

src/ConnectionSettings.php

+26-23
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
/**
88
* The settings used during connection to a broker.
9+
*
10+
* This class is immutable and all setters return a clone of the original class because
11+
* connection settings must not change once passed to MqttClient.
912
*
1013
* @package PhpMqtt\Client
1114
*/
@@ -39,7 +42,7 @@ class ConnectionSettings
3942
* The username used for authentication when connecting to the broker.
4043
*
4144
* @param string|null $username
42-
* @return ConnectionSettings
45+
* @return ConnectionSettings A copy of the original object with the new setting applied.
4346
*/
4447
public function setUsername(?string $username): ConnectionSettings
4548
{
@@ -62,7 +65,7 @@ public function getUsername(): ?string
6265
* The password used for authentication when connecting to the broker.
6366
*
6467
* @param string|null $password
65-
* @return ConnectionSettings
68+
* @return ConnectionSettings A copy of the original object with the new setting applied.
6669
*/
6770
public function setPassword(?string $password): ConnectionSettings
6871
{
@@ -89,7 +92,7 @@ public function getPassword(): ?string
8992
* Note: This setting has no effect on subscriptions, only on the publishing of messages.
9093
*
9194
* @param bool $useBlockingSocket
92-
* @return ConnectionSettings
95+
* @return ConnectionSettings A copy of the original object with the new setting applied.
9396
*/
9497
public function useBlockingSocket(bool $useBlockingSocket): ConnectionSettings
9598
{
@@ -113,7 +116,7 @@ public function shouldUseBlockingSocket(): bool
113116
* a socket connection with the broker. The value cannot be less than 1 second.
114117
*
115118
* @param int $connectTimeout
116-
* @return ConnectionSettings
119+
* @return ConnectionSettings A copy of the original object with the new setting applied.
117120
*/
118121
public function setConnectTimeout(int $connectTimeout): ConnectionSettings
119122
{
@@ -138,7 +141,7 @@ public function getConnectTimeout(): int
138141
* The value cannot be less than 1 second.
139142
*
140143
* @param int $socketTimeout
141-
* @return ConnectionSettings
144+
* @return ConnectionSettings A copy of the original object with the new setting applied.
142145
*/
143146
public function setSocketTimeout(int $socketTimeout): ConnectionSettings
144147
{
@@ -162,7 +165,7 @@ public function getSocketTimeout(): int
162165
* of pending messages without acknowledgement. The value cannot be less than 1 second.
163166
*
164167
* @param int $resendTimeout
165-
* @return ConnectionSettings
168+
* @return ConnectionSettings A copy of the original object with the new setting applied.
166169
*/
167170
public function setResendTimeout(int $resendTimeout): ConnectionSettings
168171
{
@@ -187,7 +190,7 @@ public function getResendTimeout(): int
187190
* and may not be higher than 65535 seconds. A reasonable value is 10 seconds (the default).
188191
*
189192
* @param int $keepAliveInterval
190-
* @return ConnectionSettings
193+
* @return ConnectionSettings A copy of the original object with the new setting applied.
191194
*/
192195
public function setKeepAliveInterval(int $keepAliveInterval): ConnectionSettings
193196
{
@@ -212,7 +215,7 @@ public function getKeepAliveInterval(): int
212215
* The setting cannot be used together with the clean session flag.
213216
*
214217
* @param bool $reconnectAutomatically
215-
* @return ConnectionSettings
218+
* @return ConnectionSettings A copy of the original object with the new setting applied.
216219
*/
217220
public function setReconnectAutomatically(bool $reconnectAutomatically): ConnectionSettings
218221
{
@@ -236,7 +239,7 @@ public function shouldReconnectAutomatically(): bool
236239
* is only relevant if {@see setReconnectAutomatically()} is set to true.
237240
*
238241
* @param int $maxReconnectAttempts
239-
* @return ConnectionSettings
242+
* @return ConnectionSettings A copy of the original object with the new setting applied.
240243
*/
241244
public function setMaxReconnectAttempts(int $maxReconnectAttempts): ConnectionSettings
242245
{
@@ -260,7 +263,7 @@ public function getMaxReconnectAttempts(): int
260263
* This setting is only relevant if {@see setReconnectAutomatically()} is set to true.
261264
*
262265
* @param int $delayBetweenReconnectAttempts
263-
* @return ConnectionSettings
266+
* @return ConnectionSettings A copy of the original object with the new setting applied.
264267
*/
265268
public function setDelayBetweenReconnectAttempts(int $delayBetweenReconnectAttempts): ConnectionSettings
266269
{
@@ -287,7 +290,7 @@ public function getDelayBetweenReconnectAttempts(): int
287290
* message are configured.
288291
*
289292
* @param string|null $lastWillTopic
290-
* @return ConnectionSettings
293+
* @return ConnectionSettings A copy of the original object with the new setting applied.
291294
*/
292295
public function setLastWillTopic(?string $lastWillTopic): ConnectionSettings
293296
{
@@ -314,7 +317,7 @@ public function getLastWillTopic(): ?string
314317
* topic are configured.
315318
*
316319
* @param string|null $lastWillMessage
317-
* @return ConnectionSettings
320+
* @return ConnectionSettings A copy of the original object with the new setting applied.
318321
*/
319322
public function setLastWillMessage(?string $lastWillMessage): ConnectionSettings
320323
{
@@ -348,7 +351,7 @@ public function hasLastWill(): bool
348351
* if it gets triggered.
349352
*
350353
* @param int $lastWillQualityOfService
351-
* @return ConnectionSettings
354+
* @return ConnectionSettings A copy of the original object with the new setting applied.
352355
*/
353356
public function setLastWillQualityOfService(int $lastWillQualityOfService): ConnectionSettings
354357
{
@@ -373,7 +376,7 @@ public function getLastWillQualityOfService(): int
373376
* a retained offline state in the last will and an online state as first message on connect.
374377
*
375378
* @param bool $lastWillRetain
376-
* @return ConnectionSettings
379+
* @return ConnectionSettings A copy of the original object with the new setting applied.
377380
*/
378381
public function setRetainLastWill(bool $lastWillRetain): ConnectionSettings
379382
{
@@ -397,7 +400,7 @@ public function shouldRetainLastWill(): bool
397400
* connect to the broker must support TLS connections.
398401
*
399402
* @param bool $useTls
400-
* @return ConnectionSettings
403+
* @return ConnectionSettings A copy of the original object with the new setting applied.
401404
*/
402405
public function setUseTls(bool $useTls): ConnectionSettings
403406
{
@@ -420,7 +423,7 @@ public function shouldUseTls(): bool
420423
* This flag determines if the peer certificate is verified, if TLS is used.
421424
*
422425
* @param bool $tlsVerifyPeer
423-
* @return ConnectionSettings
426+
* @return ConnectionSettings A copy of the original object with the new setting applied.
424427
*/
425428
public function setTlsVerifyPeer(bool $tlsVerifyPeer): ConnectionSettings
426429
{
@@ -443,7 +446,7 @@ public function shouldTlsVerifyPeer(): bool
443446
* This flag determines if the peer name is verified, if TLS is used.
444447
*
445448
* @param bool $tlsVerifyPeerName
446-
* @return ConnectionSettings
449+
* @return ConnectionSettings A copy of the original object with the new setting applied.
447450
*/
448451
public function setTlsVerifyPeerName(bool $tlsVerifyPeerName): ConnectionSettings
449452
{
@@ -468,7 +471,7 @@ public function shouldTlsVerifyPeerName(): bool
468471
* scenarios and public services.
469472
*
470473
* @param bool $tlsSelfSignedAllowed
471-
* @return ConnectionSettings
474+
* @return ConnectionSettings A copy of the original object with the new setting applied.
472475
*/
473476
public function setTlsSelfSignedAllowed(bool $tlsSelfSignedAllowed): ConnectionSettings
474477
{
@@ -492,7 +495,7 @@ public function isTlsSelfSignedAllowed(): bool
492495
* certificate, if TLS is used.
493496
*
494497
* @param string|null $tlsCertificateAuthorityFile
495-
* @return ConnectionSettings
498+
* @return ConnectionSettings A copy of the original object with the new setting applied.
496499
*/
497500
public function setTlsCertificateAuthorityFile(?string $tlsCertificateAuthorityFile): ConnectionSettings
498501
{
@@ -521,7 +524,7 @@ public function getTlsCertificateAuthorityFile(): ?string
521524
* array under the key "hash".
522525
*
523526
* @param string|null $tlsCertificateAuthorityPath
524-
* @return ConnectionSettings
527+
* @return ConnectionSettings A copy of the original object with the new setting applied.
525528
*/
526529
public function setTlsCertificateAuthorityPath(?string $tlsCertificateAuthorityPath): ConnectionSettings
527530
{
@@ -549,7 +552,7 @@ public function getTlsCertificateAuthorityPath(): ?string
549552
* A passphrase can be configured using {@see ConnectionSettings::setTlsClientCertificateKeyPassphrase()}.
550553
*
551554
* @param string|null $tlsClientCertificateFile
552-
* @return ConnectionSettings
555+
* @return ConnectionSettings A copy of the original object with the new setting applied.
553556
*/
554557
public function setTlsClientCertificateFile(?string $tlsClientCertificateFile): ConnectionSettings
555558
{
@@ -575,7 +578,7 @@ public function getTlsClientCertificateFile(): ?string
575578
* to be used as well.
576579
*
577580
* @param string|null $tlsClientCertificateKeyFile
578-
* @return ConnectionSettings
581+
* @return ConnectionSettings A copy of the original object with the new setting applied.
579582
*/
580583
public function setTlsClientCertificateKeyFile(?string $tlsClientCertificateKeyFile): ConnectionSettings
581584
{
@@ -604,7 +607,7 @@ public function getTlsClientCertificateKeyFile(): ?string
604607
* Please be aware that your passphrase is not stored in secure memory when using this option.
605608
*
606609
* @param string|null $tlsClientCertificateKeyPassphrase
607-
* @return ConnectionSettings
610+
* @return ConnectionSettings A copy of the original object with the new setting applied.
608611
*/
609612
public function setTlsClientCertificateKeyPassphrase(?string $tlsClientCertificateKeyPassphrase): ConnectionSettings
610613
{

0 commit comments

Comments
 (0)