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 |
||
31 | class IronicSerialiser implements IObjectSerialiser |
||
32 | { |
||
33 | /** |
||
34 | * The service implementation. |
||
35 | * |
||
36 | * @var IService |
||
37 | */ |
||
38 | protected $service; |
||
39 | |||
40 | /** |
||
41 | * Request description instance describes OData request the |
||
42 | * the client has submitted and result of the request. |
||
43 | * |
||
44 | * @var RequestDescription |
||
45 | */ |
||
46 | protected $request; |
||
47 | |||
48 | /** |
||
49 | * Collection of complex type instances used for cycle detection. |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected $complexTypeInstanceCollection; |
||
54 | |||
55 | /** |
||
56 | * Absolute service Uri. |
||
57 | * |
||
58 | * @var string |
||
59 | */ |
||
60 | protected $absoluteServiceUri; |
||
61 | |||
62 | /** |
||
63 | * Absolute service Uri with slash. |
||
64 | * |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $absoluteServiceUriWithSlash; |
||
68 | |||
69 | /** |
||
70 | * Holds reference to segment stack being processed. |
||
71 | * |
||
72 | * @var SegmentStack |
||
73 | */ |
||
74 | protected $stack; |
||
75 | |||
76 | /** |
||
77 | * Lightweight stack tracking for recursive descent fill |
||
78 | */ |
||
79 | private $lightStack = []; |
||
80 | |||
81 | /** |
||
82 | * @param IService $service Reference to the data service instance |
||
83 | * @param RequestDescription $request Type instance describing the client submitted request |
||
84 | */ |
||
85 | public function __construct(IService $service, RequestDescription $request = null) |
||
94 | |||
95 | /** |
||
96 | * Write a top level entry resource. |
||
97 | * |
||
98 | * @param mixed $entryObject Reference to the entry object to be written |
||
99 | * |
||
100 | * @return ODataEntry |
||
101 | */ |
||
102 | public function writeTopLevelElement($entryObject) |
||
204 | |||
205 | /** |
||
206 | * Write top level feed element. |
||
207 | * |
||
208 | * @param array &$entryObjects Array of entry resources to be written |
||
209 | * |
||
210 | * @return ODataFeed |
||
211 | */ |
||
212 | public function writeTopLevelElements(&$entryObjects) |
||
253 | |||
254 | /** |
||
255 | * Write top level url element. |
||
256 | * |
||
257 | * @param mixed $entryObject The entry resource whose url to be written |
||
258 | * |
||
259 | * @return ODataURL |
||
260 | */ |
||
261 | public function writeUrlElement($entryObject) |
||
277 | |||
278 | /** |
||
279 | * Write top level url collection. |
||
280 | * |
||
281 | * @param array $entryObjects Array of entry resources |
||
282 | * whose url to be written |
||
283 | * |
||
284 | * @return ODataURLCollection |
||
285 | */ |
||
286 | public function writeUrlElements($entryObjects) |
||
313 | |||
314 | /** |
||
315 | * Write top level complex resource. |
||
316 | * |
||
317 | * @param mixed &$complexValue The complex object to be |
||
318 | * written |
||
319 | * @param string $propertyName The name of the |
||
320 | * complex property |
||
321 | * @param ResourceType &$resourceType Describes the type of |
||
322 | * complex object |
||
323 | * |
||
324 | * @return ODataPropertyContent |
||
325 | * @codeCoverageIgnore |
||
326 | */ |
||
327 | public function writeTopLevelComplexObject(&$complexValue, $propertyName, ResourceType &$resourceType) |
||
331 | |||
332 | /** |
||
333 | * Write top level bag resource. |
||
334 | * |
||
335 | * @param mixed &$BagValue The bag object to be |
||
336 | * written |
||
337 | * @param string $propertyName The name of the |
||
338 | * bag property |
||
339 | * @param ResourceType &$resourceType Describes the type of |
||
340 | * bag object |
||
341 | * @codeCoverageIgnore |
||
342 | * @return ODataPropertyContent |
||
343 | */ |
||
344 | public function writeTopLevelBagObject(&$BagValue, $propertyName, ResourceType &$resourceType) |
||
348 | |||
349 | /** |
||
350 | * Write top level primitive value. |
||
351 | * |
||
352 | * @param mixed &$primitiveValue The primitve value to be |
||
353 | * written |
||
354 | * @param ResourceProperty &$resourceProperty Resource property |
||
355 | * describing the |
||
356 | * primitive property |
||
357 | * to be written |
||
358 | * @codeCoverageIgnore |
||
359 | * @return ODataPropertyContent |
||
360 | */ |
||
361 | public function writeTopLevelPrimitive(&$primitiveValue, ResourceProperty &$resourceProperty = null) |
||
365 | |||
366 | /** |
||
367 | * Gets reference to the request submitted by client. |
||
368 | * |
||
369 | * @return RequestDescription |
||
370 | */ |
||
371 | public function getRequest() |
||
377 | |||
378 | /** |
||
379 | * Sets reference to the request submitted by client. |
||
380 | * |
||
381 | * @param RequestDescription $request |
||
382 | */ |
||
383 | public function setRequest(RequestDescription $request) |
||
388 | |||
389 | /** |
||
390 | * Gets the data service instance. |
||
391 | * |
||
392 | * @return IService |
||
393 | */ |
||
394 | public function getService() |
||
398 | |||
399 | /** |
||
400 | * Gets the segment stack instance. |
||
401 | * |
||
402 | * @return SegmentStack |
||
403 | */ |
||
404 | public function getStack() |
||
408 | |||
409 | protected function getEntryInstanceKey($entityInstance, ResourceType $resourceType, $containerName) |
||
436 | |||
437 | /** |
||
438 | * @param $entryObject |
||
439 | * @param $type |
||
440 | * @param $relativeUri |
||
441 | * @param $resourceType |
||
442 | * @return array |
||
443 | */ |
||
444 | protected function writeMediaData($entryObject, $type, $relativeUri, ResourceType $resourceType) |
||
482 | |||
483 | /** |
||
484 | * Gets collection of projection nodes under the current node. |
||
485 | * |
||
486 | * @return ProjectionNode[]|ExpandedProjectionNode[]|null List of nodes |
||
487 | * describing projections for the current segment, If this method returns |
||
488 | * null it means no projections are to be applied and the entire resource |
||
489 | * for the current segment should be serialized, If it returns non-null |
||
490 | * only the properties described by the returned projection segments should |
||
491 | * be serialized |
||
492 | */ |
||
493 | protected function getProjectionNodes() |
||
502 | |||
503 | /** |
||
504 | * Find a 'ExpandedProjectionNode' instance in the projection tree |
||
505 | * which describes the current segment. |
||
506 | * |
||
507 | * @return ExpandedProjectionNode|null |
||
508 | */ |
||
509 | protected function getCurrentExpandedProjectionNode() |
||
537 | |||
538 | /** |
||
539 | * Check whether to expand a navigation property or not. |
||
540 | * |
||
541 | * @param string $navigationPropertyName Name of naviagtion property in question |
||
542 | * |
||
543 | * @return bool True if the given navigation should be |
||
544 | * explanded otherwise false |
||
545 | */ |
||
546 | protected function shouldExpandSegment($navigationPropertyName) |
||
558 | |||
559 | /** |
||
560 | * Wheter next link is needed for the current resource set (feed) |
||
561 | * being serialized. |
||
562 | * |
||
563 | * @param int $resultSetCount Number of entries in the current |
||
564 | * resource set |
||
565 | * |
||
566 | * @return bool true if the feed must have a next page link |
||
567 | */ |
||
568 | protected function needNextPageLink($resultSetCount) |
||
583 | |||
584 | /** |
||
585 | * Resource set wrapper for the resource being serialized. |
||
586 | * |
||
587 | * @return ResourceSetWrapper |
||
588 | */ |
||
589 | protected function getCurrentResourceSetWrapper() |
||
596 | |||
597 | /** |
||
598 | * Get next page link from the given entity instance. |
||
599 | * |
||
600 | * @param mixed &$lastObject Last object serialized to be |
||
601 | * used for generating $skiptoken |
||
602 | * @param string $absoluteUri Absolute response URI |
||
603 | * |
||
604 | * @return string for the link for next page |
||
605 | */ |
||
606 | protected function getNextLinkUri(&$lastObject, $absoluteUri) |
||
615 | |||
616 | private function loadStackIfEmpty() |
||
623 | } |
||
624 |
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.