Complex classes like ExpandProjectionParser 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 ExpandProjectionParser, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
34 | class ExpandProjectionParser |
||
|
|||
35 | { |
||
36 | /** |
||
37 | * The wrapper of IMetadataProvider and IQueryProvider |
||
38 | * . |
||
39 | * |
||
40 | * @var ProvidersWrapper |
||
41 | */ |
||
42 | private $providerWrapper; |
||
43 | |||
44 | /** |
||
45 | * Holds reference to the root of 'Projection Tree'. |
||
46 | * |
||
47 | * @var RootProjectionNode |
||
48 | */ |
||
49 | private $rootProjectionNode; |
||
50 | |||
51 | /** |
||
52 | * Creates new instance of ExpandProjectionParser. |
||
53 | * |
||
54 | * @param ProvidersWrapper $providerWrapper Reference to metadata and query provider wrapper |
||
55 | */ |
||
56 | private function __construct(ProvidersWrapper $providerWrapper) |
||
60 | |||
61 | /** |
||
62 | * Parse the given expand and select clause, validate them |
||
63 | * and build 'Projection Tree'. |
||
64 | * |
||
65 | * @param ResourceSetWrapper $resourceSetWrapper The resource set identified by the resource path uri |
||
66 | * @param ResourceType $resourceType The resource type of entities identified by the resource path uri |
||
67 | * @param InternalOrderByInfo $internalOrderInfo The top level sort information, this will be set if the $skip, $top is |
||
68 | * specified in the |
||
69 | * request uri or Server |
||
70 | * side paging is |
||
71 | * enabled for top level |
||
72 | * resource |
||
73 | * @param int $skipCount The value of $skip option applied to the top level resource |
||
74 | * set identified by the |
||
75 | * resource path uri |
||
76 | * null means $skip |
||
77 | * option is not present |
||
78 | * @param int $takeCount The minimum among the value of $top option applied to and |
||
79 | * page size configured |
||
80 | * for the top level |
||
81 | * resource |
||
82 | * set identified |
||
83 | * by the resource |
||
84 | * path uri. |
||
85 | * null means $top option |
||
86 | * is not present and/or |
||
87 | * page size is not |
||
88 | * configured for top |
||
89 | * level resource set |
||
90 | * @param string $expand The value of $expand clause |
||
91 | * @param string $select The value of $select clause |
||
92 | * @param ProvidersWrapper $providerWrapper Reference to metadata and query provider wrapper |
||
93 | * |
||
94 | * @throws ODataException If any error occur while parsing expand and/or select clause |
||
95 | * |
||
96 | * @return RootProjectionNode Returns root of the 'Projection Tree' |
||
97 | */ |
||
98 | public static function parseExpandAndSelectClause( |
||
122 | |||
123 | /** |
||
124 | * Read the given expand clause and build 'Projection Tree', |
||
125 | * do nothing if the clause is null. |
||
126 | * |
||
127 | * @param string $expand Value of $expand clause |
||
128 | * |
||
129 | * @throws ODataException If any error occurs while reading expand clause |
||
130 | * or building the projection tree |
||
131 | */ |
||
132 | private function parseExpand($expand) |
||
140 | |||
141 | /** |
||
142 | * Read the given select clause and apply selection to the |
||
143 | * 'Projection Tree', mark the entire tree as selected if this |
||
144 | * clause is null |
||
145 | * Note: _parseExpand should to be called before the invocation |
||
146 | * of this function so that basic 'Projection Tree' with expand |
||
147 | * information will be ready. |
||
148 | * |
||
149 | * @param string $select Value of $select clause |
||
150 | * |
||
151 | * @throws ODataException If any error occurs while reading expand clause |
||
152 | * or applying selection to projection tree |
||
153 | */ |
||
154 | private function parseSelect($select) |
||
168 | |||
169 | /** |
||
170 | * Build 'Projection Tree' from the given expand path segments. |
||
171 | * |
||
172 | * @param array<array> $expandPathSegments Collection of expand paths |
||
173 | * |
||
174 | * @throws ODataException If any error occurs while processing the expand path segments |
||
175 | */ |
||
176 | private function buildProjectionTree($expandPathSegments) |
||
267 | |||
268 | /** |
||
269 | * Modify the 'Projection Tree' to include selection details. |
||
270 | * |
||
271 | * @param array<array<string>> $selectPathSegments Collection of select |
||
272 | * paths |
||
273 | * |
||
274 | * @throws ODataException If any error occurs while processing select |
||
275 | * path segments |
||
276 | */ |
||
277 | private function applySelectionToProjectionTree($selectPathSegments) |
||
368 | |||
369 | /** |
||
370 | * Read expand or select clause. |
||
371 | * |
||
372 | * @param string $value expand or select clause to read |
||
373 | * @param bool $isSelect true means $value is value of select clause |
||
374 | * else value of expand clause |
||
375 | * |
||
376 | * @return array<array> An array of 'PathSegment's, each of which is array of 'SubPathSegment's |
||
377 | */ |
||
378 | private function readExpandOrSelect($value, $isSelect) |
||
413 | } |
||
414 |