We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
Complex classes like Read 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 Read, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
5 | trait Read |
||
6 | { |
||
7 | /* |
||
8 | |-------------------------------------------------------------------------- |
||
9 | | READ |
||
10 | |-------------------------------------------------------------------------- |
||
11 | */ |
||
12 | |||
13 | /** |
||
14 | * Find and retrieve an entry in the database or fail. |
||
15 | * |
||
16 | * @param [int] The id of the row in the db to fetch. |
||
17 | * |
||
18 | * @return [Eloquent Collection] The row in the db. |
||
|
|||
19 | */ |
||
20 | public function getEntry($id) |
||
29 | |||
30 | /** |
||
31 | * Make the query JOIN all relationships used in the columns, too, |
||
32 | * so there will be less database queries overall. |
||
33 | */ |
||
34 | public function autoEagerLoadRelationshipColumns() |
||
42 | |||
43 | /** |
||
44 | * Get all entries from the database. |
||
45 | * |
||
46 | * @return [Collection of your model] |
||
47 | */ |
||
48 | public function getEntries() |
||
61 | |||
62 | /** |
||
63 | * Get all entries from the database with conditions. |
||
64 | * |
||
65 | * @param string $length the number of records requested |
||
66 | * @param string $skip how many to skip |
||
67 | * @param string $orderBy the column to order by |
||
68 | * @param string $orderDirection how to order asc/desc |
||
69 | * @param string $filter what string to filter the name by |
||
70 | * |
||
71 | * @return [Collection of your model] |
||
72 | */ |
||
73 | public function getEntriesWithConditions( |
||
120 | |||
121 | /** |
||
122 | * Receives a filter and tries to get all the columns to be filtered by that filter *Work in progress*. |
||
123 | * |
||
124 | * @param $column |
||
125 | * @return null|string |
||
126 | */ |
||
127 | private function getColumnQuery($column) |
||
139 | |||
140 | /** |
||
141 | * Get the fields for the create or update forms. |
||
142 | * |
||
143 | * @param [form] create / update / both - defaults to 'both' |
||
144 | * @param [integer] the ID of the entity to be edited in the Update form |
||
145 | * |
||
146 | * @return [array] all the fields that need to be shown and their information |
||
147 | */ |
||
148 | public function getFields($form, $id = false) |
||
164 | |||
165 | /** |
||
166 | * Check if the create/update form has upload fields. |
||
167 | * Upload fields are the ones that have "upload" => true defined on them. |
||
168 | * @param [form] create / update / both - defaults to 'both' |
||
169 | * @param [id] id of the entity - defaults to false |
||
170 | * @return bool |
||
171 | */ |
||
172 | public function hasUploadFields($form, $id = false) |
||
181 | |||
182 | /** |
||
183 | * Enable the DETAILS ROW functionality:. |
||
184 | * |
||
185 | * In the table view, show a plus sign next to each entry. |
||
186 | * When clicking that plus sign, an AJAX call will bring whatever content you want from the EntityCrudController::showDetailsRow($id) and show it to the user. |
||
187 | */ |
||
188 | public function enableDetailsRow() |
||
192 | |||
193 | /** |
||
194 | * Disable the DETAILS ROW functionality:. |
||
195 | */ |
||
196 | public function disableDetailsRow() |
||
200 | |||
201 | /** |
||
202 | * Set the number of rows that should be show on the table page (list view). |
||
203 | */ |
||
204 | public function setDefaultPageLength($value) |
||
208 | |||
209 | /** |
||
210 | * Get the number of rows that should be show on the table page (list view). |
||
211 | */ |
||
212 | public function getDefaultPageLength() |
||
226 | |||
227 | /* |
||
228 | |-------------------------------------------------------------------------- |
||
229 | | AJAX TABLE |
||
230 | |-------------------------------------------------------------------------- |
||
231 | */ |
||
232 | |||
233 | /** |
||
234 | * Tell the list view to use AJAX for loading multiple rows. |
||
235 | */ |
||
236 | public function enableAjaxTable() |
||
240 | |||
241 | /** |
||
242 | * Check if ajax is enabled for the table view. |
||
243 | * @return bool |
||
244 | */ |
||
245 | public function ajaxTable() |
||
249 | |||
250 | /** |
||
251 | * Get the HTML of the cells in a table row, for a certain DB entry. |
||
252 | * @param Entity $entry A db entry of the current entity; |
||
253 | * @return array Array of HTML cell contents. |
||
254 | */ |
||
255 | public function getRowViews($entry) |
||
264 | |||
265 | /** |
||
266 | * Get the HTML of a cell, using the column types. |
||
267 | * @param array $column |
||
268 | * @param Entity $entry A db entry of the current entity; |
||
269 | * @return HTML |
||
270 | */ |
||
271 | public function getCellView($column, $entry) |
||
291 | |||
292 | /* |
||
293 | |-------------------------------------------------------------------------- |
||
294 | | EXPORT BUTTONS |
||
295 | |-------------------------------------------------------------------------- |
||
296 | */ |
||
297 | |||
298 | /** |
||
299 | * Tell the list view to show the DataTables export buttons. |
||
300 | */ |
||
301 | public function enableExportButtons() |
||
305 | |||
306 | /** |
||
307 | * Check if export buttons are enabled for the table view. |
||
308 | * @return bool |
||
309 | */ |
||
310 | public function exportButtons() |
||
314 | } |
||
315 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.