Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix minor corrections. #10

Merged
merged 1 commit into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 50 additions & 4 deletions src/MailerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,26 @@ public function __construct(
) {
}

public function attachmentsFromPath(string $value): self
/**
* Returns a new instance with the specified attachments.
*
* @param array $value Attachments.
*
* @psalm-param string[] $value
*/
public function attachments(array $value): self
{
$new = clone $this;
$new->attachments[] = $this->aliases->get($value);
$new->attachments = $value;

return $new;
}

/**
* Returns a new instance with the specified from.
*
* @param string $value From.
*/
public function from(string $value): self
{
$new = clone $this;
Expand All @@ -54,7 +66,9 @@ public function from(string $value): self
}

/**
* @param array $value
* Returns a new instance with the specified layout.
*
* @param array $value Layout.
*
* @psalm-param array<string, string>|string|null $value
*/
Expand All @@ -66,6 +80,11 @@ public function layout(array|string|null $value): self
return $new;
}

/**
* Returns a new instance with the specified signature image.
*
* @param string $value Signature image.
*/
public function signatureImage(string $value): self
{
$new = clone $this;
Expand All @@ -78,6 +97,11 @@ public function signatureImage(string $value): self
return $new;
}

/**
* Returns a new instance with the specified signature text.
*
* @param string $value Signature text.
*/
public function signatureText(string $value): self
{
$new = clone $this;
Expand All @@ -86,6 +110,11 @@ public function signatureText(string $value): self
return $new;
}

/**
* Returns a new instance with the specified subject.
*
* @param string $value Subject.
*/
public function subject(string $value): self
{
$new = clone $this;
Expand All @@ -94,6 +123,11 @@ public function subject(string $value): self
return $new;
}

/**
* Returns a new instance with the specified translator category.
*
* @param string $value Translator category.
*/
public function translatorCategory(string $value): self
{
$new = clone $this;
Expand All @@ -105,6 +139,11 @@ public function translatorCategory(string $value): self
return $new;
}

/**
* Returns a new instance with the specified view path.
*
* @param string $value View path.
*/
public function viewPath(string $value): self
{
$new = clone $this;
Expand All @@ -116,6 +155,12 @@ public function viewPath(string $value): self
return $new;
}

/**
* Sends an email.
*
* @param string $email Email.
* @param array $params Params.
*/
public function send(string $email, array $params = []): bool
{
$message = $this->mailer
Expand All @@ -136,8 +181,9 @@ public function send(string $email, array $params = []): bool
->withTo($email);

foreach ($this->attachments as $attachment) {
$filename = $this->aliases->get($attachment);
$message = $message->withAttached(
File::fromPath($attachment, basename($attachment), mime_content_type($attachment))
File::fromPath($filename, basename($filename), mime_content_type($filename))
);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Mailer/ImmutabilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testImmutability(): void

$mailer = $this->mailer;

$this->assertNotSame($mailer, $mailer->attachmentsFromPath(''));
$this->assertNotSame($mailer, $mailer->attachments([]));
$this->assertNotSame($mailer, $mailer->from(''));
$this->assertNotSame($mailer, $mailer->layout([]));
$this->assertNotSame($mailer, $mailer->signatureImage('@resources/data/test.txt'));
Expand Down
6 changes: 3 additions & 3 deletions tests/Mailer/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testMailer(): void

$this->assertTrue(
$this->mailer
->attachmentsFromPath('@resources/data/test.txt')
->attachments(['@resources/data/test.txt'])
->from('admin@example.com')
->layout(['html' => 'contact'])
->signatureImage('@resources/data/test.txt')
Expand Down Expand Up @@ -51,7 +51,7 @@ public function testMailerWithEmptySignatureImage(): void

$this->assertTrue(
$this->mailer
->attachmentsFromPath('@resources/data/test.txt')
->attachments(['@resources/data/test.txt'])
->from('admin@example.com')
->layout(['html' => 'contact'])
->signatureImage('')
Expand All @@ -67,7 +67,7 @@ public function testMailerWithTranslatorCategory(): void

$this->assertTrue(
$this->mailer
->attachmentsFromPath('@resources/data/test.txt')
->attachments(['@resources/data/test.txt'])
->from('admin@example.com')
->layout(['html' => 'contact'])
->signatureText('Signature')
Expand Down