Complex classes like IronicSerialiser 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 IronicSerialiser, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
30 | class IronicSerialiser implements IObjectSerialiser |
||
31 | { |
||
32 | /** |
||
33 | * The service implementation. |
||
34 | * |
||
35 | * @var IService |
||
36 | */ |
||
37 | protected $service; |
||
38 | |||
39 | /** |
||
40 | * Request description instance describes OData request the |
||
41 | * the client has submitted and result of the request. |
||
42 | * |
||
43 | * @var RequestDescription |
||
44 | */ |
||
45 | protected $request; |
||
46 | |||
47 | /** |
||
48 | * Collection of complex type instances used for cycle detection. |
||
49 | * |
||
50 | * @var array |
||
51 | */ |
||
52 | protected $complexTypeInstanceCollection; |
||
53 | |||
54 | /** |
||
55 | * Absolute service Uri. |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $absoluteServiceUri; |
||
60 | |||
61 | /** |
||
62 | * Absolute service Uri with slash. |
||
63 | * |
||
64 | * @var string |
||
65 | */ |
||
66 | protected $absoluteServiceUriWithSlash; |
||
67 | |||
68 | /** |
||
69 | * Holds reference to segment stack being processed. |
||
70 | * |
||
71 | * @var SegmentStack |
||
72 | */ |
||
73 | protected $stack; |
||
74 | |||
75 | /** |
||
76 | * Lightweight stack tracking for recursive descent fill |
||
77 | */ |
||
78 | private $lightStack = []; |
||
79 | |||
80 | /** |
||
81 | * @param IService $service Reference to the data service instance |
||
82 | * @param RequestDescription $request Type instance describing the client submitted request |
||
83 | */ |
||
84 | public function __construct(IService $service, RequestDescription $request = null) |
||
93 | |||
94 | /** |
||
95 | * Write a top level entry resource. |
||
96 | * |
||
97 | * @param mixed $entryObject Reference to the entry object to be written |
||
98 | * |
||
99 | * @return ODataEntry |
||
100 | */ |
||
101 | public function writeTopLevelElement($entryObject) |
||
206 | |||
207 | /** |
||
208 | * Write top level feed element. |
||
209 | * |
||
210 | * @param array &$entryObjects Array of entry resources to be written |
||
211 | * |
||
212 | * @return ODataFeed |
||
213 | */ |
||
214 | public function writeTopLevelElements(&$entryObjects) |
||
244 | |||
245 | /** |
||
246 | * Write top level url element. |
||
247 | * |
||
248 | * @param mixed $entryObject The entry resource whose url to be written |
||
249 | * |
||
250 | * @return ODataURL |
||
251 | */ |
||
252 | public function writeUrlElement($entryObject) |
||
256 | |||
257 | /** |
||
258 | * Write top level url collection. |
||
259 | * |
||
260 | * @param array $entryObjects Array of entry resources |
||
261 | * whose url to be written |
||
262 | * |
||
263 | * @return ODataURLCollection |
||
264 | */ |
||
265 | public function writeUrlElements($entryObjects) |
||
269 | |||
270 | /** |
||
271 | * Write top level complex resource. |
||
272 | * |
||
273 | * @param mixed &$complexValue The complex object to be |
||
274 | * written |
||
275 | * @param string $propertyName The name of the |
||
276 | * complex property |
||
277 | * @param ResourceType &$resourceType Describes the type of |
||
278 | * complex object |
||
279 | * |
||
280 | * @return ODataPropertyContent |
||
281 | */ |
||
282 | public function writeTopLevelComplexObject(&$complexValue, $propertyName, ResourceType &$resourceType) |
||
286 | |||
287 | /** |
||
288 | * Write top level bag resource. |
||
289 | * |
||
290 | * @param mixed &$BagValue The bag object to be |
||
291 | * written |
||
292 | * @param string $propertyName The name of the |
||
293 | * bag property |
||
294 | * @param ResourceType &$resourceType Describes the type of |
||
295 | * bag object |
||
296 | * |
||
297 | * @return ODataPropertyContent |
||
298 | */ |
||
299 | public function writeTopLevelBagObject(&$BagValue, $propertyName, ResourceType &$resourceType) |
||
303 | |||
304 | /** |
||
305 | * Write top level primitive value. |
||
306 | * |
||
307 | * @param mixed &$primitiveValue The primitve value to be |
||
308 | * written |
||
309 | * @param ResourceProperty &$resourceProperty Resource property |
||
310 | * describing the |
||
311 | * primitive property |
||
312 | * to be written |
||
313 | * |
||
314 | * @return ODataPropertyContent |
||
315 | */ |
||
316 | public function writeTopLevelPrimitive(&$primitiveValue, ResourceProperty &$resourceProperty = null) |
||
320 | |||
321 | /** |
||
322 | * Gets reference to the request submitted by client. |
||
323 | * |
||
324 | * @return RequestDescription |
||
325 | */ |
||
326 | public function getRequest() |
||
332 | |||
333 | /** |
||
334 | * Sets reference to the request submitted by client. |
||
335 | * |
||
336 | * @param RequestDescription $request |
||
337 | */ |
||
338 | public function setRequest(RequestDescription $request) |
||
343 | |||
344 | /** |
||
345 | * Gets the data service instance. |
||
346 | * |
||
347 | * @return IService |
||
348 | */ |
||
349 | public function getService() |
||
353 | |||
354 | /** |
||
355 | * Gets the segment stack instance. |
||
356 | * |
||
357 | * @return SegmentStack |
||
358 | */ |
||
359 | public function getStack() |
||
363 | |||
364 | protected function getEntryInstanceKey($entityInstance, ResourceType $resourceType, $containerName) |
||
392 | |||
393 | /** |
||
394 | * @param $entryObject |
||
395 | * @param $type |
||
396 | * @param $relativeUri |
||
397 | * @param $resourceType |
||
398 | * @return array |
||
399 | */ |
||
400 | protected function writeMediaData($entryObject, $type, $relativeUri, ResourceType $resourceType) |
||
438 | |||
439 | /** |
||
440 | * Gets collection of projection nodes under the current node. |
||
441 | * |
||
442 | * @return ProjectionNode[]|ExpandedProjectionNode[]|null List of nodes |
||
443 | * describing projections for the current segment, If this method returns |
||
444 | * null it means no projections are to be applied and the entire resource |
||
445 | * for the current segment should be serialized, If it returns non-null |
||
446 | * only the properties described by the returned projection segments should |
||
447 | * be serialized |
||
448 | */ |
||
449 | protected function getProjectionNodes() |
||
458 | |||
459 | /** |
||
460 | * Find a 'ExpandedProjectionNode' instance in the projection tree |
||
461 | * which describes the current segment. |
||
462 | * |
||
463 | * @return ExpandedProjectionNode|null |
||
464 | */ |
||
465 | protected function getCurrentExpandedProjectionNode() |
||
494 | |||
495 | /** |
||
496 | * Check whether to expand a navigation property or not. |
||
497 | * |
||
498 | * @param string $navigationPropertyName Name of naviagtion property in question |
||
499 | * |
||
500 | * @return bool True if the given navigation should be |
||
501 | * explanded otherwise false |
||
502 | */ |
||
503 | protected function shouldExpandSegment($navigationPropertyName) |
||
515 | } |
||
516 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.