Lines
100.00%
56 / 56
Methods
100.00%
2 / 2
Classes
100.00%
1 / 1
| Name | Lines | Methods | CRAP | ||||
|---|---|---|---|---|---|---|---|
| getAttachmentList | 100.00% | 7 / 7 | 100.00% | 1 / 1 | 2 | ||
| mapMimeTypeToIcon | 100.00% | 49 / 49 | 100.00% | 1 / 1 | 12 | ||
| 28 | class AttachmentHelper | |
| 29 | { | |
| 30 | /** | |
| 31 | * Returns a list of attached files. | |
| 32 | * | |
| 33 | * @param AbstractAttachment[] $attachmentList | |
| 34 | * @return array<int, array<string, string>> | |
| 35 | */ | |
| 36 | public function getAttachmentList(array $attachmentList): array | |
| 37 | { | |
| 38 | if ($attachmentList === []) { | |
| 39 | return []; | |
| 40 | } | |
| 41 | ||
| 42 | return array_map(fn(AbstractAttachment $attachment): array => [ | |
| 43 | 'icon' => $this->mapMimeTypeToIcon($attachment->getMimeType()), | |
| 44 | 'url' => $attachment->buildUrl(), | |
| 45 | 'filename' => $attachment->getFilename(), | |
| 46 | ], array_values($attachmentList)); | |
| 47 | } | |
| 48 | ||
| 49 | private function mapMimeTypeToIcon(string $mimeType): string | |
| 50 | { | |
| 51 | return match ($mimeType) { | |
| 52 | 'application/zip' => 'file-archive-o', | |
| 53 | 'audio/basic', | |
| 54 | 'audio/midi', | |
| 55 | 'audio/mpeg', | |
| 56 | 'audio/x-aiff', | |
| 57 | 'audio/x-mpegurl', | |
| 58 | 'audio/x-pn-realaudio', | |
| 59 | 'audio/x-pn-realaudio-plugin', | |
| 60 | 'audio/x-realaudio', | |
| 61 | 'audio/x-wav', | |
| 62 | => 'file-audio-o', | |
| 63 | 'application/xhtml+xml', 'text/xml' => 'file-code-o', | |
| 64 | 'application/vnd.ms-excel', | |
| 65 | 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', | |
| 66 | => 'file-excel-o', | |
| 67 | 'image/bmp', | |
| 68 | 'image/gif', | |
| 69 | 'image/ief', | |
| 70 | 'image/jpeg', | |
| 71 | 'image/png', | |
| 72 | 'image/tiff', | |
| 73 | 'image/vnd.djvu', | |
| 74 | 'image/vnd.wap.wbmp', | |
| 75 | 'image/x-cmu-raster', | |
| 76 | 'image/x-portable-anymap', | |
| 77 | 'image/x-portable-bitmap', | |
| 78 | 'image/x-portable-graymap', | |
| 79 | 'image/x-portable-pixmap', | |
| 80 | 'image/x-rgb', | |
| 81 | 'image/x-xbitmap', | |
| 82 | 'image/x-xpixmap', | |
| 83 | 'image/x-xwindowdump', | |
| 84 | => 'file-image-o', | |
| 85 | 'application/vnd.ms-powerpoint', | |
| 86 | 'application/vnd.openxmlformats-officedocument.presentationml.presentation', | |
| 87 | => 'file-powerpoint-o', | |
| 88 | 'application/pdf' => 'file-pdf-o', | |
| 89 | 'text/plain', 'text/richtext', 'text/rtf' => 'file-text-o', | |
| 90 | 'application/msword', | |
| 91 | 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', | |
| 92 | => 'file-word-o', | |
| 93 | 'video/mpeg', | |
| 94 | 'video/quicktime', | |
| 95 | 'video/vnd.mpegurl', | |
| 96 | 'video/x-msvideo', | |
| 97 | 'video/x-sgi-movie', | |
| 98 | => 'file-video-o', | |
| 99 | default => 'file-o', | |
| 100 | }; | |
| 101 | } | |
| 102 | } |