Skip to content

Commit 78e585d

Browse files
committed
added PHP 8 typehints
1 parent 1586f33 commit 78e585d

File tree

5 files changed

+21
-41
lines changed

5 files changed

+21
-41
lines changed

src/Mail/FallbackMailer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ public function send(Message $mail): void
7373
}
7474

7575

76-
/** @return static */
77-
public function addMailer(Mailer $mailer)
76+
public function addMailer(Mailer $mailer): static
7877
{
7978
$this->mailers[] = $mailer;
8079
return $this;

src/Mail/Message.php

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ public function __construct()
4949

5050
/**
5151
* Sets the sender of the message. Email or format "John Doe" <[email protected]>
52-
* @return static
5352
*/
54-
public function setFrom(string $email, ?string $name = null)
53+
public function setFrom(string $email, ?string $name = null): static
5554
{
5655
$this->setHeader('From', $this->formatEmail($email, $name));
5756
return $this;
@@ -69,9 +68,8 @@ public function getFrom(): ?array
6968

7069
/**
7170
* Adds the reply-to address. Email or format "John Doe" <[email protected]>
72-
* @return static
7371
*/
74-
public function addReplyTo(string $email, ?string $name = null)
72+
public function addReplyTo(string $email, ?string $name = null): static
7573
{
7674
$this->setHeader('Reply-To', $this->formatEmail($email, $name), true);
7775
return $this;
@@ -80,9 +78,8 @@ public function addReplyTo(string $email, ?string $name = null)
8078

8179
/**
8280
* Sets the subject of the message.
83-
* @return static
8481
*/
85-
public function setSubject(string $subject)
82+
public function setSubject(string $subject): static
8683
{
8784
$this->setHeader('Subject', $subject);
8885
return $this;
@@ -100,9 +97,8 @@ public function getSubject(): ?string
10097

10198
/**
10299
* Adds email recipient. Email or format "John Doe" <[email protected]>
103-
* @return static
104100
*/
105-
public function addTo(string $email, ?string $name = null) // addRecipient()
101+
public function addTo(string $email, ?string $name = null): static // addRecipient()
106102
{
107103
$this->setHeader('To', $this->formatEmail($email, $name), true);
108104
return $this;
@@ -111,9 +107,8 @@ public function addTo(string $email, ?string $name = null) // addRecipient()
111107

112108
/**
113109
* Adds carbon copy email recipient. Email or format "John Doe" <[email protected]>
114-
* @return static
115110
*/
116-
public function addCc(string $email, ?string $name = null)
111+
public function addCc(string $email, ?string $name = null): static
117112
{
118113
$this->setHeader('Cc', $this->formatEmail($email, $name), true);
119114
return $this;
@@ -122,9 +117,8 @@ public function addCc(string $email, ?string $name = null)
122117

123118
/**
124119
* Adds blind carbon copy email recipient. Email or format "John Doe" <[email protected]>
125-
* @return static
126120
*/
127-
public function addBcc(string $email, ?string $name = null)
121+
public function addBcc(string $email, ?string $name = null): static
128122
{
129123
$this->setHeader('Bcc', $this->formatEmail($email, $name), true);
130124
return $this;
@@ -151,9 +145,8 @@ private function formatEmail(string $email, ?string $name = null): array
151145

152146
/**
153147
* Sets the Return-Path header of the message.
154-
* @return static
155148
*/
156-
public function setReturnPath(string $email)
149+
public function setReturnPath(string $email): static
157150
{
158151
$this->setHeader('Return-Path', $email);
159152
return $this;
@@ -171,9 +164,8 @@ public function getReturnPath(): ?string
171164

172165
/**
173166
* Sets email priority.
174-
* @return static
175167
*/
176-
public function setPriority(int $priority)
168+
public function setPriority(int $priority): static
177169
{
178170
$this->setHeader('X-Priority', (string) $priority);
179171
return $this;
@@ -192,9 +184,8 @@ public function getPriority(): ?int
192184

193185
/**
194186
* Sets HTML body.
195-
* @return static
196187
*/
197-
public function setHtmlBody(string $html, ?string $basePath = null)
188+
public function setHtmlBody(string $html, ?string $basePath = null): static
198189
{
199190
if ($basePath) {
200191
$cids = [];
@@ -262,9 +253,8 @@ public function addEmbeddedFile(string $file, ?string $content = null, ?string $
262253

263254
/**
264255
* Adds inlined Mime Part.
265-
* @return static
266256
*/
267-
public function addInlinePart(MimePart $part)
257+
public function addInlinePart(MimePart $part): static
268258
{
269259
$this->inlines[] = $part;
270260
return $this;
@@ -338,9 +328,8 @@ public function generateMessage(): string
338328

339329
/**
340330
* Builds email. Does not modify itself, but returns a new object.
341-
* @return static
342331
*/
343-
public function build()
332+
public function build(): static
344333
{
345334
$mail = clone $this;
346335
$mail->setHeader('Message-ID', $mail->getHeader('Message-ID') ?? $this->getRandomId());

src/Mail/MimePart.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ class MimePart
4747
/**
4848
* Sets a header.
4949
* @param string|array|null $value value or pair email => name
50-
* @return static
5150
*/
52-
public function setHeader(string $name, $value, bool $append = false)
51+
public function setHeader(string $name, string|array|null $value, bool $append = false): static
5352
{
5453
if (!$name || preg_match('#[^a-z0-9-]#i', $name)) {
5554
throw new Nette\InvalidArgumentException("Header name must be non-empty alphanumeric string, '$name' given.");
@@ -92,19 +91,17 @@ public function setHeader(string $name, $value, bool $append = false)
9291

9392
/**
9493
* Returns a header.
95-
* @return mixed
9694
*/
97-
public function getHeader(string $name)
95+
public function getHeader(string $name): mixed
9896
{
9997
return $this->headers[$name] ?? null;
10098
}
10199

102100

103101
/**
104102
* Removes a header.
105-
* @return static
106103
*/
107-
public function clearHeader(string $name)
104+
public function clearHeader(string $name): static
108105
{
109106
unset($this->headers[$name]);
110107
return $this;
@@ -155,9 +152,8 @@ public function getHeaders(): array
155152

156153
/**
157154
* Sets Content-Type header.
158-
* @return static
159155
*/
160-
public function setContentType(string $contentType, ?string $charset = null)
156+
public function setContentType(string $contentType, ?string $charset = null): static
161157
{
162158
$this->setHeader('Content-Type', $contentType . ($charset ? "; charset=$charset" : ''));
163159
return $this;
@@ -166,9 +162,8 @@ public function setContentType(string $contentType, ?string $charset = null)
166162

167163
/**
168164
* Sets Content-Transfer-Encoding header.
169-
* @return static
170165
*/
171-
public function setEncoding(string $encoding)
166+
public function setEncoding(string $encoding): static
172167
{
173168
$this->setHeader('Content-Transfer-Encoding', $encoding);
174169
return $this;
@@ -195,9 +190,8 @@ public function addPart(?self $part = null): self
195190

196191
/**
197192
* Sets textual body.
198-
* @return static
199193
*/
200-
public function setBody(string $body)
194+
public function setBody(string $body): static
201195
{
202196
$this->body = $body;
203197
return $this;

src/Mail/SendmailMailer.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ class SendmailMailer implements Mailer
2323
private ?Signer $signer = null;
2424

2525

26-
/** @return static */
27-
public function setSigner(Signer $signer): self
26+
public function setSigner(Signer $signer): static
2827
{
2928
$this->signer = $signer;
3029
return $this;

src/Mail/SmtpMailer.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public function __construct(array $options = [])
7272
}
7373

7474

75-
/** @return static */
76-
public function setSigner(Signer $signer): self
75+
public function setSigner(Signer $signer): static
7776
{
7877
$this->signer = $signer;
7978
return $this;
@@ -210,7 +209,7 @@ protected function disconnect(): void
210209
* Writes data to server and checks response against expected code if some provided.
211210
* @param int|int[] $expectedCode
212211
*/
213-
protected function write(string $line, $expectedCode = null, ?string $message = null): void
212+
protected function write(string $line, int|array|null $expectedCode = null, ?string $message = null): void
214213
{
215214
fwrite($this->connection, $line . Message::EOL);
216215
if ($expectedCode) {

0 commit comments

Comments
 (0)