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:
| 1 | <?php |
||
| 27 | class ContentService implements ContentServiceInterface |
||
| 28 | { |
||
| 29 | /** |
||
| 30 | * Aggregated service. |
||
| 31 | * |
||
| 32 | * @var \eZ\Publish\API\Repository\ContentService |
||
| 33 | */ |
||
| 34 | protected $service; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * Language resolver |
||
| 38 | * |
||
| 39 | * @var LanguageResolver |
||
| 40 | */ |
||
| 41 | protected $languageResolver; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Construct service object from aggregated service and LanguageResolver. |
||
| 45 | * |
||
| 46 | * @param \eZ\Publish\API\Repository\ContentService $service |
||
| 47 | * @param LanguageResolver $languageResolver |
||
| 48 | */ |
||
| 49 | public function __construct( |
||
| 56 | |||
| 57 | public function loadContentInfo($contentId) |
||
| 61 | |||
| 62 | function loadContentInfoByRemoteId($remoteId) |
||
| 66 | |||
| 67 | public function loadVersionInfo(APIContentInfo $contentInfo, $versionNo = null) |
||
| 71 | |||
| 72 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
| 76 | |||
| 77 | View Code Duplication | public function loadContentByContentInfo(APIContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
|
| 88 | |||
| 89 | public function loadContentByVersionInfo(APIVersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
| 95 | |||
| 96 | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 107 | |||
| 108 | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 119 | |||
| 120 | public function createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array()) |
||
| 124 | |||
| 125 | public function updateContentMetadata(APIContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 129 | |||
| 130 | public function deleteContent(APIContentInfo $contentInfo) |
||
| 134 | |||
| 135 | public function createContentDraft(APIContentInfo $contentInfo, APIVersionInfo $versionInfo = null, User $user = null) |
||
| 139 | |||
| 140 | public function loadContentDrafts(User $user = null) |
||
| 144 | |||
| 145 | public function translateVersion(TranslationInfo $translationInfo, TranslationValues $translationValues, User $user = null) |
||
| 149 | |||
| 150 | public function updateContent(APIVersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct) |
||
| 154 | |||
| 155 | public function publishVersion(APIVersionInfo $versionInfo) |
||
| 159 | |||
| 160 | public function deleteVersion(APIVersionInfo $versionInfo) |
||
| 164 | |||
| 165 | public function loadVersions(APIContentInfo $contentInfo) |
||
| 169 | |||
| 170 | public function copyContent(APIContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, APIVersionInfo $versionInfo = null) |
||
| 174 | |||
| 175 | public function loadRelations(APIVersionInfo $versionInfo) |
||
| 179 | |||
| 180 | public function loadReverseRelations(APIContentInfo $contentInfo) |
||
| 184 | |||
| 185 | public function addRelation(APIVersionInfo $sourceVersion, APIContentInfo $destinationContent) |
||
| 189 | |||
| 190 | public function deleteRelation(APIVersionInfo $sourceVersion, APIContentInfo $destinationContent) |
||
| 194 | |||
| 195 | public function addTranslationInfo(TranslationInfo $translationInfo) |
||
| 199 | |||
| 200 | public function loadTranslationInfos(APIContentInfo $contentInfo, array $filter = array()) |
||
| 204 | |||
| 205 | public function removeTranslation(APIContentInfo $contentInfo, $languageCode) |
||
| 209 | |||
| 210 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 214 | |||
| 215 | public function newContentMetadataUpdateStruct() |
||
| 219 | |||
| 220 | public function newContentUpdateStruct() |
||
| 224 | |||
| 225 | public function newTranslationInfo() |
||
| 229 | |||
| 230 | public function newTranslationValues() |
||
| 234 | } |
||
| 235 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.