| Conditions | 7 |
| Paths | 3 |
| Total Lines | 41 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 28 |
| CRAP Score | 7 |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 27 | function server_request_files(?array $files = null): array |
||
| 28 | { |
||
| 29 | 39 | $files ??= $_FILES; |
|
| 30 | |||
| 31 | 39 | $walker = static function ($path, $size, $error, $name, $type) use (&$walker) { |
|
| 32 | 2 | if (!is_array($path)) { |
|
| 33 | 2 | $stream = $error === UPLOAD_ERR_OK ? new FileStream($path, 'rb') : null; |
|
| 34 | |||
| 35 | 2 | return new UploadedFile($stream, $size, $error, $name, $type); |
|
| 36 | } |
||
| 37 | |||
| 38 | 1 | $result = []; |
|
| 39 | 1 | foreach ($path as $key => $_) { |
|
| 40 | 1 | if ($error[$key] !== UPLOAD_ERR_NO_FILE) { |
|
| 41 | 1 | $result[$key] = $walker( |
|
| 42 | 1 | $path[$key], |
|
| 43 | 1 | $size[$key], |
|
| 44 | 1 | $error[$key], |
|
| 45 | 1 | $name[$key], |
|
| 46 | 1 | $type[$key], |
|
| 47 | 1 | ); |
|
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | 1 | return $result; |
|
| 52 | 39 | }; |
|
| 53 | |||
| 54 | 39 | $result = []; |
|
| 55 | 39 | foreach ($files as $key => $file) { |
|
| 56 | 2 | if ($file['error'] !== UPLOAD_ERR_NO_FILE) { |
|
| 57 | 2 | $result[$key] = $walker( |
|
| 58 | 2 | $file['tmp_name'], |
|
| 59 | 2 | $file['size'], |
|
| 60 | 2 | $file['error'], |
|
| 61 | 2 | $file['name'], |
|
| 62 | 2 | $file['type'], |
|
| 63 | 2 | ); |
|
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | 39 | return $result; |
|
| 68 | } |
||
| 69 |