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 | 33 |
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 |
||
17 | public function uploadFile(Model $entry, $value = null) |
||
18 | { |
||
19 | $filesToDelete = CRUD::getRequest()->get('clear_'.$this->getName()); |
||
20 | $value = $value ?? CRUD::getRequest()->file($this->getName()); |
||
21 | $previousFiles = $entry->getOriginal($this->getName()) ?? []; |
||
22 | |||
23 | if (! is_array($previousFiles) && is_string($previousFiles)) { |
||
24 | $previousFiles = json_decode($previousFiles, true); |
||
25 | } |
||
26 | |||
27 | if ($filesToDelete) { |
||
28 | foreach ($previousFiles as $previousFile) { |
||
29 | if (in_array($previousFile, $filesToDelete)) { |
||
30 | Storage::disk($this->getDisk())->delete($previousFile); |
||
31 | |||
32 | $previousFiles = Arr::where($previousFiles, function ($value, $key) use ($previousFile) { |
||
33 | return $value != $previousFile; |
||
34 | }); |
||
35 | } |
||
36 | } |
||
37 | } |
||
38 | |||
39 | foreach ($value ?? [] as $file) { |
||
40 | if ($file && is_file($file)) { |
||
41 | $fileName = $this->getFileName($file); |
||
42 | |||
43 | $file->storeAs($this->getPath(), $fileName, $this->getDisk()); |
||
44 | |||
45 | $previousFiles[] = $this->getPath().$fileName; |
||
46 | } |
||
47 | } |
||
48 | |||
49 | return isset($entry->getCasts()[$this->getName()]) ? $previousFiles : json_encode($previousFiles); |
||
50 | } |
||
80 |
In the issue above, the returned value is violating the contract defined by the mentioned interface.
Let's take a look at an example: