Skip to content

Commit 6838472

Browse files
committed
added PHP 8 typehints
1 parent 24fed2f commit 6838472

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

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

7170
/**
7271
* Adds the reply-to address. Email or format "John Doe" <[email protected]>
73-
* @return static
7472
*/
75-
public function addReplyTo(string $email, string $name = null)
73+
public function addReplyTo(string $email, string $name = null): static
7674
{
7775
$this->setHeader('Reply-To', $this->formatEmail($email, $name), true);
7876
return $this;
@@ -81,9 +79,8 @@ public function addReplyTo(string $email, string $name = null)
8179

8280
/**
8381
* Sets the subject of the message.
84-
* @return static
8582
*/
86-
public function setSubject(string $subject)
83+
public function setSubject(string $subject): static
8784
{
8885
$this->setHeader('Subject', $subject);
8986
return $this;
@@ -101,9 +98,8 @@ public function getSubject(): ?string
10198

10299
/**
103100
* Adds email recipient. Email or format "John Doe" <[email protected]>
104-
* @return static
105101
*/
106-
public function addTo(string $email, string $name = null) // addRecipient()
102+
public function addTo(string $email, string $name = null): static // addRecipient()
107103
{
108104
$this->setHeader('To', $this->formatEmail($email, $name), true);
109105
return $this;
@@ -112,9 +108,8 @@ public function addTo(string $email, string $name = null) // addRecipient()
112108

113109
/**
114110
* Adds carbon copy email recipient. Email or format "John Doe" <[email protected]>
115-
* @return static
116111
*/
117-
public function addCc(string $email, string $name = null)
112+
public function addCc(string $email, string $name = null): static
118113
{
119114
$this->setHeader('Cc', $this->formatEmail($email, $name), true);
120115
return $this;
@@ -123,9 +118,8 @@ public function addCc(string $email, string $name = null)
123118

124119
/**
125120
* Adds blind carbon copy email recipient. Email or format "John Doe" <[email protected]>
126-
* @return static
127121
*/
128-
public function addBcc(string $email, string $name = null)
122+
public function addBcc(string $email, string $name = null): static
129123
{
130124
$this->setHeader('Bcc', $this->formatEmail($email, $name), true);
131125
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 = [];
@@ -261,9 +252,8 @@ public function addEmbeddedFile(string $file, string $content = null, string $co
261252

262253
/**
263254
* Adds inlined Mime Part.
264-
* @return static
265255
*/
266-
public function addInlinePart(MimePart $part)
256+
public function addInlinePart(MimePart $part): static
267257
{
268258
$this->inlines[] = $part;
269259
return $this;
@@ -334,9 +324,8 @@ public function generateMessage(): string
334324

335325
/**
336326
* Builds email. Does not modify itself, but returns a new object.
337-
* @return static
338327
*/
339-
public function build()
328+
public function build(): static
340329
{
341330
$mail = clone $this;
342331
$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.");
@@ -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;
@@ -153,9 +150,8 @@ public function getHeaders(): array
153150

154151
/**
155152
* Sets Content-Type header.
156-
* @return static
157153
*/
158-
public function setContentType(string $contentType, string $charset = null)
154+
public function setContentType(string $contentType, string $charset = null): static
159155
{
160156
$this->setHeader('Content-Type', $contentType . ($charset ? "; charset=$charset" : ''));
161157
return $this;
@@ -164,9 +160,8 @@ public function setContentType(string $contentType, string $charset = null)
164160

165161
/**
166162
* Sets Content-Transfer-Encoding header.
167-
* @return static
168163
*/
169-
public function setEncoding(string $encoding)
164+
public function setEncoding(string $encoding): static
170165
{
171166
$this->setHeader('Content-Transfer-Encoding', $encoding);
172167
return $this;
@@ -193,9 +188,8 @@ public function addPart(self $part = null): self
193188

194189
/**
195190
* Sets textual body.
196-
* @return static
197191
*/
198-
public function setBody(string $body)
192+
public function setBody(string $body): static
199193
{
200194
$this->body = $body;
201195
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
@@ -79,8 +79,7 @@ public function __construct(array $options = [])
7979
}
8080

8181

82-
/** @return static */
83-
public function setSigner(Signer $signer): self
82+
public function setSigner(Signer $signer): static
8483
{
8584
$this->signer = $signer;
8685
return $this;
@@ -215,7 +214,7 @@ protected function disconnect(): void
215214
* Writes data to server and checks response against expected code if some provided.
216215
* @param int|int[] $expectedCode
217216
*/
218-
protected function write(string $line, $expectedCode = null, string $message = null): void
217+
protected function write(string $line, int|array $expectedCode = null, string $message = null): void
219218
{
220219
fwrite($this->connection, $line . Message::EOL);
221220
if ($expectedCode) {

0 commit comments

Comments
 (0)