Complex classes like QueryBuilderEngine often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use QueryBuilderEngine, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class QueryBuilderEngine extends BaseEngine implements DataTableEngineContract |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @param \Illuminate\Database\Query\Builder $builder |
||
| 24 | * @param \Yajra\Datatables\Request $request |
||
| 25 | */ |
||
| 26 | public function __construct(Builder $builder, Request $request) |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Initialize attributes. |
||
| 34 | * |
||
| 35 | * @param \Yajra\Datatables\Request $request |
||
| 36 | * @param \Illuminate\Database\Query\Builder $builder |
||
| 37 | * @param string $type |
||
| 38 | */ |
||
| 39 | protected function init($request, $builder, $type = 'builder') |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @inheritdoc |
||
| 54 | */ |
||
| 55 | public function filter(Closure $callback) |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @inheritdoc |
||
| 64 | */ |
||
| 65 | public function make($mDataSupport = false, $orderFirst = false) |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Counts current query. |
||
| 72 | * |
||
| 73 | * @return int |
||
| 74 | */ |
||
| 75 | public function count() |
||
| 88 | |||
| 89 | /** |
||
| 90 | * @inheritdoc |
||
| 91 | */ |
||
| 92 | public function filtering() |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Perform filter column on selected field. |
||
| 118 | * |
||
| 119 | * @param mixed $query |
||
| 120 | * @param string $method |
||
| 121 | * @param mixed $parameters |
||
| 122 | * @param string $column |
||
| 123 | * @param string $keyword |
||
| 124 | */ |
||
| 125 | protected function compileColumnQuery($query, $method, $parameters, $column, $keyword) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * Build Query Builder Parameters. |
||
| 148 | * |
||
| 149 | * @return array |
||
| 150 | */ |
||
| 151 | protected function parameterize() |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Add a query on global search. |
||
| 163 | * |
||
| 164 | * @param mixed $query |
||
| 165 | * @param string $column |
||
| 166 | * @param string $keyword |
||
| 167 | */ |
||
| 168 | protected function compileGlobalSearch($query, $column, $keyword) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Wrap a column and cast in pgsql |
||
| 182 | * |
||
| 183 | * @param string $column |
||
| 184 | * @return string |
||
| 185 | */ |
||
| 186 | public function castColumn($column) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @inheritdoc |
||
| 198 | */ |
||
| 199 | public function columnSearch() |
||
| 233 | |||
| 234 | /** |
||
| 235 | * Get proper keyword to use for search. |
||
| 236 | * |
||
| 237 | * @param int $i |
||
| 238 | * @return string |
||
| 239 | */ |
||
| 240 | private function getSearchKeyword($i) |
||
| 248 | |||
| 249 | /** |
||
| 250 | * @inheritdoc |
||
| 251 | */ |
||
| 252 | public function ordering() |
||
| 276 | |||
| 277 | /** |
||
| 278 | * Get order by column name. |
||
| 279 | * |
||
| 280 | * @param array $orderable |
||
| 281 | * @return string |
||
| 282 | */ |
||
| 283 | private function setupOrderColumn(array $orderable) |
||
| 295 | |||
| 296 | /** |
||
| 297 | * @inheritdoc |
||
| 298 | */ |
||
| 299 | public function paging() |
||
| 304 | |||
| 305 | /** |
||
| 306 | * Get results |
||
| 307 | * |
||
| 308 | * @return array|static[] |
||
| 309 | */ |
||
| 310 | public function results() |
||
| 314 | } |
||
| 315 |