We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 10 | 
| Paths | 24 | 
| Total Lines | 31 | 
| Code Lines | 17 | 
| 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 | ||
| 18 | public function uploadFiles(Model $entry, $value = null) | ||
| 19 |     { | ||
| 20 |         $filesToDelete = CRUD::getRequest()->get('clear_'.$this->getName()); | ||
|  | |||
| 21 | $value = $value ?? CRUD::getRequest()->file($this->getName()); | ||
| 22 | $previousFiles = $this->getPreviousFiles($entry) ?? []; | ||
| 23 | |||
| 24 |         if (! is_array($previousFiles) && is_string($previousFiles)) { | ||
| 25 | $previousFiles = json_decode($previousFiles, true); | ||
| 26 | } | ||
| 27 | |||
| 28 |         if ($filesToDelete) { | ||
| 29 |             foreach ($previousFiles as $previousFile) { | ||
| 30 |                 if (in_array($previousFile, $filesToDelete)) { | ||
| 31 | Storage::disk($this->getDisk())->delete($previousFile); | ||
| 32 | |||
| 33 |                     $previousFiles = Arr::where($previousFiles, function ($value, $key) use ($previousFile) { | ||
| 34 | return $value != $previousFile; | ||
| 35 | }); | ||
| 36 | } | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 |         foreach ($value ?? [] as $file) { | ||
| 41 |             if ($file && is_file($file)) { | ||
| 42 | $fileName = $this->getFileName($file); | ||
| 43 | $file->storeAs($this->getPath(), $fileName, $this->getDisk()); | ||
| 44 | $previousFiles[] = $this->getPath().$fileName; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | return isset($entry->getCasts()[$this->getName()]) ? $previousFiles : json_encode($previousFiles); | ||
| 49 | } | ||
| 77 |