| Conditions | 10 |
| Paths | 17 |
| Total Lines | 31 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 44 | * @param array<string,Validator>|Validator|null $validators |
||
| 45 | * |
||
| 46 | * @return array<array<int<0, max>, string>|string> |
||
|
|
|||
| 47 | */ |
||
| 48 | public function writeRequest(Request $request, ?string $path = '', array|Validator|null $validators = null): array |
||
| 49 | { |
||
| 50 | $uploaded = []; |
||
| 51 | $files = $request->files->all(); |
||
| 52 | foreach ($files as $name => $file) { |
||
| 53 | if (is_array($validators) && array_key_exists($name, $validators)) { |
||
| 54 | $validator = $validators[$name]; |
||
| 55 | } elseif ($validators instanceof Validator) { |
||
| 56 | $validator = $validators; |
||
| 57 | } else { |
||
| 58 | $validator = null; |
||
| 59 | } |
||
| 60 | if (\is_array($file)) { |
||
| 61 | $paths = []; |
||
| 62 | foreach ($file as $single) { |
||
| 63 | if ($single) { |
||
| 64 | $filepath = $this->writeFile($single, $path, $validator); |
||
| 65 | $paths[] = $filepath; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | $uploaded[$name] = $paths; |
||
| 69 | } elseif ($file) { |
||
| 70 | $uploaded[$name] = $this->writeFile($file, $path, $validator); |
||
| 71 | } |
||
| 72 | } |
||
| 73 | |||
| 74 | return $uploaded; |
||
| 75 | } |
||
| 121 |