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 | 35 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
22 | private function saveMultipleFiles($entry, $value = null) |
||
23 | { |
||
24 | $filesToDelete = CRUD::getRequest()->get('clear_'.$this->name); |
||
|
|||
25 | |||
26 | $value = $value ?? CRUD::getRequest()->file($this->name); |
||
27 | |||
28 | $previousFiles = $entry->getOriginal($this->name) ?? []; |
||
29 | |||
30 | if (! is_array($previousFiles) && is_string($previousFiles)) { |
||
31 | $previousFiles = json_decode($previousFiles, true); |
||
32 | } |
||
33 | |||
34 | if ($filesToDelete) { |
||
35 | foreach ($previousFiles as $previousFile) { |
||
36 | if (in_array($previousFile, $filesToDelete)) { |
||
37 | Storage::disk($this->disk)->delete($previousFile); |
||
38 | |||
39 | $previousFiles = Arr::where($previousFiles, function ($value, $key) use ($previousFile) { |
||
40 | return $value != $previousFile; |
||
41 | }); |
||
42 | } |
||
43 | } |
||
44 | } |
||
45 | |||
46 | foreach ($value ?? [] as $file) { |
||
47 | if ($file && is_file($file)) { |
||
48 | $fileName = $this->getFileNameWithExtension($file); |
||
49 | |||
50 | $file->storeAs($this->path, $fileName, $this->disk); |
||
51 | |||
52 | $previousFiles[] = $this->path.$fileName; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | return isset($entry->getCasts()[$this->name]) ? $previousFiles : json_encode($previousFiles); |
||
57 | } |
||
88 |