From dbe43a52a020c55e89dd2180bc81372af843c466 Mon Sep 17 00:00:00 2001 From: Oskar Stark Date: Wed, 27 Dec 2023 13:49:27 +0100 Subject: [PATCH] [Notifier] Use CPP --- .../Notifier/Channel/BrowserChannel.php | 12 ++++-------- .../Notifier/Channel/ChannelPolicy.php | 8 +++----- .../Component/Notifier/Channel/EmailChannel.php | 14 ++++++-------- src/Symfony/Component/Notifier/Chatter.php | 14 +++++--------- .../DataCollector/NotificationDataCollector.php | 8 +++----- .../Notifier/Event/FailedMessageEvent.php | 11 ++++------- .../Component/Notifier/Event/MessageEvent.php | 11 ++++------- .../Notifier/Event/SentMessageEvent.php | 8 +++----- .../SendFailedMessageToNotifierListener.php | 8 +++----- .../Exception/IncompleteDsnException.php | 10 +++++----- .../Notifier/Exception/TransportException.php | 10 ++++++---- .../Component/Notifier/Message/ChatMessage.php | 10 ++++------ .../Component/Notifier/Message/EmailMessage.php | 10 ++++------ .../Component/Notifier/Message/PushMessage.php | 13 +++++-------- .../Component/Notifier/Message/SentMessage.php | 10 ++++------ .../Component/Notifier/Message/SmsMessage.php | 17 ++++++----------- .../Notifier/Messenger/MessageHandler.php | 8 +++----- src/Symfony/Component/Notifier/Notifier.php | 10 ++++------ .../Test/Constraint/NotificationCount.php | 14 +++++--------- .../Constraint/NotificationSubjectContains.php | 8 +++----- .../Constraint/NotificationTransportIsEqual.php | 8 +++----- src/Symfony/Component/Notifier/Texter.php | 14 +++++--------- src/Symfony/Component/Notifier/Transport.php | 8 +++----- 23 files changed, 95 insertions(+), 149 deletions(-) diff --git a/src/Symfony/Component/Notifier/Channel/BrowserChannel.php b/src/Symfony/Component/Notifier/Channel/BrowserChannel.php index 28e74e93a3651..077888fef2c68 100644 --- a/src/Symfony/Component/Notifier/Channel/BrowserChannel.php +++ b/src/Symfony/Component/Notifier/Channel/BrowserChannel.php @@ -22,14 +22,10 @@ */ final class BrowserChannel implements ChannelInterface { - private RequestStack $stack; - - private FlashMessageImportanceMapperInterface $mapper; - - public function __construct(RequestStack $stack, FlashMessageImportanceMapperInterface $mapper = new DefaultFlashMessageImportanceMapper()) - { - $this->stack = $stack; - $this->mapper = $mapper; + public function __construct( + private RequestStack $stack, + private FlashMessageImportanceMapperInterface $mapper = new DefaultFlashMessageImportanceMapper(), + ) { } public function notify(Notification $notification, RecipientInterface $recipient, string $transportName = null): void diff --git a/src/Symfony/Component/Notifier/Channel/ChannelPolicy.php b/src/Symfony/Component/Notifier/Channel/ChannelPolicy.php index afe78ec593468..6d995dd59fcae 100644 --- a/src/Symfony/Component/Notifier/Channel/ChannelPolicy.php +++ b/src/Symfony/Component/Notifier/Channel/ChannelPolicy.php @@ -18,11 +18,9 @@ */ final class ChannelPolicy implements ChannelPolicyInterface { - private array $policy; - - public function __construct(array $policy) - { - $this->policy = $policy; + public function __construct( + private array $policy, + ) { } public function getChannels(string $importance): array diff --git a/src/Symfony/Component/Notifier/Channel/EmailChannel.php b/src/Symfony/Component/Notifier/Channel/EmailChannel.php index e79d44401924b..f517c57911c8e 100644 --- a/src/Symfony/Component/Notifier/Channel/EmailChannel.php +++ b/src/Symfony/Component/Notifier/Channel/EmailChannel.php @@ -29,21 +29,19 @@ */ class EmailChannel implements ChannelInterface { - private ?TransportInterface $transport; - private ?MessageBusInterface $bus; private string|Address|null $from; - private ?Envelope $envelope; - public function __construct(TransportInterface $transport = null, MessageBusInterface $bus = null, string $from = null, Envelope $envelope = null) - { + public function __construct( + private ?TransportInterface $transport = null, + private ?MessageBusInterface $bus = null, + string $from = null, + private ?Envelope $envelope = null, + ) { if (null === $transport && null === $bus) { throw new LogicException(sprintf('"%s" needs a Transport or a Bus but both cannot be "null".', static::class)); } - $this->transport = $transport; - $this->bus = $bus; $this->from = $from ?: $envelope?->getSender(); - $this->envelope = $envelope; } /** diff --git a/src/Symfony/Component/Notifier/Chatter.php b/src/Symfony/Component/Notifier/Chatter.php index 90861061fb5f2..d1291ae6f1c14 100644 --- a/src/Symfony/Component/Notifier/Chatter.php +++ b/src/Symfony/Component/Notifier/Chatter.php @@ -23,15 +23,11 @@ */ final class Chatter implements ChatterInterface { - private TransportInterface $transport; - private ?MessageBusInterface $bus; - private ?EventDispatcherInterface $dispatcher; - - public function __construct(TransportInterface $transport, MessageBusInterface $bus = null, EventDispatcherInterface $dispatcher = null) - { - $this->transport = $transport; - $this->bus = $bus; - $this->dispatcher = $dispatcher; + public function __construct( + private TransportInterface $transport, + private ?MessageBusInterface $bus = null, + private ?EventDispatcherInterface $dispatcher = null, + ) { } public function __toString(): string diff --git a/src/Symfony/Component/Notifier/DataCollector/NotificationDataCollector.php b/src/Symfony/Component/Notifier/DataCollector/NotificationDataCollector.php index 88f37a44ccce5..555a72b352600 100644 --- a/src/Symfony/Component/Notifier/DataCollector/NotificationDataCollector.php +++ b/src/Symfony/Component/Notifier/DataCollector/NotificationDataCollector.php @@ -22,11 +22,9 @@ */ final class NotificationDataCollector extends DataCollector { - private NotificationLoggerListener $logger; - - public function __construct(NotificationLoggerListener $logger) - { - $this->logger = $logger; + public function __construct( + private NotificationLoggerListener $logger, + ) { } public function collect(Request $request, Response $response, \Throwable $exception = null): void diff --git a/src/Symfony/Component/Notifier/Event/FailedMessageEvent.php b/src/Symfony/Component/Notifier/Event/FailedMessageEvent.php index 728ea73eb4c2a..603e74ff1dcd4 100644 --- a/src/Symfony/Component/Notifier/Event/FailedMessageEvent.php +++ b/src/Symfony/Component/Notifier/Event/FailedMessageEvent.php @@ -19,13 +19,10 @@ */ final class FailedMessageEvent extends Event { - private MessageInterface $message; - private \Throwable $error; - - public function __construct(MessageInterface $message, \Throwable $error) - { - $this->message = $message; - $this->error = $error; + public function __construct( + private MessageInterface $message, + private \Throwable $error, + ) { } public function getMessage(): MessageInterface diff --git a/src/Symfony/Component/Notifier/Event/MessageEvent.php b/src/Symfony/Component/Notifier/Event/MessageEvent.php index 7fbc171fb7efb..65d7e6de4cc2f 100644 --- a/src/Symfony/Component/Notifier/Event/MessageEvent.php +++ b/src/Symfony/Component/Notifier/Event/MessageEvent.php @@ -19,13 +19,10 @@ */ final class MessageEvent extends Event { - private MessageInterface $message; - private bool $queued; - - public function __construct(MessageInterface $message, bool $queued = false) - { - $this->message = $message; - $this->queued = $queued; + public function __construct( + private MessageInterface $message, + private bool $queued = false, + ) { } public function getMessage(): MessageInterface diff --git a/src/Symfony/Component/Notifier/Event/SentMessageEvent.php b/src/Symfony/Component/Notifier/Event/SentMessageEvent.php index b6ecd9f8e2d16..537b974b66447 100644 --- a/src/Symfony/Component/Notifier/Event/SentMessageEvent.php +++ b/src/Symfony/Component/Notifier/Event/SentMessageEvent.php @@ -19,11 +19,9 @@ */ final class SentMessageEvent extends Event { - private SentMessage $message; - - public function __construct(SentMessage $message) - { - $this->message = $message; + public function __construct( + private SentMessage $message, + ) { } public function getMessage(): SentMessage diff --git a/src/Symfony/Component/Notifier/EventListener/SendFailedMessageToNotifierListener.php b/src/Symfony/Component/Notifier/EventListener/SendFailedMessageToNotifierListener.php index 07308247cab76..69c710e012ec7 100644 --- a/src/Symfony/Component/Notifier/EventListener/SendFailedMessageToNotifierListener.php +++ b/src/Symfony/Component/Notifier/EventListener/SendFailedMessageToNotifierListener.php @@ -24,11 +24,9 @@ */ class SendFailedMessageToNotifierListener implements EventSubscriberInterface { - private Notifier $notifier; - - public function __construct(Notifier $notifier) - { - $this->notifier = $notifier; + public function __construct( + private Notifier $notifier, + ) { } public function onMessageFailed(WorkerMessageFailedEvent $event): void diff --git a/src/Symfony/Component/Notifier/Exception/IncompleteDsnException.php b/src/Symfony/Component/Notifier/Exception/IncompleteDsnException.php index 2795031dcb756..4b57f63b52f62 100644 --- a/src/Symfony/Component/Notifier/Exception/IncompleteDsnException.php +++ b/src/Symfony/Component/Notifier/Exception/IncompleteDsnException.php @@ -16,11 +16,11 @@ */ class IncompleteDsnException extends InvalidArgumentException { - private ?string $dsn; - - public function __construct(string $message, string $dsn = null, \Throwable $previous = null) - { - $this->dsn = $dsn; + public function __construct( + string $message, + private ?string $dsn = null, + \Throwable $previous = null, + ) { if ($dsn) { $message = sprintf('Invalid "%s" notifier DSN: %s', $dsn, $message); } diff --git a/src/Symfony/Component/Notifier/Exception/TransportException.php b/src/Symfony/Component/Notifier/Exception/TransportException.php index 8db70a1e0cd41..1c2b584ef0899 100644 --- a/src/Symfony/Component/Notifier/Exception/TransportException.php +++ b/src/Symfony/Component/Notifier/Exception/TransportException.php @@ -18,12 +18,14 @@ */ class TransportException extends RuntimeException implements TransportExceptionInterface { - private ResponseInterface $response; private string $debug = ''; - public function __construct(string $message, ResponseInterface $response, int $code = 0, \Throwable $previous = null) - { - $this->response = $response; + public function __construct( + string $message, + private ResponseInterface $response, + int $code = 0, + \Throwable $previous = null, + ) { $this->debug .= $response->getInfo('debug') ?? ''; parent::__construct($message, $code, $previous); diff --git a/src/Symfony/Component/Notifier/Message/ChatMessage.php b/src/Symfony/Component/Notifier/Message/ChatMessage.php index 66fbe6924725f..f4bb474397c84 100644 --- a/src/Symfony/Component/Notifier/Message/ChatMessage.php +++ b/src/Symfony/Component/Notifier/Message/ChatMessage.php @@ -19,14 +19,12 @@ class ChatMessage implements MessageInterface, FromNotificationInterface { private ?string $transport = null; - private string $subject; - private ?MessageOptionsInterface $options; private ?Notification $notification = null; - public function __construct(string $subject, MessageOptionsInterface $options = null) - { - $this->subject = $subject; - $this->options = $options; + public function __construct( + private string $subject, + private ?MessageOptionsInterface $options = null, + ) { } public static function fromNotification(Notification $notification): self diff --git a/src/Symfony/Component/Notifier/Message/EmailMessage.php b/src/Symfony/Component/Notifier/Message/EmailMessage.php index 62fe4c8f97a44..d2aa856c9cc13 100644 --- a/src/Symfony/Component/Notifier/Message/EmailMessage.php +++ b/src/Symfony/Component/Notifier/Message/EmailMessage.php @@ -25,14 +25,12 @@ */ class EmailMessage implements MessageInterface, FromNotificationInterface { - private RawMessage $message; - private ?Envelope $envelope; private ?Notification $notification = null; - public function __construct(RawMessage $message, Envelope $envelope = null) - { - $this->message = $message; - $this->envelope = $envelope; + public function __construct( + private RawMessage $message, + private ?Envelope $envelope = null, + ) { } public static function fromNotification(Notification $notification, EmailRecipientInterface $recipient): self diff --git a/src/Symfony/Component/Notifier/Message/PushMessage.php b/src/Symfony/Component/Notifier/Message/PushMessage.php index 41f71d6d7b6e0..9b2d086b572f5 100644 --- a/src/Symfony/Component/Notifier/Message/PushMessage.php +++ b/src/Symfony/Component/Notifier/Message/PushMessage.php @@ -19,16 +19,13 @@ class PushMessage implements MessageInterface, FromNotificationInterface { private ?string $transport = null; - private string $subject; - private string $content; - private ?MessageOptionsInterface $options; private ?Notification $notification = null; - public function __construct(string $subject, string $content, MessageOptionsInterface $options = null) - { - $this->subject = $subject; - $this->content = $content; - $this->options = $options; + public function __construct( + private string $subject, + private string $content, + private ?MessageOptionsInterface $options = null, + ) { } public static function fromNotification(Notification $notification): self diff --git a/src/Symfony/Component/Notifier/Message/SentMessage.php b/src/Symfony/Component/Notifier/Message/SentMessage.php index 6febf9ebc97e5..5478d1d682e4e 100644 --- a/src/Symfony/Component/Notifier/Message/SentMessage.php +++ b/src/Symfony/Component/Notifier/Message/SentMessage.php @@ -16,14 +16,12 @@ */ class SentMessage { - private MessageInterface $original; - private string $transport; private ?string $messageId = null; - public function __construct(MessageInterface $original, string $transport) - { - $this->original = $original; - $this->transport = $transport; + public function __construct( + private MessageInterface $original, + private string $transport, + ) { } public function getOriginalMessage(): MessageInterface diff --git a/src/Symfony/Component/Notifier/Message/SmsMessage.php b/src/Symfony/Component/Notifier/Message/SmsMessage.php index a8d774755dfff..b7f72fafd5d89 100644 --- a/src/Symfony/Component/Notifier/Message/SmsMessage.php +++ b/src/Symfony/Component/Notifier/Message/SmsMessage.php @@ -21,22 +21,17 @@ class SmsMessage implements MessageInterface, FromNotificationInterface { private ?string $transport = null; - private string $subject; - private string $phone; - private string $from; - private ?MessageOptionsInterface $options; private ?Notification $notification = null; - public function __construct(string $phone, string $subject, string $from = '', MessageOptionsInterface $options = null) - { + public function __construct( + private string $phone, + private string $subject, + private string $from = '', + private ?MessageOptionsInterface $options = null, + ) { if ('' === $phone) { throw new InvalidArgumentException(sprintf('"%s" needs a phone number, it cannot be empty.', __CLASS__)); } - - $this->subject = $subject; - $this->phone = $phone; - $this->from = $from; - $this->options = $options; } public static function fromNotification(Notification $notification, SmsRecipientInterface $recipient): self diff --git a/src/Symfony/Component/Notifier/Messenger/MessageHandler.php b/src/Symfony/Component/Notifier/Messenger/MessageHandler.php index 88bfd9f64d143..8d99c86edfc3d 100644 --- a/src/Symfony/Component/Notifier/Messenger/MessageHandler.php +++ b/src/Symfony/Component/Notifier/Messenger/MessageHandler.php @@ -20,11 +20,9 @@ */ final class MessageHandler { - private TransportInterface $transport; - - public function __construct(TransportInterface $transport) - { - $this->transport = $transport; + public function __construct( + private TransportInterface $transport, + ) { } public function __invoke(MessageInterface $message): ?SentMessage diff --git a/src/Symfony/Component/Notifier/Notifier.php b/src/Symfony/Component/Notifier/Notifier.php index 2e0665cef7c28..61190cefcf33d 100644 --- a/src/Symfony/Component/Notifier/Notifier.php +++ b/src/Symfony/Component/Notifier/Notifier.php @@ -27,16 +27,14 @@ final class Notifier implements NotifierInterface { private array $adminRecipients = []; - private array|ContainerInterface $channels; - private ?ChannelPolicyInterface $policy; /** * @param ChannelInterface[]|ContainerInterface $channels */ - public function __construct(array|ContainerInterface $channels, ChannelPolicyInterface $policy = null) - { - $this->channels = $channels; - $this->policy = $policy; + public function __construct( + private array|ContainerInterface $channels, + private ?ChannelPolicyInterface $policy = null, + ) { } public function send(Notification $notification, RecipientInterface ...$recipients): void diff --git a/src/Symfony/Component/Notifier/Test/Constraint/NotificationCount.php b/src/Symfony/Component/Notifier/Test/Constraint/NotificationCount.php index 5850f8cc4edd7..73f07f8d50758 100644 --- a/src/Symfony/Component/Notifier/Test/Constraint/NotificationCount.php +++ b/src/Symfony/Component/Notifier/Test/Constraint/NotificationCount.php @@ -19,15 +19,11 @@ */ final class NotificationCount extends Constraint { - private int $expectedValue; - private ?string $transport; - private bool $queued; - - public function __construct(int $expectedValue, string $transport = null, bool $queued = false) - { - $this->expectedValue = $expectedValue; - $this->transport = $transport; - $this->queued = $queued; + public function __construct( + private int $expectedValue, + private ?string $transport = null, + private bool $queued = false, + ) { } public function toString(): string diff --git a/src/Symfony/Component/Notifier/Test/Constraint/NotificationSubjectContains.php b/src/Symfony/Component/Notifier/Test/Constraint/NotificationSubjectContains.php index 81cafd473a358..b06021f3f9876 100644 --- a/src/Symfony/Component/Notifier/Test/Constraint/NotificationSubjectContains.php +++ b/src/Symfony/Component/Notifier/Test/Constraint/NotificationSubjectContains.php @@ -19,11 +19,9 @@ */ final class NotificationSubjectContains extends Constraint { - private string $expectedText; - - public function __construct(string $expectedText) - { - $this->expectedText = $expectedText; + public function __construct( + private string $expectedText, + ) { } public function toString(): string diff --git a/src/Symfony/Component/Notifier/Test/Constraint/NotificationTransportIsEqual.php b/src/Symfony/Component/Notifier/Test/Constraint/NotificationTransportIsEqual.php index 990e31daccdf2..4b5f33ed2811b 100644 --- a/src/Symfony/Component/Notifier/Test/Constraint/NotificationTransportIsEqual.php +++ b/src/Symfony/Component/Notifier/Test/Constraint/NotificationTransportIsEqual.php @@ -19,11 +19,9 @@ */ final class NotificationTransportIsEqual extends Constraint { - private ?string $expectedText; - - public function __construct(?string $expectedText) - { - $this->expectedText = $expectedText; + public function __construct( + private ?string $expectedText, + ) { } public function toString(): string diff --git a/src/Symfony/Component/Notifier/Texter.php b/src/Symfony/Component/Notifier/Texter.php index 35d8578ce434e..1c9d13b428808 100644 --- a/src/Symfony/Component/Notifier/Texter.php +++ b/src/Symfony/Component/Notifier/Texter.php @@ -23,15 +23,11 @@ */ final class Texter implements TexterInterface { - private TransportInterface $transport; - private ?MessageBusInterface $bus; - private ?EventDispatcherInterface $dispatcher; - - public function __construct(TransportInterface $transport, MessageBusInterface $bus = null, EventDispatcherInterface $dispatcher = null) - { - $this->transport = $transport; - $this->bus = $bus; - $this->dispatcher = $dispatcher; + public function __construct( + private TransportInterface $transport, + private ?MessageBusInterface $bus = null, + private ?EventDispatcherInterface $dispatcher = null, + ) { } public function __toString(): string diff --git a/src/Symfony/Component/Notifier/Transport.php b/src/Symfony/Component/Notifier/Transport.php index 28059f66beca0..3e1ee1683c796 100644 --- a/src/Symfony/Component/Notifier/Transport.php +++ b/src/Symfony/Component/Notifier/Transport.php @@ -101,8 +101,6 @@ final class Transport Bridge\Zulip\ZulipTransportFactory::class, ]; - private iterable $factories; - public static function fromDsn(#[\SensitiveParameter] string $dsn, EventDispatcherInterface $dispatcher = null, HttpClientInterface $client = null): TransportInterface { $factory = new self(self::getDefaultFactories($dispatcher, $client)); @@ -120,9 +118,9 @@ public static function fromDsns(#[\SensitiveParameter] array $dsns, EventDispatc /** * @param iterable $factories */ - public function __construct(iterable $factories) - { - $this->factories = $factories; + public function __construct( + private iterable $factories, + ) { } public function fromStrings(#[\SensitiveParameter] array $dsns): Transports