Conditions | 3 |
Paths | 2 |
Total Lines | 69 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 10 | ||
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 |
||
19 | public function getItems(Request $request) |
||
20 | { |
||
21 | /*$currentPage = self::getCurrentPageFromRequest(); |
||
22 | $keyword = $request->keyword; |
||
23 | |||
24 | $perPage = $this->helper->getPaginationPerPage(); |
||
25 | $items = array_merge($this->lfm->folders(), $this->lfm->files()); |
||
26 | |||
27 | $items = array_map(function ($item) { |
||
28 | return $item->fill()->attributes; |
||
29 | }, array_slice($items, ($currentPage - 1) * $perPage, $perPage)); |
||
30 | |||
31 | $c = count($items); |
||
32 | |||
33 | if (!empty($keyword)) { |
||
34 | $items = array_values(array_filter($items, function ($item) use ($keyword) { |
||
35 | if ($this->like_match("%".$keyword."%", $item['name'])) { |
||
36 | return true; |
||
37 | } else { |
||
38 | return false; |
||
39 | } |
||
40 | })); |
||
41 | } |
||
42 | |||
43 | return [ |
||
44 | 'items' => array_map(function ($item) { |
||
45 | return $item->fill()->attributes; |
||
46 | }, array_slice($items, ($currentPage - 1) * $perPage, $perPage)), |
||
47 | 'items' => $items, |
||
48 | 'paginator' => [ |
||
49 | 'current_page' => $currentPage, |
||
50 | 'total' => $c, |
||
51 | 'per_page' => $perPage, |
||
52 | ], |
||
53 | 'display' => $this->helper->getDisplayMode(), |
||
54 | 'working_dir' => $this->lfm->path('working_dir'), |
||
55 | ];*/ |
||
56 | |||
57 | |||
58 | $currentPage = self::getCurrentPageFromRequest(); |
||
59 | |||
60 | $perPage = $this->helper->getPaginationPerPage(); |
||
61 | $items = array_merge($this->lfm->folders(), $this->lfm->files()); |
||
62 | |||
63 | dd($items); |
||
64 | |||
65 | $keyword = $request->keyword; |
||
66 | |||
67 | if (!empty($keyword)) { |
||
68 | $items = array_values(array_filter($items, function ($item) use ($keyword) { |
||
69 | if ($this->like_match("%".$keyword."%", $item['name'])) { |
||
70 | return true; |
||
71 | } else { |
||
72 | return false; |
||
73 | } |
||
74 | })); |
||
75 | } |
||
76 | |||
77 | return [ |
||
78 | 'items' => array_map(function ($item) { |
||
79 | return $item->fill()->attributes; |
||
80 | }, array_slice($items, ($currentPage - 1) * $perPage, $perPage)), |
||
81 | 'paginator' => [ |
||
82 | 'current_page' => $currentPage, |
||
83 | 'total' => count($items), |
||
84 | 'per_page' => $perPage, |
||
85 | ], |
||
86 | 'display' => $this->helper->getDisplayMode(), |
||
87 | 'working_dir' => $this->lfm->path('working_dir'), |
||
88 | ]; |
||
164 |