Skip to content

Commit 8042ad9

Browse files
authored
Fix: PHP 8.4 - Implicitly nullable parameter declarations deprecated (#192)
1 parent b273768 commit 8042ad9

File tree

8 files changed

+20
-20
lines changed

8 files changed

+20
-20
lines changed

src/Concerns/OffersHooks.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function registerLoopEventHandler(\Closure $callback): MqttClient
7373
* This does not affect other registered event handlers. It is possible
7474
* to unregister all registered event handlers by passing null as callback.
7575
*/
76-
public function unregisterLoopEventHandler(\Closure $callback = null): MqttClient
76+
public function unregisterLoopEventHandler(?\Closure $callback = null): MqttClient
7777
{
7878
if ($callback === null) {
7979
$this->loopEventHandlers->removeAll($this->loopEventHandlers);
@@ -139,7 +139,7 @@ public function registerPublishEventHandler(\Closure $callback): MqttClient
139139
* This does not affect other registered event handlers. It is possible
140140
* to unregister all registered event handlers by passing null as callback.
141141
*/
142-
public function unregisterPublishEventHandler(\Closure $callback = null): MqttClient
142+
public function unregisterPublishEventHandler(?\Closure $callback = null): MqttClient
143143
{
144144
if ($callback === null) {
145145
$this->publishEventHandlers->removeAll($this->publishEventHandlers);
@@ -205,7 +205,7 @@ public function registerMessageReceivedEventHandler(\Closure $callback): MqttCli
205205
* This does not affect other registered event handlers. It is possible
206206
* to unregister all registered event handlers by passing null as callback.
207207
*/
208-
public function unregisterMessageReceivedEventHandler(\Closure $callback = null): MqttClient
208+
public function unregisterMessageReceivedEventHandler(?\Closure $callback = null): MqttClient
209209
{
210210
if ($callback === null) {
211211
$this->messageReceivedEventHandlers->removeAll($this->messageReceivedEventHandlers);
@@ -272,7 +272,7 @@ public function registerConnectedEventHandler(\Closure $callback): MqttClient
272272
* This does not affect other registered event handlers. It is possible
273273
* to unregister all registered event handlers by passing null as callback.
274274
*/
275-
public function unregisterConnectedEventHandler(\Closure $callback = null): MqttClient
275+
public function unregisterConnectedEventHandler(?\Closure $callback = null): MqttClient
276276
{
277277
if ($callback === null) {
278278
$this->connectedEventHandlers->removeAll($this->connectedEventHandlers);

src/Contracts/MqttClient.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface MqttClient
2828
* @throws ConfigurationInvalidException
2929
* @throws ConnectingToBrokerFailedException
3030
*/
31-
public function connect(ConnectionSettings $settings = null, bool $useCleanSession = false): void;
31+
public function connect(?ConnectionSettings $settings = null, bool $useCleanSession = false): void;
3232

3333
/**
3434
* Sends a disconnect message to the broker and closes the socket.
@@ -195,7 +195,7 @@ public function registerLoopEventHandler(\Closure $callback): MqttClient;
195195
* This does not affect other registered event handlers. It is possible
196196
* to unregister all registered event handlers by passing null as callback.
197197
*/
198-
public function unregisterLoopEventHandler(\Closure $callback = null): MqttClient;
198+
public function unregisterLoopEventHandler(?\Closure $callback = null): MqttClient;
199199

200200
/**
201201
* Registers a loop event handler which is called when a message is published.
@@ -230,7 +230,7 @@ public function registerPublishEventHandler(\Closure $callback): MqttClient;
230230
* This does not affect other registered event handlers. It is possible
231231
* to unregister all registered event handlers by passing null as callback.
232232
*/
233-
public function unregisterPublishEventHandler(\Closure $callback = null): MqttClient;
233+
public function unregisterPublishEventHandler(?\Closure $callback = null): MqttClient;
234234

235235
/**
236236
* Registers an event handler which is called when a message is received from the broker.
@@ -262,5 +262,5 @@ public function registerMessageReceivedEventHandler(\Closure $callback): MqttCli
262262
* This does not affect other registered event handlers. It is possible
263263
* to unregister all registered event handlers by passing null as callback.
264264
*/
265-
public function unregisterMessageReceivedEventHandler(\Closure $callback = null): MqttClient;
265+
public function unregisterMessageReceivedEventHandler(?\Closure $callback = null): MqttClient;
266266
}

src/Contracts/Repository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function getPendingOutgoingMessage(int $messageId): ?PendingMessage;
6161
*
6262
* @return PendingMessage[]
6363
*/
64-
public function getPendingOutgoingMessagesLastSentBefore(DateTime $dateTime = null): array;
64+
public function getPendingOutgoingMessagesLastSentBefore(?DateTime $dateTime = null): array;
6565

6666
/**
6767
* Adds a pending outgoing message to the repository.

src/Exceptions/MqttClientException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class MqttClientException extends \Exception
1414
/**
1515
* MqttClientException constructor.
1616
*/
17-
public function __construct(string $message = '', int $code = 0, \Throwable $parentException = null)
17+
public function __construct(string $message = '', int $code = 0, ?\Throwable $parentException = null)
1818
{
1919
if (empty($message)) {
2020
parent::__construct(

src/MessageProcessors/Mqtt31MessageProcessor.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function __construct(private string $clientId, LoggerInterface $logger)
3131
/**
3232
* {@inheritDoc}
3333
*/
34-
public function tryFindMessageInBuffer(string $buffer, int $bufferLength, string &$message = null, int &$requiredBytes = -1): bool
34+
public function tryFindMessageInBuffer(string $buffer, int $bufferLength, ?string &$message = null, int &$requiredBytes = -1): bool
3535
{
3636
// If we received no input, we can return immediately without doing work.
3737
if ($bufferLength === 0) {
@@ -328,7 +328,7 @@ public function buildPublishMessage(
328328
string $message,
329329
int $qualityOfService,
330330
bool $retain,
331-
int $messageId = null,
331+
?int $messageId = null,
332332
bool $isDuplicate = false,
333333
): string
334334
{

src/MqttClient.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ public function __construct(
7575
private int $port = 1883,
7676
?string $clientId = null,
7777
string $protocol = self::MQTT_3_1,
78-
Repository $repository = null,
79-
LoggerInterface $logger = null
78+
?Repository $repository = null,
79+
?LoggerInterface $logger = null
8080
)
8181
{
8282
if (!in_array($protocol, [self::MQTT_3_1, self::MQTT_3_1_1])) {
@@ -97,7 +97,7 @@ public function __construct(
9797
/**
9898
* {@inheritDoc}
9999
*/
100-
public function connect(ConnectionSettings $settings = null, bool $useCleanSession = false): void
100+
public function connect(?ConnectionSettings $settings = null, bool $useCleanSession = false): void
101101
{
102102
// Always abruptly close any previous connection if we are opening a new one.
103103
// The caller should make sure this does not happen.
@@ -546,7 +546,7 @@ protected function publishMessage(
546546
/**
547547
* {@inheritDoc}
548548
*/
549-
public function subscribe(string $topicFilter, callable $callback = null, int $qualityOfService = self::QOS_AT_MOST_ONCE): void
549+
public function subscribe(string $topicFilter, ?callable $callback = null, int $qualityOfService = self::QOS_AT_MOST_ONCE): void
550550
{
551551
$this->ensureConnected();
552552

@@ -598,7 +598,7 @@ protected function nextPingAt(): float
598598
/**
599599
* {@inheritDoc}
600600
*/
601-
public function loop(bool $allowSleep = true, bool $exitWhenQueuesEmpty = false, int $queueWaitLimit = null): void
601+
public function loop(bool $allowSleep = true, bool $exitWhenQueuesEmpty = false, ?int $queueWaitLimit = null): void
602602
{
603603
$this->logger->debug('Starting client loop to process incoming messages and the resend queue.');
604604

src/PendingMessage.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ abstract class PendingMessage
2525
/**
2626
* Creates a new pending message object.
2727
*/
28-
protected function __construct(private int $messageId, DateTime $sentAt = null)
28+
protected function __construct(private int $messageId, ?DateTime $sentAt = null)
2929
{
3030
$this->lastSentAt = $sentAt ?? new DateTime();
3131
}
@@ -57,7 +57,7 @@ public function getSendingAttempts(): int
5757
/**
5858
* Sets the date time when the message was last sent.
5959
*/
60-
public function setLastSentAt(DateTime $value = null): self
60+
public function setLastSentAt(?DateTime $value = null): self
6161
{
6262
$this->lastSentAt = $value ?? new DateTime();
6363

src/Repositories/MemoryRepository.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function getPendingOutgoingMessage(int $messageId): ?PendingMessage
8686
/**
8787
* {@inheritDoc}
8888
*/
89-
public function getPendingOutgoingMessagesLastSentBefore(\DateTime $dateTime = null): array
89+
public function getPendingOutgoingMessagesLastSentBefore(?\DateTime $dateTime = null): array
9090
{
9191
$result = [];
9292

0 commit comments

Comments
 (0)