Skip to content

Commit

Permalink
Fix minor corrections. (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
terabytesoftw committed Feb 2, 2023
1 parent d747cfa commit a4dbb84
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
54 changes: 50 additions & 4 deletions src/MailerService.php
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
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
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

0 comments on commit a4dbb84

Please sign in to comment.