Skip to content

Commit cb08cb2

Browse files
committed
use constructor property promotion
1 parent 6a8f490 commit cb08cb2

16 files changed

+74
-109
lines changed

DelayedEnvelope.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,10 @@ final class DelayedEnvelope extends Envelope
2525
{
2626
private bool $senderSet = false;
2727
private bool $recipientsSet = false;
28-
private Message $message;
2928

30-
public function __construct(Message $message)
31-
{
32-
$this->message = $message;
29+
public function __construct(
30+
private Message $message,
31+
) {
3332
}
3433

3534
public function setSender(Address $sender): void

Event/MessageEvent.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,17 @@
2424
*/
2525
final class MessageEvent extends Event
2626
{
27-
private RawMessage $message;
28-
private Envelope $envelope;
29-
private string $transport;
30-
private bool $queued;
3127
private bool $rejected = false;
3228

3329
/** @var StampInterface[] */
3430
private array $stamps = [];
3531

36-
public function __construct(RawMessage $message, Envelope $envelope, string $transport, bool $queued = false)
37-
{
38-
$this->message = $message;
39-
$this->envelope = $envelope;
40-
$this->transport = $transport;
41-
$this->queued = $queued;
32+
public function __construct(
33+
private RawMessage $message,
34+
private Envelope $envelope,
35+
private string $transport,
36+
private bool $queued = false,
37+
) {
4238
}
4339

4440
public function getMessage(): RawMessage

EventListener/MessageListener.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ class MessageListener implements EventSubscriberInterface
3939
'bcc' => self::HEADER_ADD,
4040
];
4141

42-
private ?Headers $headers;
4342
private array $headerRules = [];
44-
private ?BodyRendererInterface $renderer;
4543

46-
public function __construct(?Headers $headers = null, ?BodyRendererInterface $renderer = null, array $headerRules = self::DEFAULT_RULES)
47-
{
48-
$this->headers = $headers;
49-
$this->renderer = $renderer;
44+
public function __construct(
45+
private ?Headers $headers = null,
46+
private ?BodyRendererInterface $renderer = null,
47+
array $headerRules = self::DEFAULT_RULES,
48+
) {
5049
foreach ($headerRules as $headerName => $rule) {
5150
$this->addHeaderRule($headerName, $rule);
5251
}

Exception/HttpTransportException.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
*/
1919
class HttpTransportException extends TransportException
2020
{
21-
private ResponseInterface $response;
22-
23-
public function __construct(string $message, ResponseInterface $response, int $code = 0, ?\Throwable $previous = null)
24-
{
21+
public function __construct(
22+
string $message,
23+
private ResponseInterface $response,
24+
int $code = 0,
25+
?\Throwable $previous = null,
26+
) {
2527
parent::__construct($message, $code, $previous);
26-
27-
$this->response = $response;
2828
}
2929

3030
public function getResponse(): ResponseInterface

Header/MetadataHeader.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
*/
1919
final class MetadataHeader extends UnstructuredHeader
2020
{
21-
private string $key;
22-
23-
public function __construct(string $key, string $value)
24-
{
25-
$this->key = $key;
26-
21+
public function __construct(
22+
private string $key,
23+
string $value,
24+
) {
2725
parent::__construct('X-Metadata-'.$key, $value);
2826
}
2927

Mailer.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,11 @@
2525
*/
2626
final class Mailer implements MailerInterface
2727
{
28-
private TransportInterface $transport;
29-
private ?MessageBusInterface $bus;
30-
private ?EventDispatcherInterface $dispatcher;
31-
32-
public function __construct(TransportInterface $transport, ?MessageBusInterface $bus = null, ?EventDispatcherInterface $dispatcher = null)
33-
{
34-
$this->transport = $transport;
35-
$this->bus = $bus;
36-
$this->dispatcher = $dispatcher;
28+
public function __construct(
29+
private TransportInterface $transport,
30+
private ?MessageBusInterface $bus = null,
31+
private ?EventDispatcherInterface $dispatcher = null,
32+
) {
3733
}
3834

3935
public function send(RawMessage $message, ?Envelope $envelope = null): void

Messenger/MessageHandler.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919
*/
2020
class MessageHandler
2121
{
22-
private TransportInterface $transport;
23-
24-
public function __construct(TransportInterface $transport)
25-
{
26-
$this->transport = $transport;
22+
public function __construct(
23+
private TransportInterface $transport,
24+
) {
2725
}
2826

2927
public function __invoke(SendEmailMessage $message): ?SentMessage

Messenger/SendEmailMessage.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919
*/
2020
class SendEmailMessage
2121
{
22-
private RawMessage $message;
23-
private ?Envelope $envelope;
24-
25-
public function __construct(RawMessage $message, ?Envelope $envelope = null)
26-
{
27-
$this->message = $message;
28-
$this->envelope = $envelope;
22+
public function __construct(
23+
private RawMessage $message,
24+
private ?Envelope $envelope = null,
25+
) {
2926
}
3027

3128
public function getMessage(): RawMessage

SentMessage.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ class SentMessage
2121
{
2222
private RawMessage $original;
2323
private RawMessage $raw;
24-
private Envelope $envelope;
2524
private string $messageId;
2625
private string $debug = '';
2726

2827
/**
2928
* @internal
3029
*/
31-
public function __construct(RawMessage $message, Envelope $envelope)
32-
{
30+
public function __construct(
31+
RawMessage $message,
32+
private Envelope $envelope,
33+
) {
3334
$message->ensureValidity();
3435

3536
$this->original = $message;
36-
$this->envelope = $envelope;
3737

3838
if ($message instanceof Message) {
3939
$message = clone $message;

Test/Constraint/EmailCount.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,11 @@
1616

1717
final class EmailCount extends Constraint
1818
{
19-
private int $expectedValue;
20-
private ?string $transport;
21-
private bool $queued;
22-
23-
public function __construct(int $expectedValue, ?string $transport = null, bool $queued = false)
24-
{
25-
$this->expectedValue = $expectedValue;
26-
$this->transport = $transport;
27-
$this->queued = $queued;
19+
public function __construct(
20+
private int $expectedValue,
21+
private ?string $transport = null,
22+
private bool $queued = false,
23+
) {
2824
}
2925

3026
public function toString(): string

0 commit comments

Comments
 (0)