Conditions | 10 |
Paths | 288 |
Total Lines | 77 |
Code Lines | 42 |
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 | |||
39 | $query = $CbCtrl->table()->select(DB::raw($table.".".$CbCtrl->primaryKey)); |
||
40 | |||
41 | $this->_filterForParent($query); |
||
42 | |||
43 | $CbCtrl->hookQueryIndex($query); |
||
44 | |||
45 | if (\Schema::hasColumn($table, 'deleted_at')) { |
||
46 | $this->_filterOutSoftDeleted($query); |
||
47 | } |
||
48 | |||
49 | $columns_table = $CbCtrl->columns_table; |
||
50 | foreach ($columns_table as $index => $coltab) { |
||
51 | $field = @$coltab['name']; |
||
52 | |||
53 | if (strpos($field, '.')) { |
||
54 | $columns_table = $this->addDotField($columns_table, $index, $field, $query); |
||
55 | } else { |
||
56 | $columns_table = $this->_addField($columns_table, $index, $field, $query, $table); |
||
57 | } |
||
58 | } |
||
59 | |||
60 | $this->_applyWhereAndQfilters($query, $columns_table, $table); |
||
61 | |||
62 | $filter_is_orderby = false; |
||
63 | if (request('filter_column')) { |
||
64 | $filter_is_orderby = app(FilterIndexRows::class)->filterIndexRows($query, request('filter_column')); |
||
65 | } |
||
66 | |||
67 | if ($filter_is_orderby === true) { |
||
68 | (new Order($this->cb))->handle($query, $table); |
||
69 | } |
||
70 | $limit = is_string($limit) ? (int)$limit : 15; |
||
71 | $data['result'] = $query->paginate($limit); |
||
72 | |||
73 | $data['columns'] = $columns_table; |
||
74 | |||
75 | if ($CbCtrl->indexReturn) { |
||
76 | return $data; |
||
77 | } |
||
78 | |||
79 | //LISTING INDEX HTML |
||
80 | $addAction = $CbCtrl->data['addAction']; |
||
81 | |||
82 | if (! empty($CbCtrl->sub_module)) { |
||
83 | $addAction = $this->_handleSubModules($addAction); |
||
84 | } |
||
85 | |||
86 | //$mainpath = CRUDBooster::mainpath(); |
||
87 | //$orig_mainpath = $CbCtrl->data['mainpath']; |
||
88 | //$titleField = $CbCtrl->titleField; |
||
89 | $number = (request('page', 1) - 1) * $limit + 1; |
||
90 | $columnsTable = array_filter($columns_table, function ($col) { |
||
91 | return $col['visible'] !== false; |
||
92 | }); |
||
93 | $htmlContents = (new RowContent($CbCtrl))->calculate($data, $number, $columnsTable, $addAction); //end foreach data[result] |
||
94 | |||
95 | $data['html_contents'] = ['html' => $htmlContents, 'data' => $data['result']]; |
||
96 | |||
97 | return $data; |
||
98 | } |
||
252 | } |