Complex classes like LaravelQuery 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 LaravelQuery, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
24 | class LaravelQuery implements IQueryProvider |
||
25 | { |
||
26 | 5 | protected $expression; |
|
27 | protected $auth; |
||
28 | protected $reader; |
||
29 | 5 | public $queryProviderClassName; |
|
30 | 5 | private $verbMap = []; |
|
31 | 5 | ||
32 | 5 | public function __construct(AuthInterface $auth = null) |
|
43 | |||
44 | /** |
||
45 | * Indicates if the QueryProvider can handle ordered paging, this means respecting order, skip, and top parameters |
||
46 | * If the query provider can not handle ordered paging, it must return the entire result set and POData will |
||
47 | * perform the ordering and paging |
||
48 | * |
||
49 | * @return Boolean True if the query provider can handle ordered paging, false if POData should perform the paging |
||
50 | */ |
||
51 | public function handlesOrderedPaging() |
||
55 | |||
56 | /** |
||
57 | * Gets the expression provider used by to compile OData expressions into expression used by this query provider. |
||
58 | * |
||
59 | * @return \POData\Providers\Expression\IExpressionProvider |
||
60 | */ |
||
61 | public function getExpressionProvider() |
||
65 | |||
66 | /** |
||
67 | * Gets the LaravelReadQuery instance used to handle read queries (repetitious, nyet?) |
||
68 | * |
||
69 | * @return LaravelReadQuery |
||
70 | 3 | */ |
|
71 | public function getReader() |
||
75 | |||
76 | /** |
||
77 | * Gets collection of entities belongs to an entity set |
||
78 | * IE: http://host/EntitySet |
||
79 | 3 | * http://host/EntitySet?$skip=10&$top=5&filter=Prop gt Value |
|
80 | * |
||
81 | * @param QueryType $queryType indicates if this is a query for a count, entities, or entities with a count |
||
82 | 3 | * @param ResourceSet $resourceSet The entity set containing the entities to fetch |
|
83 | 1 | * @param FilterInfo $filterInfo represents the $filter parameter of the OData query. NULL if no $filter specified |
|
84 | 1 | * @param mixed $orderBy sorted order if we want to get the data in some specific order |
|
85 | * @param int $top number of records which need to be skip |
||
86 | 3 | * @param String $skipToken value indicating what records to skip |
|
87 | 3 | * @param Model|Relation|null $sourceEntityInstance Starting point of query |
|
88 | 3 | * |
|
89 | * @return QueryResult |
||
90 | 3 | */ |
|
91 | public function getResourceSet( |
||
110 | /** |
||
111 | * Gets an entity instance from an entity set identified by a key |
||
112 | * IE: http://host/EntitySet(1L) |
||
113 | * http://host/EntitySet(KeyA=2L,KeyB='someValue') |
||
114 | * |
||
115 | * @param ResourceSet $resourceSet The entity set containing the entity to fetch |
||
116 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to fetch |
||
117 | 3 | * |
|
118 | 1 | * @return object|null Returns entity instance if found else null |
|
119 | 1 | */ |
|
120 | 1 | public function getResourceFromResourceSet( |
|
126 | |||
127 | 3 | /** |
|
128 | 3 | * Get related resource set for a resource |
|
129 | 3 | * IE: http://host/EntitySet(1L)/NavigationPropertyToCollection |
|
130 | * http://host/EntitySet?$expand=NavigationPropertyToCollection |
||
131 | * |
||
132 | * @param QueryType $queryType indicates if this is a query for a count, entities, or entities with a count |
||
133 | * @param ResourceSet $sourceResourceSet The entity set containing the source entity |
||
134 | * @param object $sourceEntityInstance The source entity instance. |
||
135 | * @param ResourceSet $targetResourceSet The resource set of containing the target of the navigation property |
||
136 | * @param ResourceProperty $targetProperty The navigation property to retrieve |
||
137 | * @param FilterInfo $filter represents the $filter parameter of the OData query. NULL if no $filter specified |
||
138 | * @param mixed $orderBy sorted order if we want to get the data in some specific order |
||
139 | * @param int $top number of records which need to be skip |
||
140 | * @param String $skip value indicating what records to skip |
||
141 | * |
||
142 | * @return QueryResult |
||
143 | * |
||
144 | */ |
||
145 | public function getRelatedResourceSet( |
||
168 | |||
169 | /** |
||
170 | * Gets a related entity instance from an entity set identified by a key |
||
171 | * IE: http://host/EntitySet(1L)/NavigationPropertyToCollection(33) |
||
172 | * |
||
173 | * @param ResourceSet $sourceResourceSet The entity set containing the source entity |
||
174 | * @param object $sourceEntityInstance The source entity instance. |
||
175 | * @param ResourceSet $targetResourceSet The entity set containing the entity to fetch |
||
176 | * @param ResourceProperty $targetProperty The metadata of the target property. |
||
177 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to fetch |
||
178 | * |
||
179 | * @return object|null Returns entity instance if found else null |
||
180 | */ |
||
181 | public function getResourceFromRelatedResourceSet( |
||
196 | |||
197 | /** |
||
198 | * Get related resource for a resource |
||
199 | 3 | * IE: http://host/EntitySet(1L)/NavigationPropertyToSingleEntity |
|
200 | * http://host/EntitySet?$expand=NavigationPropertyToSingleEntity |
||
201 | * |
||
202 | * @param ResourceSet $sourceResourceSet The entity set containing the source entity |
||
203 | * @param object $sourceEntityInstance The source entity instance. |
||
204 | * @param ResourceSet $targetResourceSet The entity set containing the entity pointed to by the navigation property |
||
205 | * @param ResourceProperty $targetProperty The navigation property to fetch |
||
206 | * |
||
207 | * @return object|null The related resource if found else null |
||
208 | */ |
||
209 | public function getRelatedResourceReference( |
||
222 | |||
223 | /** |
||
224 | * Updates a resource |
||
225 | * |
||
226 | * @param ResourceSet $sourceResourceSet The entity set containing the source entity |
||
227 | * @param object $sourceEntityInstance The source entity instance |
||
228 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to fetch |
||
229 | * @param object $data The New data for the entity instance. |
||
230 | * @param bool $shouldUpdate Should undefined values be updated or reset to default |
||
231 | * |
||
232 | * @return object|null The new resource value if it is assignable or throw exception for null. |
||
233 | */ |
||
234 | public function updateResource( |
||
244 | /** |
||
245 | * Delete resource from a resource set. |
||
246 | * @param ResourceSet|null $sourceResourceSet |
||
247 | * @param object $sourceEntityInstance |
||
248 | * |
||
249 | * return bool true if resources sucessfully deteled, otherwise false. |
||
250 | */ |
||
251 | public function deleteResource( |
||
273 | /** |
||
274 | * @param ResourceSet $resourceSet The entity set containing the entity to fetch |
||
275 | * @param object $sourceEntityInstance The source entity instance |
||
276 | * @param object $data The New data for the entity instance. |
||
277 | * |
||
278 | * returns object|null returns the newly created model if sucessful or null if model creation failed. |
||
279 | */ |
||
280 | public function createResourceforResourceSet( |
||
288 | |||
289 | /** |
||
290 | * @param $sourceEntityInstance |
||
291 | * @param $data |
||
292 | 1 | * @param $class |
|
293 | * @param string $verb |
||
294 | * @return array|mixed |
||
295 | * @throws ODataException |
||
296 | * @throws \POData\Common\InvalidOperationException |
||
297 | */ |
||
298 | private function createUpdateDeleteCore($sourceEntityInstance, $data, $class, $verb) |
||
334 | 1 | ||
335 | /** |
||
336 | * Puts an entity instance to entity set identified by a key. |
||
337 | * |
||
338 | * @param ResourceSet $resourceSet The entity set containing the entity to update |
||
339 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to update |
||
340 | * @param $data |
||
341 | * |
||
342 | * @return bool|null Returns result of executing query |
||
343 | 1 | */ |
|
344 | public function putResource( |
||
352 | |||
353 | 1 | /** |
|
354 | * @param ResourceSet $sourceResourceSet |
||
355 | 1 | * @param $sourceEntityInstance |
|
356 | * @param $data |
||
357 | * @param $verb |
||
358 | 1 | * @return mixed |
|
359 | * @throws ODataException |
||
360 | * @throws \POData\Common\InvalidOperationException |
||
361 | */ |
||
362 | private function createUpdateCoreWrapper(ResourceSet $sourceResourceSet, $sourceEntityInstance, $data, $verb) |
||
387 | |||
388 | 3 | /** |
|
389 | 2 | * @param $sourceEntityInstance |
|
390 | 2 | * @param $data |
|
391 | 3 | * @param $paramList |
|
392 | * @return array |
||
393 | */ |
||
394 | private function createUpdateDeleteProcessInput($sourceEntityInstance, $data, $paramList) |
||
415 | 2 | ||
416 | /** |
||
417 | * @param $result |
||
418 | 3 | * @return array|mixed |
|
419 | 3 | * @throws ODataException |
|
420 | */ |
||
421 | 3 | private function createUpdateDeleteProcessOutput($result) |
|
441 | } |
||
442 |