Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like ObjectService 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 ObjectService, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
37 | class ObjectService extends AbstractBrowserBindingService implements ObjectServiceInterface |
||
38 | { |
||
39 | /** |
||
40 | * Appends the content stream to the content of the document. |
||
41 | * |
||
42 | * The stream in contentStream is consumed but not closed by this method. |
||
43 | * |
||
44 | * @param string $repositoryId the identifier for the repository |
||
45 | * @param string $objectId The identifier for the object. The repository might return a different/new object id |
||
46 | * @param StreamInterface $contentStream The content stream to append |
||
47 | * @param boolean $isLastChunk Indicates if this content stream is the last chunk |
||
48 | * @param string|null $changeToken The last change token of this object that the client received. |
||
49 | * The repository might return a new change token (default is <code>null</code>) |
||
50 | * @param ExtensionDataInterface|null $extension |
||
51 | */ |
||
52 | public function appendContentStream( |
||
62 | |||
63 | /** |
||
64 | * Updates properties and secondary types of one or more objects. |
||
65 | * |
||
66 | * @param string $repositoryId the identifier for the repository |
||
67 | * @param BulkUpdateObjectIdAndChangeTokenInterface[] $objectIdsAndChangeTokens |
||
68 | * @param PropertiesInterface $properties |
||
69 | * @param string[] $addSecondaryTypeIds the secondary types to apply |
||
70 | * @param string[] $removeSecondaryTypeIds the secondary types to remove |
||
71 | * @param ExtensionDataInterface|null $extension |
||
72 | * @return BulkUpdateObjectIdAndChangeTokenInterface[] |
||
73 | */ |
||
74 | public function bulkUpdateProperties( |
||
84 | |||
85 | /** |
||
86 | * Creates a document object of the specified type (given by the cmis:objectTypeId property) |
||
87 | * in the (optionally) specified location. |
||
88 | * |
||
89 | * @param string $repositoryId the identifier for the repository |
||
90 | * @param PropertiesInterface $properties the property values that must be applied to the newly |
||
91 | * created document object |
||
92 | * @param string|null $folderId if specified, the identifier for the folder that must be the parent |
||
93 | * folder for the newly created document object |
||
94 | * @param StreamInterface|null $contentStream the content stream that must be stored for the newly |
||
95 | * created document object |
||
96 | * @param VersioningState|null $versioningState specifies what the versioning state of the newly created object |
||
97 | * must be (default is <code>VersioningState::MAJOR</code>) |
||
98 | * @param string[] $policies a list of policy IDs that must be applied to the newly created document object |
||
99 | * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object, |
||
100 | * either using the ACL from folderId if specified, or being applied if no folderId is specified |
||
101 | * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object, |
||
102 | * either using the ACL from folderId if specified, or being ignored if no folderId is specified |
||
103 | * @param ExtensionDataInterface|null $extension |
||
104 | * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty |
||
105 | * result (which should not happen) |
||
106 | */ |
||
107 | 3 | public function createDocument( |
|
162 | |||
163 | /** |
||
164 | * Creates a document object as a copy of the given source document in the (optionally) specified location. |
||
165 | * |
||
166 | * @param string $repositoryId the identifier for the repository |
||
167 | * @param string $sourceId the identifier for the source document |
||
168 | * @param PropertiesInterface $properties the property values that must be applied to the newly |
||
169 | * created document object |
||
170 | * @param string|null $folderId if specified, the identifier for the folder that must be the parent folder for the |
||
171 | * newly created document object |
||
172 | * @param VersioningState|null $versioningState specifies what the versioning state of the newly created object |
||
173 | * must be (default is <code>VersioningState::MAJOR</code>) |
||
174 | * @param string[] $policies a list of policy IDs that must be applied to the newly created document object |
||
175 | * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object, |
||
176 | * either using the ACL from folderId if specified, or being applied if no folderId is specified |
||
177 | * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object, |
||
178 | * either using the ACL from folderId if specified, or being ignored if no folderId is specified |
||
179 | * @param ExtensionDataInterface|null $extension |
||
180 | * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty |
||
181 | * result (which should not happen) |
||
182 | */ |
||
183 | 2 | public function createDocumentFromSource( |
|
223 | |||
224 | /** |
||
225 | * Creates a folder object of the specified type (given by the cmis:objectTypeId property) in |
||
226 | * the specified location. |
||
227 | * |
||
228 | * @param string $repositoryId the identifier for the repository |
||
229 | * @param PropertiesInterface $properties the property values that must be applied to the newly |
||
230 | * created document object |
||
231 | * @param string $folderId if specified, the identifier for the folder that must be the parent folder for the |
||
232 | * newly created document object |
||
233 | * @param string[] $policies a list of policy IDs that must be applied to the newly created document object |
||
234 | * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object, |
||
235 | * either using the ACL from folderId if specified, or being applied if no folderId is specified |
||
236 | * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object, |
||
237 | * either using the ACL from folderId if specified, or being ignored if no folderId is specified |
||
238 | * @param ExtensionDataInterface|null $extension |
||
239 | * @return string|null Returns the new object id or <code>null</code> if the repository sent an empty |
||
240 | * result (which should not happen) |
||
241 | */ |
||
242 | 2 | View Code Duplication | public function createFolder( |
271 | |||
272 | /** |
||
273 | * Creates an item object of the specified type (given by the cmis:objectTypeId property). |
||
274 | * |
||
275 | * @param string $repositoryId The identifier for the repository |
||
276 | * @param PropertiesInterface $properties The property values that must be applied to the newly |
||
277 | * created document object |
||
278 | * @param string|null $folderId If specified, the identifier for the folder that must be the parent folder for the |
||
279 | * newly created document object |
||
280 | * @param string[] $policies A list of policy IDs that must be applied to the newly created document object |
||
281 | * @param AclInterface|null $addAces A list of ACEs that must be added to the newly created document object, |
||
282 | * either using the ACL from folderId if specified, or being applied if no folderId is specified |
||
283 | * @param AclInterface|null $removeAces A list of ACEs that must be removed from the newly created document object, |
||
284 | * either using the ACL from folderId if specified, or being ignored if no folderId is specified |
||
285 | * @param ExtensionDataInterface|null $extension |
||
286 | * @return string|null Returns the new item id or <code>null</code> if the repository sent an empty |
||
287 | * result (which should not happen) |
||
288 | */ |
||
289 | 2 | public function createItem( |
|
323 | |||
324 | /** |
||
325 | * Creates a policy object of the specified type (given by the cmis:objectTypeId property). |
||
326 | * |
||
327 | * @param string $repositoryId The identifier for the repository |
||
328 | * @param PropertiesInterface $properties The property values that must be applied to the newly |
||
329 | * created document object |
||
330 | * @param string|null $folderId If specified, the identifier for the folder that must be the parent folder for the |
||
331 | * newly created document object |
||
332 | * @param string[] $policies A list of policy IDs that must be applied to the newly created document object |
||
333 | * @param AclInterface|null $addAces A list of ACEs that must be added to the newly created document object, |
||
334 | * either using the ACL from folderId if specified, or being applied if no folderId is specified |
||
335 | * @param AclInterface|null $removeAces A list of ACEs that must be removed from the newly created document object, |
||
336 | * either using the ACL from folderId if specified, or being ignored if no folderId is specified |
||
337 | * @param ExtensionDataInterface|null $extension |
||
338 | * @return string The id of the newly-created policy. |
||
339 | */ |
||
340 | public function createPolicy( |
||
351 | |||
352 | /** |
||
353 | * Creates a relationship object of the specified type (given by the cmis:objectTypeId property). |
||
354 | * |
||
355 | * @param string $repositoryId the identifier for the repository |
||
356 | * @param PropertiesInterface $properties the property values that must be applied to the newly |
||
357 | * created document object |
||
358 | * @param string[] $policies a list of policy IDs that must be applied to the newly created document object |
||
359 | * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object, |
||
360 | * either using the ACL from folderId if specified, or being applied if no folderId is specified |
||
361 | * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object, |
||
362 | * either using the ACL from folderId if specified, or being ignored if no folderId is specified |
||
363 | * @param ExtensionDataInterface|null $extension |
||
364 | * @return string|null Returns the new item id of the relationship object or <code>null</code> if the repository |
||
365 | * sent an empty result (which should not happen) |
||
366 | */ |
||
367 | View Code Duplication | public function createRelationship( |
|
395 | |||
396 | /** |
||
397 | * Deletes the content stream for the specified document object. |
||
398 | * |
||
399 | * @param string $repositoryId the identifier for the repository |
||
400 | * @param string $objectId the identifier for the object. The repository might return a different/new object id |
||
401 | * @param string|null $changeToken the last change token of this object that the client received. |
||
402 | * The repository might return a new change token (default is <code>null</code>) |
||
403 | * @param ExtensionDataInterface|null $extension |
||
404 | * @throws CmisInvalidArgumentException If $objectId is empty |
||
405 | */ |
||
406 | 3 | public function deleteContentStream( |
|
444 | |||
445 | /** |
||
446 | * Deletes the specified object. |
||
447 | * |
||
448 | * @param string $repositoryId the identifier for the repository |
||
449 | * @param string $objectId the identifier for the object |
||
450 | * @param boolean $allVersions If <code>true</code> then delete all versions of the document, otherwise delete only |
||
451 | * the document object specified (default is <code>true</code>) |
||
452 | * @param ExtensionDataInterface|null $extension |
||
453 | */ |
||
454 | 2 | public function deleteObject( |
|
470 | |||
471 | /** |
||
472 | * Deletes the specified folder object and all of its child- and descendant-objects. |
||
473 | * |
||
474 | * @param string $repositoryId the identifier for the repository |
||
475 | * @param string $folderId the identifier for the folder |
||
476 | * @param boolean $allVersions If <code>true</code> then delete all versions of the document, otherwise delete only |
||
477 | * the document object specified (default is <code>true</code>) |
||
478 | * @param UnfileObject|null $unfileObjects defines how the repository must process file-able child- or |
||
479 | * descendant-objects (default is <code>UnfileObject::DELETE</code>) |
||
480 | * @param boolean $continueOnFailure If <code>true</code>, then the repository should continue attempting to |
||
481 | * perform this operation even if deletion of a child- or descendant-object in the specified folder cannot |
||
482 | * be deleted |
||
483 | * @param ExtensionDataInterface|null $extension |
||
484 | * @return FailedToDeleteDataInterface Returns a list of object ids that could not be deleted |
||
485 | */ |
||
486 | 4 | public function deleteTree( |
|
512 | |||
513 | /** |
||
514 | * Gets the list of allowable actions for an object. |
||
515 | * |
||
516 | * @param string $repositoryId the identifier for the repository |
||
517 | * @param string $objectId the identifier for the object |
||
518 | * @param ExtensionDataInterface|null $extension |
||
519 | * @return AllowableActionsInterface |
||
520 | */ |
||
521 | public function getAllowableActions($repositoryId, $objectId, ExtensionDataInterface $extension = null) |
||
525 | |||
526 | /** |
||
527 | * Gets the content stream for the specified document object, or gets a rendition stream for |
||
528 | * a specified rendition of a document or folder object. |
||
529 | * |
||
530 | * @param string $repositoryId the identifier for the repository |
||
531 | * @param string $objectId the identifier for the object |
||
532 | * @param string|null $streamId The identifier for the rendition stream, when used to get a rendition stream. |
||
533 | * For documents, if not provided then this method returns the content stream. For folders, |
||
534 | * it MUST be provided. |
||
535 | * @param integer|null $offset |
||
536 | * @param integer|null $length |
||
537 | * @param ExtensionDataInterface|null $extension |
||
538 | * @return StreamInterface|null |
||
539 | * @throws CmisInvalidArgumentException If object id is empty |
||
540 | */ |
||
541 | 3 | public function getContentStream( |
|
573 | |||
574 | /** |
||
575 | * Gets the specified information for the object specified by id. |
||
576 | * |
||
577 | * @param string $repositoryId the identifier for the repository |
||
578 | * @param string $objectId the identifier for the object |
||
579 | * @param string|null $filter a comma-separated list of query names that defines which properties must be |
||
580 | * returned by the repository (default is repository specific) |
||
581 | * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the allowable |
||
582 | * actions for the object (default is <code>false</code>) |
||
583 | * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects |
||
584 | * participate must be returned (default is <code>IncludeRelationships::NONE</code>) |
||
585 | * @param string $renditionFilter indicates what set of renditions the repository must return whose kind |
||
586 | * matches this filter (default is "cmis:none") |
||
587 | * @param boolean $includePolicyIds if <code>true</code>, then the repository must return the policy ids for |
||
588 | * the object (default is <code>false</code>) |
||
589 | * @param boolean $includeAcl if <code>true</code>, then the repository must return the ACL for the object |
||
590 | * (default is <code>false</code>) |
||
591 | * @param ExtensionDataInterface|null $extension |
||
592 | * @return ObjectDataInterface|null Returns object of type ObjectDataInterface or <code>null</code> |
||
593 | * if the repository response was empty |
||
594 | */ |
||
595 | 3 | View Code Duplication | public function getObject( |
631 | |||
632 | /** |
||
633 | * Gets the specified information for the object specified by path. |
||
634 | * |
||
635 | * @param string $repositoryId the identifier for the repository |
||
636 | * @param string $path the path to the object |
||
637 | * @param string|null $filter a comma-separated list of query names that defines which properties must be |
||
638 | * returned by the repository (default is repository specific) |
||
639 | * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the allowable |
||
640 | * actions for the object (default is <code>false</code>) |
||
641 | * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects |
||
642 | * participate must be returned (default is <code>IncludeRelationships::NONE</code>) |
||
643 | * @param string $renditionFilter indicates what set of renditions the repository must return whose kind |
||
644 | * matches this filter (default is "cmis:none") |
||
645 | * @param boolean $includePolicyIds if <code>true</code>, then the repository must return the policy ids for |
||
646 | * the object (default is <code>false</code>) |
||
647 | * @param boolean $includeAcl if <code>true</code>, then the repository must return the ACL for the object |
||
648 | * (default is <code>false</code>) |
||
649 | * @param ExtensionDataInterface|null $extension |
||
650 | * @return ObjectDataInterface|null Returns object of type <code>ObjectDataInterface</code> or <code>null</code> |
||
651 | * if the repository response was empty |
||
652 | */ |
||
653 | 3 | View Code Duplication | public function getObjectByPath( |
689 | |||
690 | /** |
||
691 | * Gets the list of properties for an object. |
||
692 | * |
||
693 | * @param string $repositoryId the identifier for the repository |
||
694 | * @param string $objectId the identifier for the object |
||
695 | * @param string|null $filter a comma-separated list of query names that defines which properties must be |
||
696 | * returned by the repository (default is repository specific) |
||
697 | * @param ExtensionDataInterface|null $extension |
||
698 | * @return PropertiesInterface |
||
699 | */ |
||
700 | 2 | public function getProperties( |
|
727 | |||
728 | /** |
||
729 | * Gets the list of associated renditions for the specified object. |
||
730 | * Only rendition attributes are returned, not rendition stream. |
||
731 | * |
||
732 | * @param string $repositoryId the identifier for the repository |
||
733 | * @param string $objectId the identifier for the object |
||
734 | * @param string $renditionFilter indicates what set of renditions the repository must return whose kind |
||
735 | * matches this filter (default is "cmis:none") |
||
736 | * @param integer|null $maxItems the maximum number of items to return in a response |
||
737 | * (default is repository specific) |
||
738 | * @param integer $skipCount number of potential results that the repository MUST skip/page over before |
||
739 | * returning any results (default is 0) |
||
740 | * @param ExtensionDataInterface|null $extension |
||
741 | * @return RenditionDataInterface[] |
||
742 | * @throws CmisInvalidArgumentException If object id is empty or skip count not of type integer |
||
743 | */ |
||
744 | 2 | public function getRenditions( |
|
776 | |||
777 | /** |
||
778 | * Moves the specified file-able object from one folder to another. |
||
779 | * |
||
780 | * @param string $repositoryId the identifier for the repository |
||
781 | * @param string $objectId the identifier for the object. The repository might return a different/new object id |
||
782 | * @param string $targetFolderId the identifier for the target folder |
||
783 | * @param string $sourceFolderId the identifier for the source folder |
||
784 | * @param ExtensionDataInterface|null $extension |
||
785 | * @return ObjectDataInterface|null Returns object of type ObjectDataInterface or <code>null</code> |
||
786 | * if the repository response was empty |
||
787 | */ |
||
788 | 1 | public function moveObject( |
|
813 | |||
814 | /** |
||
815 | * Sets the content stream for the specified document object. |
||
816 | * |
||
817 | * @param string $repositoryId The identifier for the repository |
||
818 | * @param string $objectId The identifier for the object. The repository might return a different/new object id |
||
819 | * @param StreamInterface $contentStream The content stream |
||
820 | * @param boolean $overwriteFlag If <code>true</code>, then the repository must replace the existing content stream |
||
821 | * for the object (if any) with the input content stream. If <code>false</code>, then the repository must |
||
822 | * only set the input content stream for the object if the object currently does not have a content stream |
||
823 | * (default is <code>true</code>) |
||
824 | * @param string|null $changeToken The last change token of this object that the client received. |
||
825 | * The repository might return a new change token (default is <code>null</code>) |
||
826 | * @param ExtensionDataInterface|null $extension |
||
827 | * @throws CmisInvalidArgumentException If object id is empty |
||
828 | */ |
||
829 | 3 | public function setContentStream( |
|
874 | |||
875 | /** |
||
876 | * Updates properties of the specified object. |
||
877 | * |
||
878 | * @param string $repositoryId The identifier for the repository |
||
879 | * @param string $objectId The identifier for the object. The repository might return a different/new object id |
||
880 | * @param PropertiesInterface $properties The updated property values that must be applied to the object |
||
881 | * @param string|null $changeToken The last change token of this object that the client received. |
||
882 | * The repository might return a new change token (default is <code>null</code>) |
||
883 | * @param ExtensionDataInterface|null $extension |
||
884 | * @throws CmisInvalidArgumentException If $objectId is empty |
||
885 | */ |
||
886 | 3 | public function updateProperties( |
|
921 | } |
||
922 |