Skip to content

Commit 0590193

Browse files
committed
refactor: improve docblocks and naming
1 parent 63df442 commit 0590193

File tree

7 files changed

+47
-41
lines changed

7 files changed

+47
-41
lines changed

packages/mailer/src/Builder/Email.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@
99
use Tempest\Mail\Attachments\StorageAttachment;
1010
use Tempest\Mail\Content;
1111
use Tempest\Mail\Email as EmailInterface;
12+
use Tempest\Mail\EmailPriority;
1213
use Tempest\Mail\Envelope;
1314
use Tempest\Mail\GenericEmail;
14-
use Tempest\Mail\Priority;
1515
use Tempest\Support\Arr;
1616
use Tempest\Support\Arr\ArrayInterface;
1717
use Tempest\View\View;
1818
use UnitEnum;
1919

20+
/**
21+
* A builder class for creating email objects.
22+
*/
2023
final class Email
2124
{
2225
public function __construct(
@@ -28,7 +31,7 @@ public function __construct(
2831
private(set) ?string $subject = null,
2932
private(set) null|string|View $html = null,
3033
private(set) ?string $text = null,
31-
private(set) Priority|int $priority = Priority::NORMAL,
34+
private(set) EmailPriority|int $priority = EmailPriority::NORMAL,
3235
private(set) array $headers = [],
3336
private(set) array $attachments = [],
3437
) {}
@@ -116,7 +119,7 @@ public function text(string $text): self
116119
/**
117120
* Defines the priority of the email.
118121
*/
119-
public function priority(Priority|int $priority): self
122+
public function priority(EmailPriority|int $priority): self
120123
{
121124
$this->priority = $priority;
122125

@@ -183,7 +186,7 @@ public function make(): EmailInterface
183186
bcc: Arr\wrap($this->bcc),
184187
replyTo: Arr\wrap($this->replyTo),
185188
priority: is_int($this->priority)
186-
? Priority::from($this->priority)
189+
? EmailPriority::from($this->priority)
187190
: $this->priority,
188191
headers: $this->headers,
189192
),

packages/mailer/src/Email.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
namespace Tempest\Mail;
44

5+
/**
6+
* Represents an email.
7+
*/
58
interface Email
69
{
710
/**
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Tempest\Mail;
4+
5+
enum EmailPriority: int
6+
{
7+
/**
8+
* Indicates to email services that immediate attention is required.
9+
*/
10+
case HIGHEST = 1;
11+
12+
/**
13+
* Indicates to email services that this email is important, but not critical.
14+
*/
15+
case HIGH = 2;
16+
17+
/**
18+
* The default priority for regular emails.
19+
*/
20+
case NORMAL = 3;
21+
22+
/**
23+
* Indicates to email services that this email is not important and may be read later.
24+
*/
25+
case LOW = 4;
26+
27+
/**
28+
* Indicates to email services that this email is not important.
29+
*/
30+
case LOWEST = 5;
31+
}

packages/mailer/src/Envelope.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ public function __construct(
1515
public null|string|array|Address $bcc = null,
1616
public null|string|array|Address $replyTo = null,
1717
public array $headers = [],
18-
public Priority $priority = Priority::NORMAL,
18+
public EmailPriority $priority = EmailPriority::NORMAL,
1919
) {}
2020
}

packages/mailer/src/Priority.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/mailer/src/Testing/SentTestingEmail.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Symfony\Component\Mime\Part\DataPart;
1010
use Tempest\Mail\Address;
1111
use Tempest\Mail\Email;
12-
use Tempest\Mail\Priority;
12+
use Tempest\Mail\EmailPriority;
1313
use Tempest\Mail\SentEmail;
1414
use Tempest\Support\Arr;
1515

@@ -154,9 +154,9 @@ public function assertNotBlindCarbonCopy(string|array $addresses): self
154154
/**
155155
* Asserts that the email has the given priority.
156156
*/
157-
public function assertPriority(null|int|Priority $priority): self
157+
public function assertPriority(null|int|EmailPriority $priority): self
158158
{
159-
if ($priority instanceof Priority) {
159+
if ($priority instanceof EmailPriority) {
160160
$priority = $priority->value;
161161
}
162162

tests/Integration/Mailer/SentEmailTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
use Tempest\Mail\Attachments\FileAttachment;
88
use Tempest\Mail\Attachments\StorageAttachment;
99
use Tempest\Mail\Content;
10+
use Tempest\Mail\EmailPriority;
1011
use Tempest\Mail\Envelope;
1112
use Tempest\Mail\GenericEmail;
1213
use Tempest\Mail\Mailer;
13-
use Tempest\Mail\Priority;
1414
use Tempest\Mail\Testing\SentTestingEmail;
1515
use Tempest\Mail\Testing\TestingAttachment;
1616
use Tempest\Mail\Testing\TestingMailer;
@@ -78,7 +78,7 @@ public function test_sent_email_assertions(): void
7878
$sent->assertFrom('[email protected]');
7979
$sent->assertNotFrom('[email protected]');
8080

81-
$sent->assertPriority(Priority::NORMAL);
81+
$sent->assertPriority(EmailPriority::NORMAL);
8282

8383
$sent->assertHasHeader('X-Foo');
8484
$sent->assertHasHeader('X-Foo', 'bar');

0 commit comments

Comments
 (0)