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 ContentService 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 ContentService, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 31 | class ContentService implements APIContentService, Sessionable |
||
| 32 | { |
||
| 33 | /** |
||
| 34 | * @var \eZ\Publish\Core\REST\Client\HttpClient |
||
| 35 | */ |
||
| 36 | private $client; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var \eZ\Publish\Core\REST\Common\Input\Dispatcher |
||
| 40 | */ |
||
| 41 | private $inputDispatcher; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var \eZ\Publish\Core\REST\Common\Output\Visitor |
||
| 45 | */ |
||
| 46 | private $outputVisitor; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var \eZ\Publish\Core\REST\Common\RequestParser |
||
| 50 | */ |
||
| 51 | private $requestParser; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var \eZ\Publish\Core\REST\Client\ContentTypeService |
||
| 55 | */ |
||
| 56 | private $contentTypeService; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @param \eZ\Publish\Core\REST\Client\HttpClient $client |
||
| 60 | * @param \eZ\Publish\Core\REST\Common\Input\Dispatcher $inputDispatcher |
||
| 61 | * @param \eZ\Publish\Core\REST\Common\Output\Visitor $outputVisitor |
||
| 62 | * @param \eZ\Publish\Core\REST\Common\RequestParser $requestParser |
||
| 63 | * @param \eZ\Publish\Core\REST\Client\ContentTypeService $contentTypeService |
||
| 64 | */ |
||
| 65 | View Code Duplication | public function __construct(HttpClient $client, Dispatcher $inputDispatcher, Visitor $outputVisitor, RequestParser $requestParser, ContentTypeService $contentTypeService) |
|
| 73 | |||
| 74 | /** |
||
| 75 | * Set session ID. |
||
| 76 | * |
||
| 77 | * Only for testing |
||
| 78 | * |
||
| 79 | * @param mixed $id |
||
| 80 | * |
||
| 81 | * @private |
||
| 82 | */ |
||
| 83 | public function setSession($id) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Loads a content info object. |
||
| 92 | * |
||
| 93 | * To load fields use loadContent |
||
| 94 | * |
||
| 95 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read the content |
||
| 96 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given id does not exist |
||
| 97 | * |
||
| 98 | * @param int $contentId |
||
| 99 | * |
||
| 100 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 101 | */ |
||
| 102 | public function loadContentInfo($contentId) |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Loads a content info object for the given remoteId. |
||
| 119 | * |
||
| 120 | * To load fields use loadContent |
||
| 121 | * |
||
| 122 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 123 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content with the given remote id does not exist |
||
| 124 | * |
||
| 125 | * @param string $remoteId |
||
| 126 | * |
||
| 127 | * @return \eZ\Publish\API\Repository\Values\Content\ContentInfo |
||
| 128 | */ |
||
| 129 | View Code Duplication | public function loadContentInfoByRemoteId($remoteId) |
|
| 153 | |||
| 154 | /** |
||
| 155 | * Returns a complete ContentInfo based on $restContentInfo. |
||
| 156 | * |
||
| 157 | * @param \eZ\Publish\Core\REST\Client\Values\RestContentInfo $restContentInfo |
||
| 158 | * |
||
| 159 | * @return \eZ\Publish\Core\REST\Client\Values\Content\ContentInfo |
||
| 160 | */ |
||
| 161 | protected function completeContentInfo(Values\RestContentInfo $restContentInfo) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Returns the URL of the current version referenced by |
||
| 191 | * $currentVersionReference. |
||
| 192 | * |
||
| 193 | * @param string $currentVersionReference |
||
| 194 | * |
||
| 195 | * @return string |
||
| 196 | */ |
||
| 197 | protected function fetchCurrentVersionUrl($currentVersionReference) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * Checks if the given response is an error. |
||
| 213 | * |
||
| 214 | * @param Message $response |
||
| 215 | * |
||
| 216 | * @return bool |
||
| 217 | */ |
||
| 218 | protected function isErrorResponse(Message $response) |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Loads a version info of the given content object. |
||
| 225 | * |
||
| 226 | * If no version number is given, the method returns the current version |
||
| 227 | * |
||
| 228 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 229 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 230 | * |
||
| 231 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 232 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 233 | * |
||
| 234 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 235 | */ |
||
| 236 | public function loadVersionInfo(ContentInfo $contentInfo, $versionNo = null) |
||
| 240 | |||
| 241 | /** |
||
| 242 | * Loads a version info of the given content object id. |
||
| 243 | * |
||
| 244 | * If no version number is given, the method returns the current version |
||
| 245 | * |
||
| 246 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the version with the given number does not exist |
||
| 247 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 248 | * |
||
| 249 | * @param mixed $contentId |
||
| 250 | * @param int $versionNo the version number. If not given the current version is returned. |
||
| 251 | * |
||
| 252 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo |
||
| 253 | */ |
||
| 254 | public function loadVersionInfoById($contentId, $versionNo = null) |
||
| 258 | |||
| 259 | /** |
||
| 260 | * Loads content in a version for the given content info object. |
||
| 261 | * |
||
| 262 | * If no version number is given, the method returns the current version |
||
| 263 | * |
||
| 264 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if version with the given number does not exist |
||
| 265 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 266 | * |
||
| 267 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 268 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 269 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 270 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 271 | * |
||
| 272 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 273 | */ |
||
| 274 | public function loadContentByContentInfo(ContentInfo $contentInfo, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Loads content in the version given by version info. |
||
| 285 | * |
||
| 286 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 287 | * |
||
| 288 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 289 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 290 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 291 | * |
||
| 292 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 293 | */ |
||
| 294 | public function loadContentByVersionInfo(VersionInfo $versionInfo, array $languages = null, $useAlwaysAvailable = true) |
||
| 300 | |||
| 301 | /** |
||
| 302 | * Loads content in a version of the given content object. |
||
| 303 | * |
||
| 304 | * If no version number is given, the method returns the current version |
||
| 305 | * |
||
| 306 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given id does not exist |
||
| 307 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 308 | * |
||
| 309 | * @param int $contentId |
||
| 310 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 311 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 312 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 313 | * |
||
| 314 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 315 | * |
||
| 316 | * @todo Handle $versionNo = null |
||
| 317 | * @todo Handle language filters |
||
| 318 | */ |
||
| 319 | public function loadContent($contentId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 354 | |||
| 355 | /** |
||
| 356 | * Loads content in a version for the content object reference by the given remote id. |
||
| 357 | * |
||
| 358 | * If no version is given, the method returns the current version |
||
| 359 | * |
||
| 360 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException - if the content or version with the given remote id does not exist |
||
| 361 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load this version |
||
| 362 | * |
||
| 363 | * @param string $remoteId |
||
| 364 | * @param array $languages A language filter for fields. If not given all languages are returned |
||
| 365 | * @param int $versionNo the version number. If not given the current version is returned |
||
| 366 | * @param bool $useAlwaysAvailable Add Main language to \$languages if true (default) and if alwaysAvailable is true |
||
| 367 | * |
||
| 368 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 369 | */ |
||
| 370 | public function loadContentByRemoteId($remoteId, array $languages = null, $versionNo = null, $useAlwaysAvailable = true) |
||
| 376 | |||
| 377 | /** |
||
| 378 | * Creates a new content draft assigned to the authenticated user. |
||
| 379 | * |
||
| 380 | * If a different userId is given in $contentCreateStruct it is assigned to the given user |
||
| 381 | * but this required special rights for the authenticated user |
||
| 382 | * (this is useful for content staging where the transfer process does not |
||
| 383 | * have to authenticate with the user which created the content object in the source server). |
||
| 384 | * The user has to publish the draft if it should be visible. |
||
| 385 | * In 4.x at least one location has to be provided in the location creation array. |
||
| 386 | * |
||
| 387 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the content in the given location |
||
| 388 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is a provided remoteId which exists in the system |
||
| 389 | * or there is no location provided (4.x) or multiple locations |
||
| 390 | * are under the same parent or if the a field value is not accepted by the field type |
||
| 391 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentCreateStruct is not valid |
||
| 392 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is missing |
||
| 393 | * |
||
| 394 | * @param \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct $contentCreateStruct |
||
| 395 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct[] $locationCreateStructs For each location parent under which a location should be created for the content |
||
| 396 | * |
||
| 397 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 398 | */ |
||
| 399 | public function createContent(ContentCreateStruct $contentCreateStruct, array $locationCreateStructs = array()) |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Updates the metadata. |
||
| 406 | * |
||
| 407 | * (see {@link ContentMetadataUpdateStruct}) of a content object - to update fields use updateContent |
||
| 408 | * |
||
| 409 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update the content meta data |
||
| 410 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the remoteId in $contentMetadataUpdateStruct is set but already exists |
||
| 411 | * |
||
| 412 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 413 | * @param \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct $contentMetadataUpdateStruct |
||
| 414 | * |
||
| 415 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content with the updated attributes |
||
| 416 | */ |
||
| 417 | public function updateContentMetadata(ContentInfo $contentInfo, ContentMetadataUpdateStruct $contentMetadataUpdateStruct) |
||
| 421 | |||
| 422 | /** |
||
| 423 | * Deletes a content object including all its versions and locations including their subtrees. |
||
| 424 | * |
||
| 425 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to delete the content (in one of the locations of the given content object) |
||
| 426 | * |
||
| 427 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 428 | */ |
||
| 429 | public function deleteContent(ContentInfo $contentInfo) |
||
| 433 | |||
| 434 | /** |
||
| 435 | * Creates a draft from a published or archived version. |
||
| 436 | * |
||
| 437 | * If no version is given, the current published version is used. |
||
| 438 | * 4.x: The draft is created with the initialLanguage code of the source version or if not present with the main language. |
||
| 439 | * It can be changed on updating the version. |
||
| 440 | * |
||
| 441 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to create the draft |
||
| 442 | * |
||
| 443 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 444 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 445 | * @param \eZ\Publish\API\Repository\Values\User\User $user if set given user is used to create the draft - otherwise the current user is used |
||
| 446 | * |
||
| 447 | * @return \eZ\Publish\API\Repository\Values\Content\Content - the newly created content draft |
||
| 448 | */ |
||
| 449 | public function createContentDraft(ContentInfo $contentInfo, VersionInfo $versionInfo = null, User $user = null) |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Loads drafts for a user. |
||
| 456 | * |
||
| 457 | * If no user is given the drafts for the authenticated user a returned |
||
| 458 | * |
||
| 459 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to load the draft list |
||
| 460 | * |
||
| 461 | * @param \eZ\Publish\API\Repository\Values\User\User $user |
||
| 462 | * |
||
| 463 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo the drafts ({@link VersionInfo}) owned by the given user |
||
| 464 | */ |
||
| 465 | public function loadContentDrafts(User $user = null) |
||
| 469 | |||
| 470 | /** |
||
| 471 | * Updates the fields of a draft. |
||
| 472 | * |
||
| 473 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 474 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 475 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $contentUpdateStruct is not valid |
||
| 476 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value |
||
| 477 | * |
||
| 478 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 479 | * @param \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct $contentUpdateStruct |
||
| 480 | * |
||
| 481 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the updated fields |
||
| 482 | */ |
||
| 483 | public function updateContent(VersionInfo $versionInfo, ContentUpdateStruct $contentUpdateStruct) |
||
| 487 | |||
| 488 | /** |
||
| 489 | * Publishes a content version. |
||
| 490 | * |
||
| 491 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 492 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 493 | * |
||
| 494 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 495 | * |
||
| 496 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 497 | * |
||
| 498 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to publish this version |
||
| 499 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 500 | */ |
||
| 501 | public function publishVersion(VersionInfo $versionInfo) |
||
| 505 | |||
| 506 | /** |
||
| 507 | * Removes the given version. |
||
| 508 | * |
||
| 509 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is in |
||
| 510 | * published state or is a last version of the Content |
||
| 511 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to remove this version |
||
| 512 | * |
||
| 513 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 514 | */ |
||
| 515 | public function deleteVersion(VersionInfo $versionInfo) |
||
| 519 | |||
| 520 | /** |
||
| 521 | * Loads all versions for the given content. |
||
| 522 | * |
||
| 523 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to list versions |
||
| 524 | * |
||
| 525 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 526 | * |
||
| 527 | * @return \eZ\Publish\API\Repository\Values\Content\VersionInfo[] Sorted by creation date |
||
| 528 | */ |
||
| 529 | public function loadVersions(ContentInfo $contentInfo) |
||
| 533 | |||
| 534 | /** |
||
| 535 | * Copies the content to a new location. If no version is given, |
||
| 536 | * all versions are copied, otherwise only the given version. |
||
| 537 | * |
||
| 538 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to copy the content to the given location |
||
| 539 | * |
||
| 540 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 541 | * @param \eZ\Publish\API\Repository\Values\Content\LocationCreateStruct $destinationLocationCreateStruct the target location where the content is copied to |
||
| 542 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 543 | * |
||
| 544 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 545 | */ |
||
| 546 | public function copyContent(ContentInfo $contentInfo, LocationCreateStruct $destinationLocationCreateStruct, VersionInfo $versionInfo = null) |
||
| 550 | |||
| 551 | /** |
||
| 552 | * Finds content objects for the given query. |
||
| 553 | * |
||
| 554 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
| 555 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
| 556 | * Currently supported: <code>array("languages" => array(<language1>,..))</code>. |
||
| 557 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
| 558 | * |
||
| 559 | * @return \eZ\Publish\API\Repository\Values\Content\SearchResult |
||
| 560 | */ |
||
| 561 | public function findContent(Query $query, array $languageFilter, $filterOnUserPermissions = true) |
||
| 565 | |||
| 566 | /** |
||
| 567 | * Performs a query for a single content object. |
||
| 568 | * |
||
| 569 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if the object was not found by the query or due to permissions |
||
| 570 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the query would return more than one result |
||
| 571 | * |
||
| 572 | * @param \eZ\Publish\API\Repository\Values\Content\Query $query |
||
| 573 | * @param array $languageFilter Configuration for specifying prioritized languages query will be performed on. |
||
| 574 | * Currently supported: <code>array("languages" => array(<language1>,..))</code>. |
||
| 575 | * @param bool $filterOnUserPermissions if true only the objects which is the user allowed to read are returned. |
||
| 576 | * |
||
| 577 | * @return \eZ\Publish\API\Repository\Values\Content\Content |
||
| 578 | */ |
||
| 579 | public function findSingle(Query $query, array $languageFilter, $filterOnUserPermissions = true) |
||
| 583 | |||
| 584 | /** |
||
| 585 | * Loads all outgoing relations for the given version. |
||
| 586 | * |
||
| 587 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 588 | * |
||
| 589 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $versionInfo |
||
| 590 | * |
||
| 591 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 592 | */ |
||
| 593 | public function loadRelations(VersionInfo $versionInfo) |
||
| 597 | |||
| 598 | /** |
||
| 599 | * Loads all incoming relations for a content object. |
||
| 600 | * |
||
| 601 | * The relations come only |
||
| 602 | * from published versions of the source content objects |
||
| 603 | * |
||
| 604 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to read this version |
||
| 605 | * |
||
| 606 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 607 | * |
||
| 608 | * @return \eZ\Publish\API\Repository\Values\Content\Relation[] |
||
| 609 | */ |
||
| 610 | public function loadReverseRelations(ContentInfo $contentInfo) |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Adds a relation of type common. |
||
| 617 | * |
||
| 618 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to edit this version |
||
| 619 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 620 | * |
||
| 621 | * The source of the relation is the content and version |
||
| 622 | * referenced by $versionInfo. |
||
| 623 | * |
||
| 624 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 625 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent the destination of the relation |
||
| 626 | * |
||
| 627 | * @return \eZ\Publish\API\Repository\Values\Content\Relation the newly created relation |
||
| 628 | */ |
||
| 629 | public function addRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 633 | |||
| 634 | /** |
||
| 635 | * Removes a relation of type COMMON from a draft. |
||
| 636 | * |
||
| 637 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed edit this version |
||
| 638 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the version is not a draft |
||
| 639 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if there is no relation of type COMMON for the given destination |
||
| 640 | * |
||
| 641 | * @param \eZ\Publish\API\Repository\Values\Content\VersionInfo $sourceVersion |
||
| 642 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $destinationContent |
||
| 643 | */ |
||
| 644 | public function deleteRelation(VersionInfo $sourceVersion, ContentInfo $destinationContent) |
||
| 648 | |||
| 649 | /** |
||
| 650 | * Instantiates a new content create struct object. |
||
| 651 | * |
||
| 652 | * alwaysAvailable is set to the ContentType's defaultAlwaysAvailable |
||
| 653 | * |
||
| 654 | * @param \eZ\Publish\API\Repository\Values\ContentType\ContentType $contentType |
||
| 655 | * @param string $mainLanguageCode |
||
| 656 | * |
||
| 657 | * @return \eZ\Publish\API\Repository\Values\Content\ContentCreateStruct |
||
| 658 | */ |
||
| 659 | public function newContentCreateStruct(ContentType $contentType, $mainLanguageCode) |
||
| 663 | |||
| 664 | /** |
||
| 665 | * Instantiates a new content meta data update struct. |
||
| 666 | * |
||
| 667 | * @return \eZ\Publish\API\Repository\Values\Content\ContentMetadataUpdateStruct |
||
| 668 | */ |
||
| 669 | public function newContentMetadataUpdateStruct() |
||
| 673 | |||
| 674 | /** |
||
| 675 | * Instantiates a new content update struct. |
||
| 676 | * |
||
| 677 | * @return \eZ\Publish\API\Repository\Values\Content\ContentUpdateStruct |
||
| 678 | */ |
||
| 679 | public function newContentUpdateStruct() |
||
| 683 | |||
| 684 | // Ignore this eZ Publish 5 feature by now. |
||
| 685 | |||
| 686 | // @codeCoverageIgnoreStart |
||
| 687 | |||
| 688 | /** |
||
| 689 | * Translate a version. |
||
| 690 | * |
||
| 691 | * updates the destination version given in $translationInfo with the provided translated fields in $translationValues |
||
| 692 | * |
||
| 693 | * @example Examples/translation_5x.php |
||
| 694 | * |
||
| 695 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed to update this version |
||
| 696 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the given destination version is not a draft |
||
| 697 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentValidationException if a required field is set to an empty value |
||
| 698 | * @throws \eZ\Publish\API\Repository\Exceptions\ContentFieldValidationException if a field in the $translationValues is not valid |
||
| 699 | * |
||
| 700 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 701 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationValues $translationValues |
||
| 702 | * @param \eZ\Publish\API\Repository\Values\User\User $user If set, this user is taken as modifier of the version |
||
| 703 | * |
||
| 704 | * @return \eZ\Publish\API\Repository\Values\Content\Content the content draft with the translated fields |
||
| 705 | * |
||
| 706 | * @since 5.0 |
||
| 707 | */ |
||
| 708 | public function translateVersion(TranslationInfo $translationInfo, TranslationValues $translationValues, User $user = null) |
||
| 712 | |||
| 713 | /** |
||
| 714 | * Adds translation information to the content object. |
||
| 715 | * |
||
| 716 | * @example Examples/translation_5x.php |
||
| 717 | * |
||
| 718 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed add a translation info |
||
| 719 | * |
||
| 720 | * @param \eZ\Publish\API\Repository\Values\Content\TranslationInfo $translationInfo |
||
| 721 | * |
||
| 722 | * @since 5.0 |
||
| 723 | */ |
||
| 724 | public function addTranslationInfo(TranslationInfo $translationInfo) |
||
| 728 | |||
| 729 | /** |
||
| 730 | * lists the translations done on this content object. |
||
| 731 | * |
||
| 732 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed read translation infos |
||
| 733 | * |
||
| 734 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 735 | * @param array $filter |
||
| 736 | * |
||
| 737 | * @todo TBD - filter by sourceversion destination version and languages |
||
| 738 | * |
||
| 739 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo[] |
||
| 740 | * |
||
| 741 | * @since 5.0 |
||
| 742 | */ |
||
| 743 | public function loadTranslationInfos(ContentInfo $contentInfo, array $filter = array()) |
||
| 747 | |||
| 748 | /** |
||
| 749 | * Remove Content Object translation from all Versions (including archived ones) of a Content Object. |
||
| 750 | * |
||
| 751 | * NOTE: this operation is risky and permanent, so user interface (ideally CLI) should provide |
||
| 752 | * a warning before performing it. |
||
| 753 | * |
||
| 754 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException if the specified translation |
||
| 755 | * is the only one a Version has or it is the main translation of a Content Object. |
||
| 756 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the user is not allowed |
||
| 757 | * to delete the content (in one of the locations of the given Content Object). |
||
| 758 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if languageCode argument |
||
| 759 | * is invalid for the given content. |
||
| 760 | * |
||
| 761 | * @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo |
||
| 762 | * @param string $languageCode |
||
| 763 | * |
||
| 764 | * @throws \Exception |
||
| 765 | * |
||
| 766 | * @since 6.11 |
||
| 767 | */ |
||
| 768 | public function removeTranslation(ContentInfo $contentInfo, $languageCode) |
||
| 772 | |||
| 773 | /** |
||
| 774 | * {@inheritdoc} |
||
| 775 | */ |
||
| 776 | public function deleteTranslation(VersionInfo $versionInfo, $languageCode) |
||
| 780 | |||
| 781 | /** |
||
| 782 | * Instantiates a new TranslationInfo object. |
||
| 783 | * |
||
| 784 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationInfo |
||
| 785 | */ |
||
| 786 | public function newTranslationInfo() |
||
| 790 | |||
| 791 | /** |
||
| 792 | * Instantiates a Translation object. |
||
| 793 | * |
||
| 794 | * @return \eZ\Publish\API\Repository\Values\Content\TranslationValues |
||
| 795 | */ |
||
| 796 | public function newTranslationValues() |
||
| 800 | } |
||
| 801 |
This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.
Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.