Skip to content

Commit c850d87

Browse files
committed
added PHP 8 typehints
1 parent 3538b5f commit c850d87

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
@@ -51,9 +51,8 @@ public function __construct()
5151

5252
/**
5353
* Sets the sender of the message. Email or format "John Doe" <doe@example.com>
54-
* @return static
5554
*/
56-
public function setFrom(string $email, string $name = null)
55+
public function setFrom(string $email, string $name = null): static
5756
{
5857
$this->setHeader('From', $this->formatEmail($email, $name));
5958
return $this;
@@ -71,9 +70,8 @@ public function getFrom(): ?array
7170

7271
/**
7372
* Adds the reply-to address. Email or format "John Doe" <doe@example.com>
74-
* @return static
7573
*/
76-
public function addReplyTo(string $email, string $name = null)
74+
public function addReplyTo(string $email, string $name = null): static
7775
{
7876
$this->setHeader('Reply-To', $this->formatEmail($email, $name), true);
7977
return $this;
@@ -82,9 +80,8 @@ public function addReplyTo(string $email, string $name = null)
8280

8381
/**
8482
* Sets the subject of the message.
85-
* @return static
8683
*/
87-
public function setSubject(string $subject)
84+
public function setSubject(string $subject): static
8885
{
8986
$this->setHeader('Subject', $subject);
9087
return $this;
@@ -102,9 +99,8 @@ public function getSubject(): ?string
10299

103100
/**
104101
* Adds email recipient. Email or format "John Doe" <doe@example.com>
105-
* @return static
106102
*/
107-
public function addTo(string $email, string $name = null) // addRecipient()
103+
public function addTo(string $email, string $name = null): static // addRecipient()
108104
{
109105
$this->setHeader('To', $this->formatEmail($email, $name), true);
110106
return $this;
@@ -113,9 +109,8 @@ public function addTo(string $email, string $name = null) // addRecipient()
113109

114110
/**
115111
* Adds carbon copy email recipient. Email or format "John Doe" <doe@example.com>
116-
* @return static
117112
*/
118-
public function addCc(string $email, string $name = null)
113+
public function addCc(string $email, string $name = null): static
119114
{
120115
$this->setHeader('Cc', $this->formatEmail($email, $name), true);
121116
return $this;
@@ -124,9 +119,8 @@ public function addCc(string $email, string $name = null)
124119

125120
/**
126121
* Adds blind carbon copy email recipient. Email or format "John Doe" <doe@example.com>
127-
* @return static
128122
*/
129-
public function addBcc(string $email, string $name = null)
123+
public function addBcc(string $email, string $name = null): static
130124
{
131125
$this->setHeader('Bcc', $this->formatEmail($email, $name), true);
132126
return $this;
@@ -153,9 +147,8 @@ private function formatEmail(string $email, string $name = null): array
153147

154148
/**
155149
* Sets the Return-Path header of the message.
156-
* @return static
157150
*/
158-
public function setReturnPath(string $email)
151+
public function setReturnPath(string $email): static
159152
{
160153
$this->setHeader('Return-Path', $email);
161154
return $this;
@@ -173,9 +166,8 @@ public function getReturnPath(): ?string
173166

174167
/**
175168
* Sets email priority.
176-
* @return static
177169
*/
178-
public function setPriority(int $priority)
170+
public function setPriority(int $priority): static
179171
{
180172
$this->setHeader('X-Priority', (string) $priority);
181173
return $this;
@@ -194,9 +186,8 @@ public function getPriority(): ?int
194186

195187
/**
196188
* Sets HTML body.
197-
* @return static
198189
*/
199-
public function setHtmlBody(string $html, string $basePath = null)
190+
public function setHtmlBody(string $html, string $basePath = null): static
200191
{
201192
if ($basePath) {
202193
$cids = [];
@@ -264,9 +255,8 @@ public function addEmbeddedFile(string $file, string $content = null, string $co
264255

265256
/**
266257
* Adds inlined Mime Part.
267-
* @return static
268258
*/
269-
public function addInlinePart(MimePart $part)
259+
public function addInlinePart(MimePart $part): static
270260
{
271261
$this->inlines[] = $part;
272262
return $this;
@@ -339,9 +329,8 @@ public function generateMessage(): string
339329

340330
/**
341331
* Builds email. Does not modify itself, but returns a new object.
342-
* @return static
343332
*/
344-
public function build()
333+
public function build(): static
345334
{
346335
$mail = clone $this;
347336
$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
@@ -48,9 +48,8 @@ class MimePart
4848
/**
4949
* Sets a header.
5050
* @param string|array|null $value value or pair email => name
51-
* @return static
5251
*/
53-
public function setHeader(string $name, $value, bool $append = false)
52+
public function setHeader(string $name, string|array|null $value, bool $append = false): static
5453
{
5554
if (!$name || preg_match('#[^a-z0-9-]#i', $name)) {
5655
throw new Nette\InvalidArgumentException("Header name must be non-empty alphanumeric string, '$name' given.");
@@ -93,19 +92,17 @@ public function setHeader(string $name, $value, bool $append = false)
9392

9493
/**
9594
* Returns a header.
96-
* @return mixed
9795
*/
98-
public function getHeader(string $name)
96+
public function getHeader(string $name): mixed
9997
{
10098
return $this->headers[$name] ?? null;
10199
}
102100

103101

104102
/**
105103
* Removes a header.
106-
* @return static
107104
*/
108-
public function clearHeader(string $name)
105+
public function clearHeader(string $name): static
109106
{
110107
unset($this->headers[$name]);
111108
return $this;
@@ -156,9 +153,8 @@ public function getHeaders(): array
156153

157154
/**
158155
* Sets Content-Type header.
159-
* @return static
160156
*/
161-
public function setContentType(string $contentType, string $charset = null)
157+
public function setContentType(string $contentType, string $charset = null): static
162158
{
163159
$this->setHeader('Content-Type', $contentType . ($charset ? "; charset=$charset" : ''));
164160
return $this;
@@ -167,9 +163,8 @@ public function setContentType(string $contentType, string $charset = null)
167163

168164
/**
169165
* Sets Content-Transfer-Encoding header.
170-
* @return static
171166
*/
172-
public function setEncoding(string $encoding)
167+
public function setEncoding(string $encoding): static
173168
{
174169
$this->setHeader('Content-Transfer-Encoding', $encoding);
175170
return $this;
@@ -196,9 +191,8 @@ public function addPart(self $part = null): self
196191

197192
/**
198193
* Sets textual body.
199-
* @return static
200194
*/
201-
public function setBody(string $body)
195+
public function setBody(string $body): static
202196
{
203197
$this->body = $body;
204198
return $this;

src/Mail/SendmailMailer.php

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

2626

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

src/Mail/SmtpMailer.php

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

8383

84-
/** @return static */
85-
public function setSigner(Signer $signer): self
84+
public function setSigner(Signer $signer): static
8685
{
8786
$this->signer = $signer;
8887
return $this;
@@ -219,7 +218,7 @@ protected function disconnect(): void
219218
* Writes data to server and checks response against expected code if some provided.
220219
* @param int|int[] $expectedCode
221220
*/
222-
protected function write(string $line, $expectedCode = null, string $message = null): void
221+
protected function write(string $line, int|array $expectedCode = null, string $message = null): void
223222
{
224223
fwrite($this->connection, $line . Message::EOL);
225224
if ($expectedCode) {

0 commit comments

Comments
 (0)