Complex classes like ObjectProxyTrait 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 ObjectProxyTrait, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
56 | trait ObjectProxyTrait |
||
57 | { |
||
58 | /** |
||
59 | * Use traits |
||
60 | */ |
||
61 | use IterableProxyTrait; |
||
62 | /** |
||
63 | * Object |
||
64 | * |
||
65 | * @var ObjectInterface |
||
66 | */ |
||
67 | protected $object = null; |
||
68 | |||
69 | /** |
||
70 | * Return the object repository locator |
||
71 | * |
||
72 | * @return RepositoryLocatorInterface Object repository locator |
||
73 | */ |
||
74 | public function getRepositoryLocator() |
||
83 | |||
84 | /** |
||
85 | * Return the URL |
||
86 | * |
||
87 | * @return ApparatUrl URL |
||
88 | */ |
||
89 | abstract public function getUrl(); |
||
90 | |||
91 | /** |
||
92 | * Return the object property data |
||
93 | * |
||
94 | * @param bool $serialize Serialize property objects |
||
95 | * @return array Object property data |
||
96 | */ |
||
97 | public function getPropertyData($serialize = true) |
||
101 | |||
102 | /** |
||
103 | * Return the enclosed remote object |
||
104 | * |
||
105 | * @return ObjectInterface Remote object |
||
106 | */ |
||
107 | 1 | protected function object() |
|
118 | |||
119 | /** |
||
120 | * Return the object payload |
||
121 | * |
||
122 | * @return string Object payload |
||
123 | */ |
||
124 | public function getPayload() |
||
128 | |||
129 | /** |
||
130 | * Set the payload |
||
131 | * |
||
132 | * @param string $payload Payload |
||
133 | * @return ObjectInterface Self reference |
||
134 | */ |
||
135 | public function setPayload($payload) |
||
139 | |||
140 | /** |
||
141 | * Return the object ID |
||
142 | * |
||
143 | * @return Id Object ID |
||
144 | */ |
||
145 | public function getId() |
||
149 | |||
150 | /** |
||
151 | * Return the object type |
||
152 | * |
||
153 | * @return Type Object type |
||
154 | */ |
||
155 | public function getObjectType() |
||
159 | |||
160 | /** |
||
161 | * Return the object revision |
||
162 | * |
||
163 | * @return Revision Object revision |
||
164 | */ |
||
165 | public function getRevision() |
||
169 | |||
170 | /** |
||
171 | * Return the latitude |
||
172 | * |
||
173 | * @return float Latitude |
||
174 | */ |
||
175 | public function getLatitude() |
||
179 | |||
180 | /** |
||
181 | * Set the latitude |
||
182 | * |
||
183 | * @param float $latitude Latitude |
||
184 | * @return ObjectInterface Self reference |
||
185 | */ |
||
186 | public function setLatitude($latitude) |
||
190 | |||
191 | /** |
||
192 | * Return the longitude |
||
193 | * |
||
194 | * @return float Longitude |
||
195 | */ |
||
196 | public function getLongitude() |
||
200 | |||
201 | /** |
||
202 | * Set the longitude |
||
203 | * |
||
204 | * @param float $longitude Longitude |
||
205 | * @return ObjectInterface Self reference |
||
206 | */ |
||
207 | public function setLongitude($longitude) |
||
211 | |||
212 | /** |
||
213 | * Return the elevation |
||
214 | * |
||
215 | * @return float Elevation |
||
216 | */ |
||
217 | public function getElevation() |
||
221 | |||
222 | /** |
||
223 | * Set the elevation |
||
224 | * |
||
225 | * @param float $elevation |
||
226 | * @return ObjectInterface Self reference |
||
227 | */ |
||
228 | public function setElevation($elevation) |
||
232 | |||
233 | /** |
||
234 | * Return the object draft mode |
||
235 | * |
||
236 | * @return boolean Object draft mode |
||
237 | */ |
||
238 | public function isDraft() |
||
242 | |||
243 | /** |
||
244 | * Return whether the object is in modified state |
||
245 | * |
||
246 | * @return boolean Modified state |
||
247 | */ |
||
248 | public function hasBeenModified() |
||
252 | |||
253 | /** |
||
254 | * Return whether the object is in mutated state |
||
255 | * |
||
256 | * @return boolean Mutated state |
||
257 | */ |
||
258 | public function hasBeenMutated() |
||
262 | |||
263 | /** |
||
264 | * Return the creation date & time |
||
265 | * |
||
266 | * @return \DateTimeInterface Creation date & time |
||
267 | */ |
||
268 | public function getCreated() |
||
272 | |||
273 | /** |
||
274 | * Return the deletion date & time |
||
275 | * |
||
276 | * @return \DateTimeInterface Deletion date & time |
||
277 | */ |
||
278 | public function getDeleted() |
||
282 | |||
283 | /** |
||
284 | * Return the modification date & time |
||
285 | * |
||
286 | * @return \DateTimeInterface Modification date & time |
||
287 | */ |
||
288 | public function getModified() |
||
292 | |||
293 | /** |
||
294 | * Return the publication date & time |
||
295 | * |
||
296 | * @return \DateTimeInterface Publication date & time |
||
297 | */ |
||
298 | public function getPublished() |
||
302 | |||
303 | /** |
||
304 | * Return the object title |
||
305 | * |
||
306 | * @return string Object title |
||
307 | */ |
||
308 | 1 | public function getTitle() |
|
312 | |||
313 | /** |
||
314 | * Set the title |
||
315 | * |
||
316 | * @param string $title Title |
||
317 | * @return ObjectInterface Self reference |
||
318 | */ |
||
319 | public function setTitle($title) |
||
323 | |||
324 | /** |
||
325 | * Return the object slug |
||
326 | * |
||
327 | * @return string Object slug |
||
328 | */ |
||
329 | public function getSlug() |
||
333 | |||
334 | /** |
||
335 | * Set the slug |
||
336 | * |
||
337 | * @param string $slug Slug |
||
338 | * @return ObjectInterface Self reference |
||
339 | */ |
||
340 | public function setSlug($slug) |
||
344 | |||
345 | /** |
||
346 | * Return the object description |
||
347 | * |
||
348 | * @return string Object description |
||
349 | */ |
||
350 | public function getDescription() |
||
354 | |||
355 | /** |
||
356 | * Set the description |
||
357 | * |
||
358 | * @param string $description Description |
||
359 | * @return ObjectInterface Self reference |
||
360 | */ |
||
361 | public function setDescription($description) |
||
365 | |||
366 | /** |
||
367 | * Return the object abstract |
||
368 | * |
||
369 | * @return string Object abstract |
||
370 | */ |
||
371 | public function getAbstract() |
||
375 | |||
376 | /** |
||
377 | * Set the abstract |
||
378 | * |
||
379 | * @param string $abstract Abstract |
||
380 | * @return ObjectInterface Self reference |
||
381 | */ |
||
382 | public function setAbstract($abstract) |
||
386 | |||
387 | /** |
||
388 | * Return all object keywords |
||
389 | * |
||
390 | * @return array Object keywords |
||
391 | */ |
||
392 | public function getKeywords() |
||
396 | |||
397 | /** |
||
398 | * Set the keywords |
||
399 | * |
||
400 | * @param array $keywords Keywords |
||
401 | * @return ObjectInterface Self reference |
||
402 | */ |
||
403 | public function setKeywords(array $keywords) |
||
407 | |||
408 | /** |
||
409 | * Return the license |
||
410 | * |
||
411 | * @return string License |
||
412 | */ |
||
413 | public function getLicense() |
||
417 | |||
418 | /** |
||
419 | * Set the license |
||
420 | * |
||
421 | * @param string $license License |
||
422 | * @return ObjectInterface Self reference |
||
423 | */ |
||
424 | public function setLicense($license) |
||
428 | |||
429 | /** |
||
430 | * Return the language |
||
431 | * |
||
432 | * @return string Language |
||
433 | */ |
||
434 | public function getLanguage() |
||
438 | |||
439 | /** |
||
440 | * Return the privacy |
||
441 | * |
||
442 | * @return string Privacy |
||
443 | */ |
||
444 | public function getPrivacy() |
||
448 | |||
449 | /** |
||
450 | * Set the privacy |
||
451 | * |
||
452 | * @param string $privacy Privacy |
||
453 | * @return ObjectInterface Self reference |
||
454 | */ |
||
455 | public function setPrivacy($privacy) |
||
459 | |||
460 | /** |
||
461 | * Return all object categories |
||
462 | * |
||
463 | * @return array Object categories |
||
464 | */ |
||
465 | public function getCategories() |
||
469 | |||
470 | /** |
||
471 | * Set the categories |
||
472 | * |
||
473 | * @param array $categories Categories |
||
474 | * @return ObjectInterface Self reference |
||
475 | */ |
||
476 | public function setCategories(array $categories) |
||
480 | |||
481 | /** |
||
482 | * Get a domain property value |
||
483 | * |
||
484 | * Multi-level properties might be traversed by property name locators separated with colons (":"). |
||
485 | * |
||
486 | * @param string $property Property name |
||
487 | * @return mixed Property value |
||
488 | */ |
||
489 | public function getDomain($property) |
||
493 | |||
494 | /** |
||
495 | * Set a domain property value |
||
496 | * |
||
497 | * @param string $property Property name |
||
498 | * @param mixed $value Property value |
||
499 | * @return ObjectInterface Self reference |
||
500 | */ |
||
501 | public function setDomain($property, $value) |
||
505 | |||
506 | /** |
||
507 | * Get a processing instruction |
||
508 | * |
||
509 | * @param string $procInst Processing instruction name |
||
510 | * @return mixed Processing instruction |
||
511 | */ |
||
512 | public function getProcessingInstruction($procInst) |
||
516 | |||
517 | /** |
||
518 | * Set a processing instruction |
||
519 | * |
||
520 | * @param string $procInst Processing instruction name |
||
521 | * @param mixed $value Processing instruction |
||
522 | * @return ObjectInterface Self reference |
||
523 | */ |
||
524 | public function setProcessingInstruction($procInst, $value) |
||
528 | |||
529 | /** |
||
530 | * Return the canonical object URL |
||
531 | * |
||
532 | * @return string |
||
533 | */ |
||
534 | public function getCanonicalUrl() |
||
538 | |||
539 | /** |
||
540 | * Return the absolute object URL |
||
541 | * |
||
542 | * @return string |
||
543 | */ |
||
544 | public function getAbsoluteUrl() |
||
548 | |||
549 | /** |
||
550 | * Generic caller |
||
551 | * |
||
552 | * @param string $name Method name |
||
553 | * @param array $arguments Method arguments |
||
554 | */ |
||
555 | public function __call($name, $arguments) |
||
567 | |||
568 | /** |
||
569 | * Use a specific object revision |
||
570 | * |
||
571 | * @param Revision $revision Revision to be used |
||
572 | * @return ObjectInterface Object |
||
573 | */ |
||
574 | public function useRevision(Revision $revision) |
||
578 | |||
579 | /** |
||
580 | * Persist the current object revision |
||
581 | * |
||
582 | * @return ObjectInterface Object |
||
583 | */ |
||
584 | public function persist() |
||
588 | |||
589 | /** |
||
590 | * Return whether the object is in published state |
||
591 | * |
||
592 | * @return boolean Published state |
||
593 | */ |
||
594 | public function isPublished() |
||
598 | |||
599 | /** |
||
600 | * Return whether the object has just been published |
||
601 | * |
||
602 | * @return boolean Object has just been published |
||
603 | */ |
||
604 | public function hasBeenPublished() |
||
608 | |||
609 | /** |
||
610 | * Return whether the object has been deleted |
||
611 | * |
||
612 | * @return boolean Object is deleted |
||
613 | */ |
||
614 | public function isDeleted() |
||
618 | |||
619 | /** |
||
620 | * Return whether the object has just been deleted |
||
621 | * |
||
622 | * @return boolean Object has just been deleted |
||
623 | */ |
||
624 | public function hasBeenDeleted() |
||
628 | |||
629 | /** |
||
630 | * Return whether the object has just been undeleted |
||
631 | * |
||
632 | * @return boolean Object has just been undeleted |
||
633 | */ |
||
634 | public function hasBeenUndeleted() |
||
638 | |||
639 | /** |
||
640 | * Publish the current object revision |
||
641 | * |
||
642 | * @return ObjectInterface Object |
||
643 | */ |
||
644 | public function publish() |
||
648 | |||
649 | /** |
||
650 | * Delete the object and all its revisions |
||
651 | * |
||
652 | * @return ObjectInterface Object |
||
653 | */ |
||
654 | public function delete() |
||
658 | |||
659 | /** |
||
660 | * Undelete the object and all its revisions |
||
661 | * |
||
662 | * @return ObjectInterface Object |
||
663 | */ |
||
664 | public function undelete() |
||
668 | |||
669 | /** |
||
670 | * Add an object relation |
||
671 | * |
||
672 | * @param string|RelationInterface $relation Serialized or instantiated object relation |
||
673 | * @param string|null $relationType Relation type |
||
674 | * @return ObjectInterface |
||
675 | */ |
||
676 | public function addRelation($relation, $relationType = null) |
||
680 | |||
681 | /** |
||
682 | * Delete an object relation |
||
683 | * |
||
684 | * @param RelationInterface $relation Object relation |
||
685 | * @return ObjectInterface |
||
686 | */ |
||
687 | public function deleteRelation(RelationInterface $relation) |
||
691 | |||
692 | /** |
||
693 | * Get all relations (optional: Of a particular type) |
||
694 | * |
||
695 | * @param string|null $relationType Optional: Relation type |
||
696 | * @return array Object relations |
||
697 | */ |
||
698 | public function getRelations($relationType = null) |
||
702 | |||
703 | /** |
||
704 | * Find and return particular relations |
||
705 | * |
||
706 | * @param array $criteria Relation criteria |
||
707 | * @return RelationInterface[] Relations |
||
708 | */ |
||
709 | public function findRelations(array $criteria) |
||
713 | } |
||
714 |