Conditions | 10 |
Paths | 50 |
Total Lines | 58 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
20 | public function getDelete() |
||
21 | { |
||
22 | $item_names = request('items'); |
||
|
|||
23 | $errors = []; |
||
24 | |||
25 | foreach ($item_names as $name_to_delete) { |
||
26 | $file = $this->lfm->setName($name_to_delete); |
||
27 | |||
28 | if ($file->isDirectory()) { |
||
29 | event(new FolderIsDeleting($file->path('absolute'))); |
||
30 | } else { |
||
31 | event(new FileIsDeleting($file->path('absolute'))); |
||
32 | event(new ImageIsDeleting($file->path('absolute'))); |
||
33 | } |
||
34 | |||
35 | if (!Storage::disk($this->helper->config('disk'))->exists($file->path('storage'))) { |
||
36 | abort(404); |
||
37 | } |
||
38 | |||
39 | $file_to_delete = $this->lfm->pretty($name_to_delete); |
||
40 | $file_path = $file_to_delete->path('absolute'); |
||
41 | |||
42 | if (is_null($name_to_delete)) { |
||
43 | array_push($errors, parent::error('folder-name')); |
||
44 | continue; |
||
45 | } |
||
46 | |||
47 | if (! $this->lfm->setName($name_to_delete)->exists()) { |
||
48 | array_push($errors, parent::error('folder-not-found', ['folder' => $file_path])); |
||
49 | continue; |
||
50 | } |
||
51 | |||
52 | if ($this->lfm->setName($name_to_delete)->isDirectory()) { |
||
53 | if (! $this->lfm->setName($name_to_delete)->directoryIsEmpty()) { |
||
54 | array_push($errors, parent::error('delete-folder')); |
||
55 | continue; |
||
56 | } |
||
57 | |||
58 | $this->lfm->setName($name_to_delete)->delete(); |
||
59 | |||
60 | event(new FolderWasDeleted($file_path)); |
||
61 | } else { |
||
62 | if ($file_to_delete->isImage()) { |
||
63 | $this->lfm->setName($name_to_delete)->thumb()->delete(); |
||
64 | } |
||
65 | |||
66 | $this->lfm->setName($name_to_delete)->delete(); |
||
67 | |||
68 | event(new FileWasDeleted($file_path)); |
||
69 | event(new ImageWasDeleted($file_path)); |
||
70 | } |
||
71 | } |
||
72 | |||
73 | if (count($errors) > 0) { |
||
74 | return response()->json($errors, 400); |
||
75 | } |
||
76 | |||
77 | return parent::$success_response; |
||
78 | } |
||
80 |