| Conditions | 3 |
| Paths | 2 |
| Total Lines | 67 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 9 | ||
| 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 | $keyword = $request->keyword; |
||
| 64 | |||
| 65 | if (!empty($keyword)) { |
||
| 66 | $items = array_values(array_filter($items, function ($item) use ($keyword) { |
||
| 67 | if ($this->like_match("%".$keyword."%", $item['name'])) { |
||
| 68 | return true; |
||
| 69 | } else { |
||
| 70 | return false; |
||
| 71 | } |
||
| 72 | })); |
||
| 73 | } |
||
| 74 | |||
| 75 | return [ |
||
| 76 | 'items' => array_map(function ($item) { |
||
| 77 | return $item->fill()->attributes; |
||
| 78 | }, array_slice($items, ($currentPage - 1) * $perPage, $perPage)), |
||
| 79 | 'paginator' => [ |
||
| 80 | 'current_page' => $currentPage, |
||
| 81 | 'total' => count($items), |
||
| 82 | 'per_page' => $perPage, |
||
| 83 | ], |
||
| 84 | 'display' => $this->helper->getDisplayMode(), |
||
| 85 | 'working_dir' => $this->lfm->path('working_dir'), |
||
| 86 | ]; |
||
| 162 |