| Conditions | 7 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 72 | public static function normalizeFiles(array $files): array |
||
| 73 | { |
||
| 74 | /** @var array<mixed> $result */ |
||
| 75 | $result = []; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * TODO |
||
| 79 | * Only support for : |
||
| 80 | * <input type = 'file' name ='my_file' /><br /> |
||
| 81 | * <input type = 'file' name ='files[]' /><br /> |
||
| 82 | * |
||
| 83 | * Not support currently: |
||
| 84 | * <input type = 'file' name ='files[my_name]' /> |
||
| 85 | * <input type = 'file' name ='files[][foo]' /> |
||
| 86 | * <input type = 'file' name ='files[][bar][]' /> |
||
| 87 | * <input type = 'file' name ='files[file1][file2][file3][file_n]' /> |
||
| 88 | * <input type = 'file' name ='files[file_name][]' /> |
||
| 89 | */ |
||
| 90 | foreach ($files as $name => $file) { |
||
| 91 | if ($file instanceof UploadedFile) { |
||
| 92 | $tempName = (string) tempnam(sys_get_temp_dir(), uniqid()); |
||
| 93 | static::moveUploadedFileToTempDirectory($file, $tempName); |
||
| 94 | |||
| 95 | $result[$name] = File::create( |
||
| 96 | $tempName, |
||
| 97 | (string) $file->getClientFilename(), |
||
| 98 | $file->getClientFilename(), |
||
| 99 | $file->getError() |
||
| 100 | ); |
||
| 101 | continue; |
||
| 102 | } |
||
| 103 | |||
| 104 | if (is_array($file)) { |
||
| 105 | $result[$name] = []; |
||
| 106 | |||
| 107 | foreach ($file as $index => $file2) { |
||
| 108 | if (is_int($index) && $file2 instanceof UploadedFile) { |
||
| 109 | $tempName = (string) tempnam(sys_get_temp_dir(), uniqid()); |
||
| 110 | static::moveUploadedFileToTempDirectory($file2, $tempName); |
||
| 111 | |||
| 112 | $result[$name][$index] = File::create( |
||
| 113 | $tempName, |
||
| 114 | (string) $file2->getClientFilename(), |
||
| 115 | $file2->getClientFilename(), |
||
| 116 | $file2->getError() |
||
| 117 | ); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | return $result; |
||
| 124 | } |
||
| 186 |