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 | ||
| 26 | class VersioningService extends AbstractBrowserBindingService implements VersioningServiceInterface | ||
| 27 | { | ||
| 28 | /** | ||
| 29 | * Reverses the effect of a check-out. | ||
| 30 | * | ||
| 31 | * @param string $repositoryId the identifier for the repository | ||
| 32 | * @param string $objectId the identifier for the PWC | ||
| 33 | * @param ExtensionDataInterface|null $extension | ||
| 34 | * @return ObjectDataInterface|null | ||
| 35 | */ | ||
| 36 | public function cancelCheckOut($repositoryId, $objectId, ExtensionDataInterface $extension = null) | ||
| 49 | |||
| 50 | /** | ||
| 51 | * Checks-in the private working copy (PWC) document. | ||
| 52 | * | ||
| 53 | * @param string $repositoryId the identifier for the repository | ||
| 54 | * @param string $objectId input: the identifier for the PWC, | ||
| 55 | * output: the identifier for the newly created version document | ||
| 56 | * @param boolean $major indicator if the new version should become a major (<code>true</code>) or minor | ||
| 57 | * (<code>false</code>) version | ||
| 58 | * @param PropertiesInterface|null $properties the property values that must be applied to the | ||
| 59 | * newly created document object | ||
| 60 | * @param StreamInterface|null $contentStream the content stream that must be stored | ||
| 61 | * for the newly created document object | ||
| 62 | * @param string|null $checkinComment a version comment | ||
| 63 | * @param string[] $policies a list of policy IDs that must be applied to the newly created document object | ||
| 64 | * @param AclInterface|null $addAces a list of ACEs that must be added to the newly created document object | ||
| 65 | * @param AclInterface|null $removeAces a list of ACEs that must be removed from the newly created document object | ||
| 66 | * @param ExtensionDataInterface|null $extension | ||
| 67 | * @return ObjectDataInterface|null | ||
| 68 | */ | ||
| 69 | public function checkIn( | ||
| 127 | |||
| 128 | /** | ||
| 129 | * Create a private working copy of the document. | ||
| 130 | * | ||
| 131 | * @param string $repositoryId the identifier for the repository | ||
| 132 | * @param string $objectId input: the identifier for the document that should be checked out, | ||
| 133 | * output: the identifier for the newly created PWC | ||
| 134 | * @param ExtensionDataInterface|null $extension | ||
| 135 | * @param boolean|null $contentCopied output: indicator if the content of the original | ||
| 136 | * document has been copied to the PWC | ||
| 137 | * @return ObjectDataInterface|null | ||
| 138 | */ | ||
| 139 | public function checkOut( | ||
| 158 | |||
| 159 | /** | ||
| 160 | * Returns the list of all document objects in the specified version series, | ||
| 161 | * sorted by the property "cmis:creationDate" descending. | ||
| 162 | * | ||
| 163 | * @param string $repositoryId the identifier for the repository | ||
| 164 | * @param string $objectId the identifier for the object | ||
| 165 | * @param string $versionSeriesId the identifier for the object | ||
| 166 | * @param string|null $filter a comma-separated list of query names that defines which properties must be | ||
| 167 | * returned by the repository (default is repository specific) | ||
| 168 | * @param boolean $includeAllowableActions if <code>true</code>, then the repository must return the allowable | ||
| 169 | * actions for the objects (default is <code>false</code>) | ||
| 170 | * @param ExtensionDataInterface|null $extension | ||
| 171 | * @return ObjectDataInterface[] the complete version history of the version series | ||
| 172 | */ | ||
| 173 | public function getAllVersions( | ||
| 189 | |||
| 190 | /** | ||
| 191 | * Get the latest document object in the version series. | ||
| 192 | * | ||
| 193 | * @param string $repositoryId the identifier for the repository | ||
| 194 | * @param string $objectId | ||
| 195 | * @param string $versionSeriesId | ||
| 196 | * @param boolean $major | ||
| 197 | * @param string|null $filter a comma-separated list of query names that defines which properties must be | ||
| 198 | * returned by the repository (default is repository specific) | ||
| 199 | * @param boolean $includeAllowableActions | ||
| 200 | * @param IncludeRelationships|null $includeRelationships indicates what relationships in which the objects | ||
| 201 | * participate must be returned (default is <code>IncludeRelationships::NONE</code>) | ||
| 202 | * @param string $renditionFilter indicates what set of renditions the repository must return whose kind | ||
| 203 | * matches this filter (default is "cmis:none") | ||
| 204 | * @param boolean $includePolicyIds if <code>true</code>, then the repository must return the policy ids for | ||
| 205 | * the object (default is <code>false</code>) | ||
| 206 | * @param boolean $includeAcl if <code>true</code>, then the repository must return the ACL for the object | ||
| 207 | * (default is <code>false</code>) | ||
| 208 | * @param ExtensionDataInterface|null $extension | ||
| 209 | * @return ObjectDataInterface | ||
| 210 | */ | ||
| 211 | public function getObjectOfLatestVersion( | ||
| 232 | |||
| 233 | /** | ||
| 234 | * Get a subset of the properties for the latest document object in the version series. | ||
| 235 | * | ||
| 236 | * @param string $repositoryId the identifier for the repository | ||
| 237 | * @param string $objectId The identifier for the object | ||
| 238 | * @param string $versionSeriesId The identifier for the version series. | ||
| 239 | * @param boolean $major If <code>true</code>, then the repository MUST return the properties for the latest | ||
| 240 | * major version object in the version series. | ||
| 241 | * If <code>false</code>, the repository MUST return the properties for the latest | ||
| 242 | * (major or non-major) version object in the version series. | ||
| 243 | * @param string|null $filter a comma-separated list of query names that defines which properties must be | ||
| 244 | * returned by the repository (default is repository specific) | ||
| 245 | * @param ExtensionDataInterface|null $extension | ||
| 246 | * @return PropertiesInterface | ||
| 247 | */ | ||
| 248 | public function getPropertiesOfLatestVersion( | ||
| 265 | |||
| 266 | /** | ||
| 267 | * @param string $action | ||
| 268 | * @param array $parameters | ||
| 269 | * @param ExtensionDataInterface $extension | ||
| 270 | * @return array | ||
| 271 | */ | ||
| 272 | protected function createQueryArray( | ||
| 286 | |||
| 287 | } | ||
| 288 | 
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: