Complex classes like ProvidersWrapper 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 ProvidersWrapper, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
34 | class ProvidersWrapper |
||
35 | { |
||
36 | /** |
||
37 | * Holds reference to IMetadataProvider implementation. |
||
38 | * |
||
39 | * @var IMetadataProvider |
||
40 | */ |
||
41 | private $metaProvider; |
||
42 | |||
43 | /** |
||
44 | * Holds reference to IServiceConfiguration implementation. |
||
45 | * |
||
46 | * @var IServiceConfiguration |
||
47 | */ |
||
48 | private $config; |
||
49 | |||
50 | /* |
||
51 | * Holds reference to ProvidersQueryWrapper implementation |
||
52 | * |
||
53 | * @var ProvidersQueryWrapper |
||
54 | */ |
||
55 | private $providerWrapper; |
||
56 | |||
57 | /** |
||
58 | * Cache for ResourceProperties of a resource type that belongs to a |
||
59 | * resource set. An entry (ResourceProperty collection) in this cache |
||
60 | * contains only the visible properties of ResourceType. |
||
61 | * |
||
62 | * @var array(string, array(string, ResourceProperty)) |
||
63 | */ |
||
64 | private $propertyCache; |
||
65 | |||
66 | /** |
||
67 | * Cache for ResourceSetWrappers. If ResourceSet is invisible value will |
||
68 | * be null. |
||
69 | * |
||
70 | * @var ResourceSetWrapper[] indexed by resource set name |
||
71 | */ |
||
72 | private $setWrapperCache; |
||
73 | |||
74 | /** |
||
75 | * Cache for ResourceTypes. |
||
76 | * |
||
77 | * @var ResourceType[] indexed by resource type name |
||
78 | */ |
||
79 | private $typeCache; |
||
80 | |||
81 | /** |
||
82 | * Cache for ResourceAssociationSet. If ResourceAssociationSet is invisible |
||
83 | * value will be null. |
||
84 | * |
||
85 | * @var ResourceAssociationSet[] indexed by name |
||
86 | */ |
||
87 | private $associationSetCache; |
||
|
|||
88 | |||
89 | /** |
||
90 | * Creates a new instance of ProvidersWrapper. |
||
91 | * |
||
92 | * @param IMetadataProvider $meta Reference to IMetadataProvider implementation |
||
93 | * @param IQueryProvider $query Reference to IQueryProvider implementation |
||
94 | * @param IServiceConfiguration $config Reference to IServiceConfiguration implementation |
||
95 | */ |
||
96 | public function __construct(IMetadataProvider $meta, IQueryProvider $query, IServiceConfiguration $config) |
||
105 | |||
106 | public function getProviderWrapper() |
||
111 | |||
112 | //Wrappers for IMetadataProvider methods |
||
113 | |||
114 | /** |
||
115 | * To get the Container name for the data source, |
||
116 | * Note: Wrapper for IMetadataProvider::getContainerName method |
||
117 | * implementation. |
||
118 | * |
||
119 | * @throws ODataException Exception if implementation returns empty container name |
||
120 | * |
||
121 | * @return string that contains the name of the container |
||
122 | */ |
||
123 | public function getContainerName() |
||
135 | |||
136 | /** |
||
137 | * To get Namespace name for the data source, |
||
138 | * Note: Wrapper for IMetadataProvider::getContainerNamespace method implementation. |
||
139 | * |
||
140 | * @throws ODataException Exception if implementation returns empty container namespace |
||
141 | * |
||
142 | * @return string that contains the namespace name |
||
143 | */ |
||
144 | public function getContainerNamespace() |
||
156 | |||
157 | /** |
||
158 | * To get the data service configuration. |
||
159 | * |
||
160 | * @return IServiceConfiguration |
||
161 | */ |
||
162 | public function getConfiguration() |
||
166 | |||
167 | /** |
||
168 | * To get all entity set information, |
||
169 | * Note: Wrapper for IMetadataProvider::getResourceSets method implementation, |
||
170 | * This method returns array of ResourceSetWrapper instances but the corresponding IDSMP method |
||
171 | * returns array of ResourceSet instances. |
||
172 | * |
||
173 | * @throws ODataException when two resource sets with the same name are encountered |
||
174 | * |
||
175 | * @return ResourceSetWrapper[] The ResourceSetWrappers for the visible ResourceSets |
||
176 | */ |
||
177 | public function getResourceSets() |
||
197 | |||
198 | /** |
||
199 | * This function perform the following operations |
||
200 | * (1) If the cache contain an entry [key, value] for the resourceset then |
||
201 | * return the entry-value |
||
202 | * (2) If the cache not contain an entry for the resourceset then validate |
||
203 | * the resourceset |
||
204 | * (a) If valid add entry as [resouceset_name, resourceSetWrapper] |
||
205 | * (b) if not valid add entry as [resouceset_name, null] |
||
206 | * Note: validating a resourceset means checking the resourceset is visible |
||
207 | * or not using configuration. |
||
208 | * |
||
209 | * @param ResourceSet $resourceSet The resourceset to validate and get the |
||
210 | * wrapper for |
||
211 | * |
||
212 | * @return ResourceSetWrapper|null Returns an instance if a resource set with the given name is visible |
||
213 | */ |
||
214 | private function _validateResourceSetAndGetWrapper(ResourceSet $resourceSet) |
||
228 | |||
229 | /** |
||
230 | * Validates the given instance of ResourceType. |
||
231 | * |
||
232 | * @param ResourceType $resourceType The ResourceType to validate |
||
233 | * |
||
234 | * @throws ODataException Exception if $resourceType is invalid |
||
235 | * |
||
236 | * @return ResourceType |
||
237 | */ |
||
238 | private function validateResourceType(ResourceType $resourceType) |
||
250 | |||
251 | /** |
||
252 | * To get all resource types in the data source, |
||
253 | * Note: Wrapper for IMetadataProvider::getTypes method implementation. |
||
254 | * |
||
255 | * @return ResourceType[] |
||
256 | */ |
||
257 | public function getTypes() |
||
275 | |||
276 | public function getSingletons() |
||
281 | |||
282 | /** |
||
283 | * To get a resource set based on the specified resource set name which is |
||
284 | * visible, |
||
285 | * Note: Wrapper for IMetadataProvider::resolveResourceSet method |
||
286 | * implementation. |
||
287 | * |
||
288 | * @param string $name Name of the resource set |
||
289 | * |
||
290 | * @return ResourceSetWrapper|null Returns resource set with the given name if found, |
||
291 | * NULL if resource set is set to invisible or not found |
||
292 | */ |
||
293 | public function resolveResourceSet($name) |
||
306 | |||
307 | /** |
||
308 | * To get a resource type based on the resource set name, |
||
309 | * Note: Wrapper for IMetadataProvider::resolveResourceType |
||
310 | * method implementation. |
||
311 | * |
||
312 | * @param string $name Name of the resource set |
||
313 | * |
||
314 | * @throws ODataException If the ResourceType is invalid |
||
315 | * |
||
316 | * @return ResourceType|null resource type with the given resource set name if found else NULL |
||
317 | */ |
||
318 | public function resolveResourceType($name) |
||
327 | |||
328 | |||
329 | public function resolveSingleton($name) |
||
337 | |||
338 | /** |
||
339 | * The method must return a collection of all the types derived from |
||
340 | * $resourceType The collection returned should NOT include the type |
||
341 | * passed in as a parameter |
||
342 | * Note: Wrapper for IMetadataProvider::getDerivedTypes |
||
343 | * method implementation. |
||
344 | * |
||
345 | * @param ResourceType $resourceType Resource to get derived resource types from |
||
346 | * |
||
347 | * @throws InvalidOperationException when the meat provider doesn't return an array |
||
348 | * |
||
349 | * @return ResourceType[] |
||
350 | */ |
||
351 | public function getDerivedTypes(ResourceType $resourceType) |
||
366 | |||
367 | /** |
||
368 | * Returns true if $resourceType represents an Entity Type which has derived |
||
369 | * Entity Types, else false. |
||
370 | * Note: Wrapper for IMetadataProvider::hasDerivedTypes method |
||
371 | * implementation. |
||
372 | * |
||
373 | * @param ResourceType $resourceType Resource to check for derived resource |
||
374 | * types |
||
375 | * |
||
376 | * @throws ODataException If the ResourceType is invalid |
||
377 | * |
||
378 | * @return bool |
||
379 | */ |
||
380 | public function hasDerivedTypes(ResourceType $resourceType) |
||
386 | |||
387 | /** |
||
388 | * Gets the visible resource properties for the given resource type from the given resource set wrapper. |
||
389 | * |
||
390 | * @param ResourceSetWrapper $setWrapper Resource set wrapper in question |
||
391 | * @param ResourceType $resourceType Resource type in question |
||
392 | * |
||
393 | * @return ResourceProperty[] Collection of visible resource properties from the given resource set wrapper |
||
394 | * and resource type |
||
395 | */ |
||
396 | public function getResourceProperties(ResourceSetWrapper $setWrapper, ResourceType $resourceType) |
||
427 | |||
428 | /** |
||
429 | * Gets the target resource set wrapper for the given navigation property, |
||
430 | * source resource set wrapper and the source resource type. |
||
431 | * |
||
432 | * @param ResourceSetWrapper $resourceSetWrapper Source resource set |
||
433 | * @param ResourceEntityType $resourceType Source resource type |
||
434 | * @param ResourceProperty $navigationResourceProperty Navigation property |
||
435 | * |
||
436 | * @return ResourceSetWrapper|null Returns instance of ResourceSetWrapper |
||
437 | * (describes the entity set and associated configuration) for the |
||
438 | * given navigation property. returns NULL if resourceset for the |
||
439 | * navigation property is invisible or if metadata provider returns |
||
440 | * null resource association set |
||
441 | */ |
||
442 | public function getResourceSetWrapperForNavigationProperty( |
||
466 | |||
467 | /** |
||
468 | * Gets the ResourceAssociationSet instance for the given source association end, |
||
469 | * Note: Wrapper for IMetadataProvider::getResourceAssociationSet |
||
470 | * method implementation. |
||
471 | * |
||
472 | * @param ResourceSet $set Resource set of the source association end |
||
473 | * @param ResourceEntityType $type Resource type of the source association end |
||
474 | * @param ResourceProperty $property Resource property of the source association end |
||
475 | * |
||
476 | * @return ResourceAssociationSet|null Returns ResourceAssociationSet for the source |
||
477 | * association end, NULL if no such |
||
478 | * association end or resource set in the |
||
479 | * other end of the association is invisible |
||
480 | */ |
||
481 | public function getResourceAssociationSet( |
||
547 | |||
548 | /** |
||
549 | * Gets the resource type on which the resource property is declared on, |
||
550 | * If property is not declared in the given resource type, then this |
||
551 | * function drill down to the inheritance hierarchy of the given resource |
||
552 | * type to find out the base class in which the property is declared. |
||
553 | * |
||
554 | * @param ResourceType $type The resource type to start looking |
||
555 | * @param ResourceProperty $property The resource property in question |
||
556 | * |
||
557 | * @return ResourceType|null Returns reference to the ResourceType on which |
||
558 | * the $property is declared, NULL if |
||
559 | * $property is not declared anywhere |
||
560 | * in the inheritance hierarchy |
||
561 | */ |
||
562 | private function getResourceTypeWherePropertyIsDeclared(ResourceType $type, ResourceProperty $property) |
||
574 | |||
575 | /** |
||
576 | * Wrapper function over _validateResourceSetAndGetWrapper function. |
||
577 | * |
||
578 | * @param ResourceSet $resourceSet see the comments of _validateResourceSetAndGetWrapper |
||
579 | * |
||
580 | * @return ResourceSetWrapper|null see the comments of _validateResourceSetAndGetWrapper |
||
581 | */ |
||
582 | public function validateResourceSetAndGetWrapper(ResourceSet $resourceSet) |
||
586 | |||
587 | /** |
||
588 | * Gets the Edm Schema version compliance to the metadata. |
||
589 | * |
||
590 | * @return EdmSchemaVersion |
||
591 | */ |
||
592 | public function getEdmSchemaVersion() |
||
597 | |||
598 | /** |
||
599 | * Gets the underlying custom expression provider, the end developer is |
||
600 | * responsible for implementing IExpressionProvider if he choose for. |
||
601 | * |
||
602 | * @return IExpressionProvider Instance of IExpressionProvider implementation |
||
603 | */ |
||
604 | public function getExpressionProvider() |
||
608 | |||
609 | /** |
||
610 | * Indicates if the QueryProvider can handle ordered paging, this means respecting order, skip, and top parameters |
||
611 | * If the query provider can not handle ordered paging, it must return the entire result set and POData will |
||
612 | * perform the ordering and paging. |
||
613 | * |
||
614 | * @return bool True if the query provider can handle ordered paging, false if POData should perform the paging |
||
615 | */ |
||
616 | public function handlesOrderedPaging() |
||
620 | |||
621 | /** |
||
622 | * Gets collection of entities belongs to an entity set. |
||
623 | * |
||
624 | * @param QueryType $queryType Indicates if this is a query for a count, entities, or entities with a |
||
625 | * count |
||
626 | * @param ResourceSet $resourceSet The entity set containing the entities that need to be fetched |
||
627 | * @param FilterInfo $filterInfo Represents the $filter parameter of the OData query. |
||
628 | * NULL if no $filter specified |
||
629 | * @param InternalOrderByInfo $orderBy The orderBy information |
||
630 | * @param int $top The top count |
||
631 | * @param int $skip The skip count |
||
632 | * @param InternalSkipTokenInfo $skipToken The skip token |
||
633 | * |
||
634 | * @return QueryResult |
||
635 | */ |
||
636 | public function getResourceSet( |
||
655 | |||
656 | /** |
||
657 | * Gets an entity instance from an entity set identified by a key. |
||
658 | * |
||
659 | * @param ResourceSet $resourceSet The entity set containing the entity to fetch |
||
660 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to fetch |
||
661 | * |
||
662 | * @return object|null Returns entity instance if found else null |
||
663 | */ |
||
664 | public function getResourceFromResourceSet(ResourceSet $resourceSet, KeyDescriptor $keyDescriptor) |
||
668 | |||
669 | /** |
||
670 | * Puts an entity instance to entity set identified by a key. |
||
671 | * |
||
672 | * @param ResourceSet $resourceSet The entity set containing the entity to update |
||
673 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to update |
||
674 | * |
||
675 | * @return bool|null Returns result of executiong query |
||
676 | */ |
||
677 | public function putResource( |
||
688 | |||
689 | /** |
||
690 | * Get related resource set for a resource. |
||
691 | * |
||
692 | * @param QueryType $queryType Indicates if this is a query for a count, entities, or entities |
||
693 | * with a count |
||
694 | * @param ResourceSet $sourceResourceSet The entity set containing the source entity |
||
695 | * @param object $sourceEntity The source entity instance |
||
696 | * @param ResourceSet $targetResourceSet The resource set containing the target of the navigation property |
||
697 | * @param ResourceProperty $targetProperty The navigation property to retrieve |
||
698 | * @param FilterInfo|null $filterInfo Represents the $filter parameter of the OData query. |
||
699 | * NULL if no $filter specified |
||
700 | * @param mixed $orderBy sorted order if we want to get the data in some specific order |
||
701 | * @param int $top number of records which need to be retrieved |
||
702 | * @param int $skip number of records which need to be skipped |
||
703 | * @param SkipTokenInfo|null $skipToken value indicating what records to skip |
||
704 | * |
||
705 | * @throws ODataException |
||
706 | * |
||
707 | * @return QueryResult |
||
708 | */ |
||
709 | public function getRelatedResourceSet( |
||
734 | |||
735 | /** |
||
736 | * Gets a related entity instance from an entity set identified by a key. |
||
737 | * |
||
738 | * @param ResourceSet $sourceResourceSet The entity set related to the entity to be fetched |
||
739 | * @param object $sourceEntity The related entity instance |
||
740 | * @param ResourceSet $targetResourceSet The entity set from which entity needs to be fetched |
||
741 | * @param ResourceProperty $targetProperty The metadata of the target property |
||
742 | * @param KeyDescriptor $keyDescriptor The key to identify the entity to be fetched |
||
743 | * |
||
744 | * @return object|null Returns entity instance if found else null |
||
745 | */ |
||
746 | public function getResourceFromRelatedResourceSet( |
||
761 | |||
762 | /** |
||
763 | * Get related resource for a resource. |
||
764 | * |
||
765 | * @param ResourceSet $sourceResourceSet The source resource set |
||
766 | * @param object $sourceEntity The source resource |
||
767 | * @param ResourceSet $targetResourceSet The resource set of the navigation |
||
768 | * property |
||
769 | * @param ResourceProperty $targetProperty The navigation property to be |
||
770 | * retrieved |
||
771 | * |
||
772 | * @return object|null The related resource if exists else null |
||
773 | */ |
||
774 | public function getRelatedResourceReference( |
||
787 | |||
788 | /** |
||
789 | * Updates a resource. |
||
790 | * |
||
791 | * @param ResourceSet $sourceResourceSet The entity set containing the source entity |
||
792 | * @param object $sourceEntityInstance The source entity instance |
||
793 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to fetch |
||
794 | * @param object $data The New data for the entity instance. |
||
795 | * @param bool $shouldUpdate Should undefined values be updated or reset to default |
||
796 | * |
||
797 | * @return object|null The new resource value if it is assignable or throw exception for null. |
||
798 | */ |
||
799 | public function updateResource( |
||
814 | |||
815 | /** |
||
816 | * Delete resource from a resource set. |
||
817 | * |
||
818 | * @param ResourceSet $sourceResourceSet |
||
819 | * @param object $sourceEntityInstance |
||
820 | * |
||
821 | * return bool true if resources sucessfully deteled, otherwise false. |
||
822 | */ |
||
823 | public function deleteResource( |
||
832 | |||
833 | /** |
||
834 | * @param ResourceSet $resourceSet The entity set containing the entity to fetch |
||
835 | * @param object $sourceEntityInstance The source entity instance |
||
836 | * @param object $data The New data for the entity instance. |
||
837 | * |
||
838 | * returns object|null returns the newly created model if sucessful or null if model creation failed. |
||
839 | */ |
||
840 | public function createResourceforResourceSet( |
||
851 | |||
852 | public function getMetadataXML() |
||
856 | } |
||
857 |
This check marks private properties in classes that are never used. Those properties can be removed.