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 |
||
33 | class ProvidersWrapper |
||
34 | { |
||
35 | /** |
||
36 | * Holds reference to IMetadataProvider implementation. |
||
37 | * |
||
38 | * @var IMetadataProvider |
||
39 | */ |
||
40 | private $metaProvider; |
||
41 | |||
42 | /** |
||
43 | * Holds reference to IServiceConfiguration implementation. |
||
44 | * |
||
45 | * @var IServiceConfiguration |
||
46 | */ |
||
47 | private $config; |
||
48 | |||
49 | /* |
||
50 | * Holds reference to ProvidersQueryWrapper implementation |
||
51 | * |
||
52 | * @var ProvidersQueryWrapper |
||
53 | */ |
||
54 | private $providerWrapper; |
||
55 | |||
56 | /** |
||
57 | * Cache for ResourceProperties of a resource type that belongs to a |
||
58 | * resource set. An entry (ResourceProperty collection) in this cache |
||
59 | * contains only the visible properties of ResourceType. |
||
60 | * |
||
61 | * @var array(string, array(string, ResourceProperty)) |
||
62 | */ |
||
63 | private $propertyCache; |
||
64 | |||
65 | /** |
||
66 | * Cache for ResourceSetWrappers. If ResourceSet is invisible value will |
||
67 | * be null. |
||
68 | * |
||
69 | * @var ResourceSetWrapper[] indexed by resource set name |
||
70 | */ |
||
71 | private $setWrapperCache; |
||
72 | |||
73 | /** |
||
74 | * Cache for ResourceTypes. |
||
75 | * |
||
76 | * @var ResourceType[] indexed by resource type name |
||
77 | */ |
||
78 | private $typeCache; |
||
79 | |||
80 | /** |
||
81 | * Cache for ResourceAssociationSet. If ResourceAssociationSet is invisible |
||
82 | * value will be null. |
||
83 | * |
||
84 | * @var ResourceAssociationSet[] indexed by name |
||
85 | */ |
||
86 | private $associationSetCache; |
||
|
|||
87 | |||
88 | /** |
||
89 | * Creates a new instance of ProvidersWrapper. |
||
90 | * |
||
91 | * @param IMetadataProvider $meta Reference to IMetadataProvider implementation |
||
92 | * @param IQueryProvider $query Reference to IQueryProvider implementation |
||
93 | * @param IServiceConfiguration $config Reference to IServiceConfiguration implementation |
||
94 | */ |
||
95 | public function __construct(IMetadataProvider $meta, IQueryProvider $query, IServiceConfiguration $config) |
||
96 | { |
||
97 | $this->metaProvider = $meta; |
||
98 | $this->config = $config; |
||
99 | $this->providerWrapper = new ProvidersQueryWrapper($query); |
||
100 | $this->setWrapperCache = []; |
||
101 | $this->typeCache = []; |
||
102 | $this->propertyCache = []; |
||
103 | } |
||
104 | |||
105 | //Wrappers for IMetadataProvider methods |
||
106 | |||
107 | /** |
||
108 | * To get the Container name for the data source, |
||
109 | * Note: Wrapper for IMetadataProvider::getContainerName method |
||
110 | * implementation. |
||
111 | * |
||
112 | * @throws ODataException Exception if implementation returns empty container name |
||
113 | * |
||
114 | * @return string that contains the name of the container |
||
115 | */ |
||
116 | public function getContainerName() |
||
128 | |||
129 | /** |
||
130 | * To get Namespace name for the data source, |
||
131 | * Note: Wrapper for IMetadataProvider::getContainerNamespace method implementation. |
||
132 | * |
||
133 | * @throws ODataException Exception if implementation returns empty container namespace |
||
134 | * |
||
135 | * @return string that contains the namespace name |
||
136 | */ |
||
137 | public function getContainerNamespace() |
||
149 | |||
150 | /** |
||
151 | * To get the data service configuration. |
||
152 | * |
||
153 | * @return IServiceConfiguration |
||
154 | */ |
||
155 | public function getConfiguration() |
||
159 | |||
160 | /** |
||
161 | * To get all entity set information, |
||
162 | * Note: Wrapper for IMetadataProvider::getResourceSets method implementation, |
||
163 | * This method returns array of ResourceSetWrapper instances but the corresponding IDSMP method |
||
164 | * returns array of ResourceSet instances. |
||
165 | * |
||
166 | * @throws ODataException when two resource sets with the same name are encountered |
||
167 | * |
||
168 | * @return ResourceSetWrapper[] The ResourceSetWrappers for the visible ResourceSets |
||
169 | */ |
||
170 | public function getResourceSets() |
||
190 | |||
191 | /** |
||
192 | * This function perform the following operations |
||
193 | * (1) If the cache contain an entry [key, value] for the resourceset then |
||
194 | * return the entry-value |
||
195 | * (2) If the cache not contain an entry for the resourceset then validate |
||
196 | * the resourceset |
||
197 | * (a) If valid add entry as [resouceset_name, resourceSetWrapper] |
||
198 | * (b) if not valid add entry as [resouceset_name, null] |
||
199 | * Note: validating a resourceset means checking the resourceset is visible |
||
200 | * or not using configuration. |
||
201 | * |
||
202 | * @param ResourceSet $resourceSet The resourceset to validate and get the |
||
203 | * wrapper for |
||
204 | * |
||
205 | * @return ResourceSetWrapper|null Returns an instance if a resource set with the given name is visible |
||
206 | */ |
||
207 | private function _validateResourceSetAndGetWrapper(ResourceSet $resourceSet) |
||
221 | |||
222 | /** |
||
223 | * Validates the given instance of ResourceType. |
||
224 | * |
||
225 | * @param ResourceType $resourceType The ResourceType to validate |
||
226 | * |
||
227 | * @throws ODataException Exception if $resourceType is invalid |
||
228 | * |
||
229 | * @return ResourceType |
||
230 | */ |
||
231 | private function validateResourceType(ResourceType $resourceType) |
||
243 | |||
244 | /** |
||
245 | * To get all resource types in the data source, |
||
246 | * Note: Wrapper for IMetadataProvider::getTypes method implementation. |
||
247 | * |
||
248 | * @return ResourceType[] |
||
249 | */ |
||
250 | public function getTypes() |
||
268 | |||
269 | public function getSingletons() |
||
274 | |||
275 | /** |
||
276 | * To get a resource set based on the specified resource set name which is |
||
277 | * visible, |
||
278 | * Note: Wrapper for IMetadataProvider::resolveResourceSet method |
||
279 | * implementation. |
||
280 | * |
||
281 | * @param string $name Name of the resource set |
||
282 | * |
||
283 | * @return ResourceSetWrapper|null Returns resource set with the given name if found, |
||
284 | * NULL if resource set is set to invisible or not found |
||
285 | */ |
||
286 | public function resolveResourceSet($name) |
||
299 | |||
300 | /** |
||
301 | * To get a resource type based on the resource set name, |
||
302 | * Note: Wrapper for IMetadataProvider::resolveResourceType |
||
303 | * method implementation. |
||
304 | * |
||
305 | * @param string $name Name of the resource set |
||
306 | * |
||
307 | * @throws ODataException If the ResourceType is invalid |
||
308 | * |
||
309 | * @return ResourceType|null resource type with the given resource set name if found else NULL |
||
310 | */ |
||
311 | public function resolveResourceType($name) |
||
320 | |||
321 | |||
322 | public function resolveSingleton($name) |
||
330 | |||
331 | /** |
||
332 | * The method must return a collection of all the types derived from |
||
333 | * $resourceType The collection returned should NOT include the type |
||
334 | * passed in as a parameter |
||
335 | * Note: Wrapper for IMetadataProvider::getDerivedTypes |
||
336 | * method implementation. |
||
337 | * |
||
338 | * @param ResourceType $resourceType Resource to get derived resource types from |
||
339 | * |
||
340 | * @throws InvalidOperationException when the meat provider doesn't return an array |
||
341 | * |
||
342 | * @return ResourceType[] |
||
343 | */ |
||
344 | public function getDerivedTypes(ResourceType $resourceType) |
||
359 | |||
360 | /** |
||
361 | * Returns true if $resourceType represents an Entity Type which has derived |
||
362 | * Entity Types, else false. |
||
363 | * Note: Wrapper for IMetadataProvider::hasDerivedTypes method |
||
364 | * implementation. |
||
365 | * |
||
366 | * @param ResourceType $resourceType Resource to check for derived resource |
||
367 | * types |
||
368 | * |
||
369 | * @throws ODataException If the ResourceType is invalid |
||
370 | * |
||
371 | * @return bool |
||
372 | */ |
||
373 | public function hasDerivedTypes(ResourceType $resourceType) |
||
379 | |||
380 | /** |
||
381 | * Gets the visible resource properties for the given resource type from the given resource set wrapper. |
||
382 | * |
||
383 | * @param ResourceSetWrapper $setWrapper Resource set wrapper in question |
||
384 | * @param ResourceType $resourceType Resource type in question |
||
385 | * |
||
386 | * @return ResourceProperty[] Collection of visible resource properties from the given resource set wrapper |
||
387 | * and resource type |
||
388 | */ |
||
389 | public function getResourceProperties(ResourceSetWrapper $setWrapper, ResourceType $resourceType) |
||
420 | |||
421 | /** |
||
422 | * Gets the target resource set wrapper for the given navigation property, |
||
423 | * source resource set wrapper and the source resource type. |
||
424 | * |
||
425 | * @param ResourceSetWrapper $resourceSetWrapper Source resource set |
||
426 | * @param ResourceEntityType $resourceType Source resource type |
||
427 | * @param ResourceProperty $navigationResourceProperty Navigation property |
||
428 | * |
||
429 | * @return ResourceSetWrapper|null Returns instance of ResourceSetWrapper |
||
430 | * (describes the entity set and associated configuration) for the |
||
431 | * given navigation property. returns NULL if resourceset for the |
||
432 | * navigation property is invisible or if metadata provider returns |
||
433 | * null resource association set |
||
434 | */ |
||
435 | public function getResourceSetWrapperForNavigationProperty( |
||
459 | |||
460 | /** |
||
461 | * Gets the ResourceAssociationSet instance for the given source association end, |
||
462 | * Note: Wrapper for IMetadataProvider::getResourceAssociationSet |
||
463 | * method implementation. |
||
464 | * |
||
465 | * @param ResourceSet $set Resource set of the source association end |
||
466 | * @param ResourceEntityType $type Resource type of the source association end |
||
467 | * @param ResourceProperty $property Resource property of the source association end |
||
468 | * |
||
469 | * @return ResourceAssociationSet|null Returns ResourceAssociationSet for the source |
||
470 | * association end, NULL if no such |
||
471 | * association end or resource set in the |
||
472 | * other end of the association is invisible |
||
473 | */ |
||
474 | public function getResourceAssociationSet( |
||
540 | |||
541 | /** |
||
542 | * Gets the resource type on which the resource property is declared on, |
||
543 | * If property is not declared in the given resource type, then this |
||
544 | * function drill down to the inheritance hierarchy of the given resource |
||
545 | * type to find out the base class in which the property is declared. |
||
546 | * |
||
547 | * @param ResourceType $type The resource type to start looking |
||
548 | * @param ResourceProperty $property The resource property in question |
||
549 | * |
||
550 | * @return ResourceType|null Returns reference to the ResourceType on which |
||
551 | * the $property is declared, NULL if |
||
552 | * $property is not declared anywhere |
||
553 | * in the inheritance hierarchy |
||
554 | */ |
||
555 | private function getResourceTypeWherePropertyIsDeclared(ResourceType $type, ResourceProperty $property) |
||
567 | |||
568 | /** |
||
569 | * Wrapper function over _validateResourceSetAndGetWrapper function. |
||
570 | * |
||
571 | * @param ResourceSet $resourceSet see the comments of _validateResourceSetAndGetWrapper |
||
572 | * |
||
573 | * @return ResourceSetWrapper|null see the comments of _validateResourceSetAndGetWrapper |
||
574 | */ |
||
575 | public function validateResourceSetAndGetWrapper(ResourceSet $resourceSet) |
||
579 | |||
580 | /** |
||
581 | * Gets the Edm Schema version compliance to the metadata. |
||
582 | * |
||
583 | * @return EdmSchemaVersion |
||
584 | */ |
||
585 | public function getEdmSchemaVersion() |
||
590 | |||
591 | /** |
||
592 | * Gets the underlying custom expression provider, the end developer is |
||
593 | * responsible for implementing IExpressionProvider if he choose for. |
||
594 | * |
||
595 | * @return IExpressionProvider Instance of IExpressionProvider implementation |
||
596 | */ |
||
597 | public function getExpressionProvider() |
||
601 | |||
602 | /** |
||
603 | * Indicates if the QueryProvider can handle ordered paging, this means respecting order, skip, and top parameters |
||
604 | * If the query provider can not handle ordered paging, it must return the entire result set and POData will |
||
605 | * perform the ordering and paging. |
||
606 | * |
||
607 | * @return bool True if the query provider can handle ordered paging, false if POData should perform the paging |
||
608 | */ |
||
609 | public function handlesOrderedPaging() |
||
613 | |||
614 | /** |
||
615 | * Gets collection of entities belongs to an entity set. |
||
616 | * |
||
617 | * @param QueryType $queryType Indicates if this is a query for a count, entities, or entities with a |
||
618 | * count |
||
619 | * @param ResourceSet $resourceSet The entity set containing the entities that need to be fetched |
||
620 | * @param FilterInfo $filterInfo Represents the $filter parameter of the OData query. |
||
621 | * NULL if no $filter specified |
||
622 | * @param InternalOrderByInfo $orderBy The orderBy information |
||
623 | * @param int $top The top count |
||
624 | * @param int $skip The skip count |
||
625 | * @param InternalSkipTokenInfo $skipToken The skip token |
||
626 | * |
||
627 | * @return QueryResult |
||
628 | */ |
||
629 | public function getResourceSet( |
||
648 | |||
649 | /** |
||
650 | * Gets an entity instance from an entity set identified by a key. |
||
651 | * |
||
652 | * @param ResourceSet $resourceSet The entity set containing the entity to fetch |
||
653 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to fetch |
||
654 | * |
||
655 | * @return object|null Returns entity instance if found else null |
||
656 | */ |
||
657 | public function getResourceFromResourceSet(ResourceSet $resourceSet, KeyDescriptor $keyDescriptor) |
||
661 | |||
662 | /** |
||
663 | * Puts an entity instance to entity set identified by a key. |
||
664 | * |
||
665 | * @param ResourceSet $resourceSet The entity set containing the entity to update |
||
666 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to update |
||
667 | * |
||
668 | * @return bool|null Returns result of executiong query |
||
669 | */ |
||
670 | public function putResource( |
||
681 | |||
682 | /** |
||
683 | * Get related resource set for a resource. |
||
684 | * |
||
685 | * @param QueryType $queryType Indicates if this is a query for a count, entities, or entities |
||
686 | * with a count |
||
687 | * @param ResourceSet $sourceResourceSet The entity set containing the source entity |
||
688 | * @param object $sourceEntity The source entity instance |
||
689 | * @param ResourceSet $targetResourceSet The resource set of containing the target of the navigation property |
||
690 | * @param ResourceProperty $targetProperty The navigation property to retrieve |
||
691 | * @param FilterInfo|null $filterInfo Represents the $filter parameter of the OData query. |
||
692 | * NULL if no $filter specified |
||
693 | * @param mixed $orderBy sorted order if we want to get the data in some specific order |
||
694 | * @param int $top number of records which need to be skip |
||
695 | * @param string $skip value indicating what records to skip |
||
696 | * |
||
697 | * @throws ODataException |
||
698 | * |
||
699 | * @return QueryResult |
||
700 | */ |
||
701 | public function getRelatedResourceSet( |
||
724 | |||
725 | /** |
||
726 | * Gets a related entity instance from an entity set identified by a key. |
||
727 | * |
||
728 | * @param ResourceSet $sourceResourceSet The entity set related to the entity to be fetched |
||
729 | * @param object $sourceEntity The related entity instance |
||
730 | * @param ResourceSet $targetResourceSet The entity set from which entity needs to be fetched |
||
731 | * @param ResourceProperty $targetProperty The metadata of the target property |
||
732 | * @param KeyDescriptor $keyDescriptor The key to identify the entity to be fetched |
||
733 | * |
||
734 | * @return object|null Returns entity instance if found else null |
||
735 | */ |
||
736 | public function getResourceFromRelatedResourceSet( |
||
751 | |||
752 | /** |
||
753 | * Get related resource for a resource. |
||
754 | * |
||
755 | * @param ResourceSet $sourceResourceSet The source resource set |
||
756 | * @param object $sourceEntity The source resource |
||
757 | * @param ResourceSet $targetResourceSet The resource set of the navigation |
||
758 | * property |
||
759 | * @param ResourceProperty $targetProperty The navigation property to be |
||
760 | * retrieved |
||
761 | * |
||
762 | * @return object|null The related resource if exists else null |
||
763 | */ |
||
764 | public function getRelatedResourceReference( |
||
777 | |||
778 | /** |
||
779 | * Updates a resource. |
||
780 | * |
||
781 | * @param ResourceSet $sourceResourceSet The entity set containing the source entity |
||
782 | * @param object $sourceEntityInstance The source entity instance |
||
783 | * @param KeyDescriptor $keyDescriptor The key identifying the entity to fetch |
||
784 | * @param object $data The New data for the entity instance. |
||
785 | * @param bool $shouldUpdate Should undefined values be updated or reset to default |
||
786 | * |
||
787 | * @return object|null The new resource value if it is assignable or throw exception for null. |
||
788 | */ |
||
789 | public function updateResource( |
||
804 | |||
805 | /** |
||
806 | * Delete resource from a resource set. |
||
807 | * |
||
808 | * @param ResourceSet $sourceResourceSet |
||
809 | * @param object $sourceEntityInstance |
||
810 | * |
||
811 | * return bool true if resources sucessfully deteled, otherwise false. |
||
812 | */ |
||
813 | public function deleteResource( |
||
822 | |||
823 | /** |
||
824 | * @param ResourceSet $resourceSet The entity set containing the entity to fetch |
||
825 | * @param object $sourceEntityInstance The source entity instance |
||
826 | * @param object $data The New data for the entity instance. |
||
827 | * |
||
828 | * returns object|null returns the newly created model if sucessful or null if model creation failed. |
||
829 | */ |
||
830 | public function createResourceforResourceSet( |
||
841 | |||
842 | public function getMetadataXML() |
||
846 | } |
||
847 |
This check marks private properties in classes that are never used. Those properties can be removed.