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 |
||
26 | 5 | class LaravelQuery implements IQueryProvider |
|
27 | { |
||
28 | protected $expression; |
||
29 | 5 | protected $auth; |
|
30 | 5 | protected $reader; |
|
31 | 5 | public $queryProviderClassName; |
|
32 | 5 | private $verbMap = []; |
|
33 | |||
34 | public function __construct(AuthInterface $auth = null) |
||
45 | |||
46 | /** |
||
47 | * Indicates if the QueryProvider can handle ordered paging, this means respecting order, skip, and top parameters |
||
48 | * If the query provider can not handle ordered paging, it must return the entire result set and POData will |
||
49 | * perform the ordering and paging |
||
50 | * |
||
51 | * @return Boolean True if the query provider can handle ordered paging, false if POData should perform the paging |
||
52 | */ |
||
53 | public function handlesOrderedPaging() |
||
57 | |||
58 | /** |
||
59 | * Gets the expression provider used by to compile OData expressions into expression used by this query provider. |
||
60 | * |
||
61 | * @return \POData\Providers\Expression\IExpressionProvider |
||
62 | */ |
||
63 | public function getExpressionProvider() |
||
67 | |||
68 | /** |
||
69 | * Gets the LaravelReadQuery instance used to handle read queries (repetitious, nyet?) |
||
70 | 3 | * |
|
71 | * @return LaravelReadQuery |
||
72 | */ |
||
73 | public function getReader() |
||
77 | |||
78 | /** |
||
79 | 3 | * Gets collection of entities belongs to an entity set |
|
80 | * IE: http://host/EntitySet |
||
81 | * http://host/EntitySet?$skip=10&$top=5&filter=Prop gt Value |
||
82 | 3 | * |
|
83 | 1 | * @param QueryType $queryType indicates if this is a query for a count, entities, or entities with a count |
|
84 | 1 | * @param ResourceSet $resourceSet The entity set containing the entities to fetch |
|
85 | * @param FilterInfo $filterInfo represents the $filter parameter of the OData query. NULL if no $filter specified |
||
86 | 3 | * @param null|InternalOrderByInfo $orderBy sorted order if we want to get the data in some specific order |
|
87 | 3 | * @param int $top number of records which need to be retrieved |
|
88 | 3 | * @param int $skip number of records which need to be skipped |
|
89 | * @param SkipTokenInfo|null $skipToken value indicating what records to skip |
||
90 | 3 | * @param Model|Relation|null $sourceEntityInstance Starting point of query |
|
91 | * |
||
92 | * @return QueryResult |
||
93 | */ |
||
94 | public function getResourceSet( |
||
115 | /** |
||
116 | * Gets an entity instance from an entity set identified by a key |
||
117 | 3 | * IE: http://host/EntitySet(1L) |
|
118 | 1 | * http://host/EntitySet(KeyA=2L,KeyB='someValue') |
|
119 | 1 | * |
|
120 | 1 | * @param ResourceSet $resourceSet The entity set containing the entity to fetch |
|
121 | 1 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to fetch |
|
122 | 1 | * |
|
123 | 3 | * @return object|null Returns entity instance if found else null |
|
124 | 3 | */ |
|
125 | public function getResourceFromResourceSet( |
||
131 | |||
132 | /** |
||
133 | * Get related resource set for a resource |
||
134 | * IE: http://host/EntitySet(1L)/NavigationPropertyToCollection |
||
135 | * http://host/EntitySet?$expand=NavigationPropertyToCollection |
||
136 | * |
||
137 | * @param QueryType $queryType indicates if this is a query for a count, entities, or entities with a count |
||
138 | * @param ResourceSet $sourceResourceSet The entity set containing the source entity |
||
139 | * @param object $sourceEntityInstance The source entity instance |
||
140 | * @param ResourceSet $targetResourceSet The resource set of containing the target of the navigation property |
||
141 | * @param ResourceProperty $targetProperty The navigation property to retrieve |
||
142 | * @param FilterInfo $filter represents the $filter parameter of the OData query. NULL if no $filter specified |
||
143 | * @param mixed $orderBy sorted order if we want to get the data in some specific order |
||
144 | * @param int $top number of records which need to be retrieved |
||
145 | * @param int $skip number of records which need to be skipped |
||
146 | * @param SkipTokenInfo|null $skipToken value indicating what records to skip |
||
147 | * |
||
148 | * @return QueryResult |
||
149 | * |
||
150 | */ |
||
151 | public function getRelatedResourceSet( |
||
176 | |||
177 | /** |
||
178 | * Gets a related entity instance from an entity set identified by a key |
||
179 | * IE: http://host/EntitySet(1L)/NavigationPropertyToCollection(33) |
||
180 | * |
||
181 | * @param ResourceSet $sourceResourceSet The entity set containing the source entity |
||
182 | * @param object $sourceEntityInstance The source entity instance. |
||
183 | * @param ResourceSet $targetResourceSet The entity set containing the entity to fetch |
||
184 | * @param ResourceProperty $targetProperty The metadata of the target property. |
||
185 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to fetch |
||
186 | * |
||
187 | * @return object|null Returns entity instance if found else null |
||
188 | */ |
||
189 | public function getResourceFromRelatedResourceSet( |
||
204 | |||
205 | /** |
||
206 | * Get related resource for a resource |
||
207 | * IE: http://host/EntitySet(1L)/NavigationPropertyToSingleEntity |
||
208 | * http://host/EntitySet?$expand=NavigationPropertyToSingleEntity |
||
209 | * |
||
210 | 3 | * @param ResourceSet $sourceResourceSet The entity set containing the source entity |
|
211 | 3 | * @param object $sourceEntityInstance The source entity instance. |
|
212 | * @param ResourceSet $targetResourceSet The entity set containing the entity pointed to by the navigation property |
||
213 | 3 | * @param ResourceProperty $targetProperty The navigation property to fetch |
|
214 | 3 | * |
|
215 | 3 | * @return object|null The related resource if found else null |
|
216 | 3 | */ |
|
217 | 3 | public function getRelatedResourceReference( |
|
231 | |||
232 | /** |
||
233 | * Updates a resource |
||
234 | * |
||
235 | * @param ResourceSet $sourceResourceSet The entity set containing the source entity |
||
236 | * @param object $sourceEntityInstance The source entity instance |
||
237 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to fetch |
||
238 | * @param object $data The New data for the entity instance. |
||
239 | * @param bool $shouldUpdate Should undefined values be updated or reset to default |
||
240 | * |
||
241 | * @return object|null The new resource value if it is assignable or throw exception for null. |
||
242 | */ |
||
243 | public function updateResource( |
||
253 | /** |
||
254 | * Delete resource from a resource set. |
||
255 | * @param ResourceSet|null $sourceResourceSet |
||
256 | * @param object $sourceEntityInstance |
||
257 | * |
||
258 | * return bool true if resources sucessfully deteled, otherwise false. |
||
259 | */ |
||
260 | public function deleteResource( |
||
282 | /** |
||
283 | * @param ResourceSet $resourceSet The entity set containing the entity to fetch |
||
284 | * @param object $sourceEntityInstance The source entity instance |
||
285 | * @param object $data The New data for the entity instance. |
||
286 | * |
||
287 | * returns object|null returns the newly created model if sucessful or null if model creation failed. |
||
288 | */ |
||
289 | public function createResourceforResourceSet( |
||
297 | |||
298 | /** |
||
299 | 1 | * @param $sourceEntityInstance |
|
300 | 1 | * @param $data |
|
301 | * @param $class |
||
302 | 1 | * @param string $verb |
|
303 | * @return array|mixed |
||
304 | 1 | * @throws ODataException |
|
305 | * @throws \POData\Common\InvalidOperationException |
||
306 | 1 | */ |
|
307 | private function createUpdateDeleteCore($sourceEntityInstance, $data, $class, $verb) |
||
343 | 1 | ||
344 | /** |
||
345 | * Puts an entity instance to entity set identified by a key. |
||
346 | * |
||
347 | * @param ResourceSet $resourceSet The entity set containing the entity to update |
||
348 | 1 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to update |
|
349 | 1 | * @param $data |
|
350 | * |
||
351 | 1 | * @return bool|null Returns result of executing query |
|
352 | */ |
||
353 | 1 | public function putResource( |
|
361 | |||
362 | /** |
||
363 | * @param ResourceSet $sourceResourceSet |
||
364 | * @param $sourceEntityInstance |
||
365 | * @param $data |
||
366 | * @param $verb |
||
367 | * @return mixed |
||
368 | * @throws ODataException |
||
369 | * @throws \POData\Common\InvalidOperationException |
||
370 | 3 | */ |
|
371 | private function createUpdateCoreWrapper(ResourceSet $sourceResourceSet, $sourceEntityInstance, $data, $verb) |
||
396 | |||
397 | 3 | /** |
|
398 | 3 | * @param $sourceEntityInstance |
|
399 | 3 | * @param $data |
|
400 | 3 | * @param $paramList |
|
401 | 3 | * @return array |
|
402 | */ |
||
403 | 3 | private function createUpdateDeleteProcessInput($sourceEntityInstance, $data, $paramList) |
|
424 | |||
425 | /** |
||
426 | 3 | * @param $result |
|
427 | 3 | * @return array|mixed |
|
428 | 3 | * @throws ODataException |
|
429 | 3 | */ |
|
430 | private function createUpdateDeleteProcessOutput($result) |
||
450 | } |
||
451 |