| Total Complexity | 15 |
| Total Lines | 64 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 22 | trait FileTrait |
||
| 23 | { |
||
| 24 | /** @var FilesInterface */ |
||
| 25 | protected $files; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Internal method to fetch filename using multiple input formats. |
||
| 29 | * |
||
| 30 | * @param mixed|UploadedFileInterface|StreamableInterface $file |
||
| 31 | * @return string|null |
||
| 32 | */ |
||
| 33 | private function resolveFilename($file): ?string |
||
| 34 | { |
||
| 35 | if (empty($file)) { |
||
| 36 | return null; |
||
| 37 | } |
||
| 38 | |||
| 39 | if ( |
||
| 40 | $file instanceof StreamableInterface || |
||
| 41 | ($file instanceof UploadedFileInterface && $file->getError() === 0) |
||
| 42 | ) { |
||
| 43 | return StreamWrapper::getFilename($file->getStream()); |
||
| 44 | } |
||
| 45 | |||
| 46 | if (is_array($file)) { |
||
| 47 | if (!isset($file['tmp_name'])) { |
||
| 48 | return null; |
||
| 49 | } |
||
| 50 | |||
| 51 | $file = $file['tmp_name']; |
||
| 52 | } |
||
| 53 | |||
| 54 | if (!is_string($file) || !$this->files->exists($file)) { |
||
| 55 | return null; |
||
| 56 | } |
||
| 57 | |||
| 58 | return $file; |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Check if file being uploaded. |
||
| 63 | * |
||
| 64 | * @param mixed|UploadedFileInterface $file Filename or file array. |
||
| 65 | * @return bool |
||
| 66 | */ |
||
| 67 | private function isUploaded($file): bool |
||
| 86 | } |
||
| 87 | } |
||
| 88 |