Conditions | 9 |
Paths | 144 |
Total Lines | 74 |
Code Lines | 41 |
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 |
||
21 | public function index(CBController $CbCtrl) |
||
22 | { |
||
23 | $this->cb = $CbCtrl; |
||
24 | $table = $this->table = $CbCtrl->table; |
||
25 | |||
26 | $data = []; |
||
27 | if (request('parent_table')) { |
||
28 | $data = $this->_handleParentTable(); |
||
29 | } |
||
30 | |||
31 | $data['table'] = $CbCtrl->table; |
||
32 | $data['table_pk'] = DbInspector::findPk($table); |
||
33 | $data['page_title'] = CRUDBooster::getCurrentModule()->name; |
||
34 | $data['page_description'] = cbTrans('default_module_description'); |
||
35 | //$data['date_candidate'] = $CbCtrl->date_candidate; |
||
36 | $data['limit'] = $limit = request('limit', $CbCtrl->limit); |
||
37 | |||
38 | $query = $CbCtrl->table()->select(DB::raw($table.".".$CbCtrl->primaryKey)); |
||
39 | |||
40 | $this->_filterForParent($query); |
||
41 | |||
42 | $CbCtrl->hookQueryIndex($query); |
||
43 | |||
44 | $this->_filterOutSoftDeleted($table, $query); |
||
45 | |||
46 | $columns_table = $CbCtrl->columns_table; |
||
47 | foreach ($columns_table as $index => $coltab) { |
||
48 | $field = @$coltab['name']; |
||
49 | |||
50 | if (strpos($field, '.')) { |
||
51 | $columns_table[$index] = array_merge($columns_table[$index], $this->addDotField($field, $query)); |
||
52 | } else { |
||
53 | $columns_table[$index] = array_merge($columns_table[$index], $this->_addField($field, $query, $table)); |
||
54 | } |
||
55 | } |
||
56 | |||
57 | $this->_applyWhereAndQfilters($query, $columns_table, $table); |
||
58 | |||
59 | $filter_is_orderby = false; |
||
60 | if (request('filter_column')) { |
||
61 | $filter_is_orderby = app(FilterIndexRows::class)->filterIndexRows($query, request('filter_column')); |
||
62 | } |
||
63 | |||
64 | if ($filter_is_orderby === true) { |
||
65 | (new Order($this->cb))->handle($query, $table); |
||
66 | } |
||
67 | $limit = is_string($limit) ? (int) $limit : 15; |
||
68 | $data['result'] = $query->paginate($limit); |
||
69 | |||
70 | $data['columns'] = $columns_table; |
||
71 | |||
72 | if ($CbCtrl->indexReturn) { |
||
73 | return $data; |
||
74 | } |
||
75 | |||
76 | //LISTING INDEX HTML |
||
77 | $addAction = $CbCtrl->data['addAction']; |
||
78 | |||
79 | if (! empty($CbCtrl->sub_module)) { |
||
80 | $addAction = $this->_handleSubModules($addAction); |
||
81 | } |
||
82 | |||
83 | //$mainpath = CRUDBooster::mainpath(); |
||
84 | //$orig_mainpath = $CbCtrl->data['mainpath']; |
||
85 | //$titleField = $CbCtrl->titleField; |
||
86 | $number = (request('page', 1) - 1) * $limit + 1; |
||
87 | $columnsTable = array_filter($columns_table, function ($col) { |
||
88 | return $col['visible'] !== false; |
||
89 | }); |
||
90 | $htmlContents = (new RowContent($CbCtrl))->calculate($data, $number, $columnsTable, $addAction); //end foreach data[result] |
||
91 | |||
92 | $data['html_contents'] = ['html' => $htmlContents, 'data' => $data['result']]; |
||
93 | |||
94 | return $data; |
||
95 | } |
||
252 | } |