Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
19 / 19 |
|
100.00% |
8 / 8 |
CRAP | |
100.00% |
1 / 1 |
| Attachment | |
100.00% |
19 / 19 |
|
100.00% |
8 / 8 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| fromPath | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| fromContent | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| getPath | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getContent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFilename | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getMimeType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isFile | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | // ╔════════════════════════════════════════════════════════════╗ |
| 4 | // ║ MIT Licence (#Expat) - https://opensource.org/licenses/MIT ║ |
| 5 | // ║ Copyright 2026 Frederic Poeydomenge <dyno@phexium.com> ║ |
| 6 | // ╚════════════════════════════════════════════════════════════╝ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | namespace Phexium\Plugin\Mailer; |
| 11 | |
| 12 | use Assert\Assert; |
| 13 | |
| 14 | final readonly class Attachment |
| 15 | { |
| 16 | private function __construct( |
| 17 | private ?string $path, |
| 18 | private ?string $content, |
| 19 | private string $filename, |
| 20 | private ?string $mimeType, |
| 21 | ) {} |
| 22 | |
| 23 | public static function fromPath(string $path, ?string $filename = null, ?string $mimeType = null): self |
| 24 | { |
| 25 | Assert::that($path)->file('Attachment file does not exist: %s'); |
| 26 | |
| 27 | return new self( |
| 28 | path: $path, |
| 29 | content: null, |
| 30 | filename: $filename ?? basename($path), |
| 31 | mimeType: $mimeType, |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | public static function fromContent(string $content, string $filename, ?string $mimeType = null): self |
| 36 | { |
| 37 | return new self( |
| 38 | path: null, |
| 39 | content: $content, |
| 40 | filename: $filename, |
| 41 | mimeType: $mimeType, |
| 42 | ); |
| 43 | } |
| 44 | |
| 45 | public function getPath(): ?string |
| 46 | { |
| 47 | return $this->path; |
| 48 | } |
| 49 | |
| 50 | public function getContent(): ?string |
| 51 | { |
| 52 | return $this->content; |
| 53 | } |
| 54 | |
| 55 | public function getFilename(): string |
| 56 | { |
| 57 | return $this->filename; |
| 58 | } |
| 59 | |
| 60 | public function getMimeType(): ?string |
| 61 | { |
| 62 | return $this->mimeType; |
| 63 | } |
| 64 | |
| 65 | public function isFile(): bool |
| 66 | { |
| 67 | return $this->path !== null; |
| 68 | } |
| 69 | } |