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