From 6c6575898f13ae83e482a102b172d451ce68655e Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 1 Nov 2022 22:49:27 +0100 Subject: [PATCH] Use ??= more --- Channel/ChatChannel.php | 4 +--- Channel/PushChannel.php | 4 +--- Channel/SmsChannel.php | 4 +--- Test/TransportTestCase.php | 12 +++--------- 4 files changed, 6 insertions(+), 18 deletions(-) diff --git a/Channel/ChatChannel.php b/Channel/ChatChannel.php index ea41c2e..792b4c0 100644 --- a/Channel/ChatChannel.php +++ b/Channel/ChatChannel.php @@ -28,9 +28,7 @@ public function notify(Notification $notification, RecipientInterface $recipient $message = $notification->asChatMessage($recipient, $transportName); } - if (null === $message) { - $message = ChatMessage::fromNotification($notification); - } + $message ??= ChatMessage::fromNotification($notification); if (null !== $transportName) { $message->transport($transportName); diff --git a/Channel/PushChannel.php b/Channel/PushChannel.php index e3b95af..f2f79ad 100644 --- a/Channel/PushChannel.php +++ b/Channel/PushChannel.php @@ -28,9 +28,7 @@ public function notify(Notification $notification, RecipientInterface $recipient $message = $notification->asPushMessage($recipient, $transportName); } - if (null === $message) { - $message = PushMessage::fromNotification($notification); - } + $message ??= PushMessage::fromNotification($notification); if (null !== $transportName) { $message->transport($transportName); diff --git a/Channel/SmsChannel.php b/Channel/SmsChannel.php index ebed801..1313087 100644 --- a/Channel/SmsChannel.php +++ b/Channel/SmsChannel.php @@ -29,9 +29,7 @@ public function notify(Notification $notification, RecipientInterface $recipient $message = $notification->asSmsMessage($recipient, $transportName); } - if (null === $message) { - $message = SmsMessage::fromNotification($notification, $recipient); - } + $message ??= SmsMessage::fromNotification($notification, $recipient); if (null !== $transportName) { $message->transport($transportName); diff --git a/Test/TransportTestCase.php b/Test/TransportTestCase.php index 012f4c5..34e7355 100644 --- a/Test/TransportTestCase.php +++ b/Test/TransportTestCase.php @@ -57,9 +57,7 @@ public function testToString(string $expected, TransportInterface $transport) */ public function testSupportedMessages(MessageInterface $message, TransportInterface $transport = null) { - if (null === $transport) { - $transport = $this->createTransport(); - } + $transport ??= $this->createTransport(); $this->assertTrue($transport->supports($message)); } @@ -69,9 +67,7 @@ public function testSupportedMessages(MessageInterface $message, TransportInterf */ public function testUnsupportedMessages(MessageInterface $message, TransportInterface $transport = null) { - if (null === $transport) { - $transport = $this->createTransport(); - } + $transport ??= $this->createTransport(); $this->assertFalse($transport->supports($message)); } @@ -81,9 +77,7 @@ public function testUnsupportedMessages(MessageInterface $message, TransportInte */ public function testUnsupportedMessagesTrowUnsupportedMessageTypeExceptionWhenSend(MessageInterface $message, TransportInterface $transport = null) { - if (null === $transport) { - $transport = $this->createTransport(); - } + $transport ??= $this->createTransport(); $this->expectException(UnsupportedMessageTypeException::class);