Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| MailAttachmentDto | |
100.00% |
6 / 6 |
|
100.00% |
2 / 2 |
4 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFormattedSize | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | /** @license For full copyright and license information, please see the LICENSE.md file. */ |
| 6 | |
| 7 | namespace App\Modules\Mail\Domain\Model; |
| 8 | |
| 9 | defined('AMMONLY_APP') || exit('Direct script access is forbidden.'); |
| 10 | |
| 11 | /** |
| 12 | * Mail Attachment Data Transfer Object. |
| 13 | * |
| 14 | * Represents an individual MIME attachment or inline content part. |
| 15 | * |
| 16 | * @package App\Modules\Mail\Domain\Model |
| 17 | */ |
| 18 | final readonly class MailAttachmentDto |
| 19 | { |
| 20 | /** |
| 21 | * MailAttachmentDto constructor. |
| 22 | * |
| 23 | * @param string $partId MIME part identifier (e.g. '2' or '1.2'). |
| 24 | * @param string $filename Decoded attachment filename. |
| 25 | * @param string $mimeType MIME content type (e.g. application/pdf). |
| 26 | * @param int $size Attachment size in bytes. |
| 27 | * @param string|null $contentId Optional Content-ID for CID inline referencing. |
| 28 | * @param bool $isInline Whether content disposition is inline. |
| 29 | * @param string $disposition Content disposition header value. |
| 30 | */ |
| 31 | public function __construct( |
| 32 | public string $partId, |
| 33 | public string $filename, |
| 34 | public string $mimeType = 'application/octet-stream', |
| 35 | public int $size = 0, |
| 36 | public ?string $contentId = null, |
| 37 | public bool $isInline = false, |
| 38 | public string $disposition = 'attachment' |
| 39 | ) { |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Formats attachment file size into human readable string. |
| 44 | * |
| 45 | * @return string Formatted size (e.g. "1.4 MB", "340 KB"). |
| 46 | */ |
| 47 | public function getFormattedSize(): string |
| 48 | { |
| 49 | if ($this->size < 1024) { |
| 50 | return sprintf('%d B', $this->size); |
| 51 | } |
| 52 | if ($this->size < 1048576) { |
| 53 | return sprintf('%.1f KB', $this->size / 1024); |
| 54 | } |
| 55 | return sprintf('%.1f MB', $this->size / 1048576); |
| 56 | } |
| 57 | } |