Skip to content

Commit

Permalink
Use ??= more
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Nov 2, 2022
1 parent 7089189 commit 6c65758
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 18 deletions.
4 changes: 1 addition & 3 deletions Channel/ChatChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions Channel/PushChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 1 addition & 3 deletions Channel/SmsChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 3 additions & 9 deletions Test/TransportTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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));
}
Expand All @@ -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);

Expand Down

0 comments on commit 6c65758

Please sign in to comment.