Conditions | 12 |
Paths | 48 |
Total Lines | 51 |
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 |
||
20 | public function process(): void |
||
21 | { |
||
22 | $listViewModel = \YF\Modules\Base\Model\ListView::getInstance($this->moduleName, $this->request->getAction()); |
||
23 | $rows = $columns = $fields = []; |
||
24 | foreach ($this->request->getArray('columns') as $key => $value) { |
||
25 | $columns[$key] = $value['name']; |
||
26 | if ($value['name']) { |
||
27 | $fields[] = $value['name']; |
||
28 | } |
||
29 | } |
||
30 | $order = current($this->request->getArray('order', \App\Purifier::ALNUM)); |
||
31 | if ($order && isset($columns[$order['column']], $columns[$order['column']])) { |
||
32 | $listViewModel->setOrder($columns[$order['column']], strtoupper($order['dir'])); |
||
33 | } |
||
34 | if ($this->request->has('filters') && !$this->request->isEmpty('filters')) { |
||
35 | $conditions = []; |
||
36 | foreach ($this->request->getArray('filters') as $fieldName => $value) { |
||
37 | if ('' !== $value) { |
||
38 | $conditions[] = [ |
||
39 | 'fieldName' => $fieldName, |
||
40 | 'value' => $value, |
||
41 | 'operator' => 'a', |
||
42 | ]; |
||
43 | } |
||
44 | } |
||
45 | $listViewModel->setConditions($conditions); |
||
46 | } |
||
47 | $listViewModel->setFields($fields); |
||
48 | $listViewModel->setLimit($this->request->getInteger('length')); |
||
49 | $listViewModel->setOffset($this->request->getInteger('start')); |
||
50 | $listViewModel->loadRecordsList(); |
||
51 | foreach ($listViewModel->getRecordsListModel() as $id => $recordModel) { |
||
52 | $row = []; |
||
53 | foreach ($columns as $column) { |
||
54 | if ($column) { |
||
55 | $value = $recordModel->getListDisplayValue($column); |
||
56 | } else { |
||
57 | $value = $recordModel->getRecordListViewActions(); |
||
58 | } |
||
59 | $row[] = $value; |
||
60 | } |
||
61 | $rows[] = $row; |
||
62 | } |
||
63 | $response = [ |
||
64 | 'draw' => $this->request->getInteger('draw'), |
||
65 | 'iTotalDisplayRecords' => $listViewModel->getCount(), |
||
66 | 'aaData' => $rows |
||
67 | ]; |
||
68 | header('content-type: text/json; charset=UTF-8'); |
||
69 | echo \App\Json::encode($response); |
||
70 | } |
||
71 | } |
||
72 |