We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Conditions | 11 |
| Paths | 49 |
| Total Lines | 53 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 1 | Features | 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 |
||
| 76 | public function search() |
||
| 77 | { |
||
| 78 | $this->crud->hasAccessOrFail('list'); |
||
| 79 | |||
| 80 | // If there's a config closure in the cache for this CRUD, run that configuration closure. |
||
| 81 | // This is done in order to allow the developer to configure the datatable component. |
||
| 82 | DatatableCache::applyFromRequest($this->crud); |
||
| 83 | |||
| 84 | $this->crud->applyUnappliedFilters(); |
||
| 85 | |||
| 86 | $start = (int) request()->input('start'); |
||
| 87 | $length = (int) request()->input('length'); |
||
| 88 | $search = request()->input('search'); |
||
| 89 | |||
| 90 | // check if length is allowed by developer |
||
| 91 | if ($length && ! in_array($length, $this->crud->getPageLengthMenu()[0])) { |
||
| 92 | return response()->json([ |
||
| 93 | 'error' => 'Unknown page length.', |
||
| 94 | ], 400); |
||
| 95 | } |
||
| 96 | |||
| 97 | // if a search term was present |
||
| 98 | if ($search && $search['value'] ?? false) { |
||
| 99 | // filter the results accordingly |
||
| 100 | $this->crud->applySearchTerm($search['value']); |
||
| 101 | } |
||
| 102 | // start the results according to the datatables pagination |
||
| 103 | if ($start) { |
||
| 104 | $this->crud->skip($start); |
||
| 105 | } |
||
| 106 | // limit the number of results according to the datatables pagination |
||
| 107 | if ($length) { |
||
| 108 | $this->crud->take($length); |
||
| 109 | } |
||
| 110 | // overwrite any order set in the setup() method with the datatables order |
||
| 111 | $this->crud->applyDatatableOrder(); |
||
| 112 | |||
| 113 | $entries = $this->crud->getEntries(); |
||
| 114 | $requestTotalEntryCount = request()->get('totalEntryCount') ? (int) request()->get('totalEntryCount') : null; |
||
| 115 | // if show entry count is disabled we use the "simplePagination" technique to move between pages. |
||
| 116 | if ($this->crud->getOperationSetting('showEntryCount')) { |
||
| 117 | $totalEntryCount = (int) ($requestTotalEntryCount ?: $this->crud->getTotalQueryCount()); |
||
| 118 | $filteredEntryCount = $this->crud->getFilteredQueryCount() ?? $totalEntryCount; |
||
| 119 | } else { |
||
| 120 | $totalEntryCount = $length; |
||
| 121 | $entryCount = $entries->count(); |
||
| 122 | $filteredEntryCount = $entryCount < $length ? $entryCount : $length + $start + 1; |
||
| 123 | } |
||
| 124 | |||
| 125 | // store the totalEntryCount in CrudPanel so that multiple blade files can access it |
||
| 126 | $this->crud->setOperationSetting('totalEntryCount', $totalEntryCount); |
||
| 127 | |||
| 128 | return $this->crud->getEntriesAsJsonForDatatables($entries, $totalEntryCount, $filteredEntryCount, $start); |
||
| 129 | } |
||
| 151 |