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