| Conditions | 16 |
| Paths | 31 |
| Total Lines | 67 |
| 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 |
||
| 76 | public static function normalizeFiles($files): array |
||
| 77 | { |
||
| 78 | if (empty($files)) { |
||
| 79 | return []; |
||
| 80 | } |
||
| 81 | |||
| 82 | if (is_object($files)) { |
||
| 83 | if (is_subclass_of($files, self::PSR7_UPLOADED_FILE_CLASS)) { |
||
|
|
|||
| 84 | return [self::extractFromUploadedFileInterface($files)]; |
||
| 85 | } |
||
| 86 | if (get_class($files) == self::SYMFONY_UPLOADED_FILE_CLASS) { |
||
| 87 | return [self::extractFromSymfonyFile($files)]; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | if (is_array($files) && is_object($files[0])) { |
||
| 92 | if (is_subclass_of($files[0], self::PSR7_UPLOADED_FILE_CLASS)) { |
||
| 93 | $result = []; |
||
| 94 | foreach ($files as $file) { |
||
| 95 | $result[] = self::extractFromUploadedFileInterface($file); |
||
| 96 | } |
||
| 97 | |||
| 98 | return $result; |
||
| 99 | } |
||
| 100 | |||
| 101 | if (get_class($files[0]) == self::SYMFONY_UPLOADED_FILE_CLASS) { |
||
| 102 | $result = []; |
||
| 103 | foreach ($files as $file) { |
||
| 104 | $result[] = self::extractFromSymfonyFile($file); |
||
| 105 | } |
||
| 106 | |||
| 107 | return $result; |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | |||
| 114 | |||
| 115 | |||
| 116 | // The caller passed $_FILES['some_field_name'] |
||
| 117 | if (isset($files['name'])) { |
||
| 118 | // we have a single file |
||
| 119 | if (! is_array($files['name'])) { |
||
| 120 | return [$files]; |
||
| 121 | } else { |
||
| 122 | // we have list of files, which PHP messes up |
||
| 123 | return Helper::remapFilesArray($files); |
||
| 124 | } |
||
| 125 | } else { |
||
| 126 | // The caller passed $_FILES |
||
| 127 | $keys = array_keys($files); |
||
| 128 | if (isset($keys[0]) && isset($files[$keys[0]]['name'])) { |
||
| 129 | if (! is_array($files[$keys[0]]['name'])) { |
||
| 130 | // $files is in the correct format already, even in the |
||
| 131 | // case it contains a single element. |
||
| 132 | return $files; |
||
| 133 | } else { |
||
| 134 | // we have list of files, which PHP messes up |
||
| 135 | return Helper::remapFilesArray($files[$keys[0]]); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | // if we got here, the $file argument is wrong |
||
| 141 | return []; |
||
| 142 | } |
||
| 143 | } |
||
| 144 |