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 Repository 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 Repository, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | class Repository implements RepositoryInterface |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * Repository Handler object. |
||
| 34 | * |
||
| 35 | * @var \eZ\Publish\SPI\Persistence\Handler |
||
| 36 | */ |
||
| 37 | protected $persistenceHandler; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Instance of main Search Handler. |
||
| 41 | * |
||
| 42 | * @var \eZ\Publish\SPI\Search\Handler |
||
| 43 | */ |
||
| 44 | protected $searchHandler; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Currently logged in user object if already loaded. |
||
| 48 | * |
||
| 49 | * @var \eZ\Publish\API\Repository\Values\User\User|null |
||
| 50 | */ |
||
| 51 | protected $currentUser; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Currently logged in user reference for permission purposes. |
||
| 55 | * |
||
| 56 | * @var \eZ\Publish\API\Repository\Values\User\UserReference |
||
| 57 | */ |
||
| 58 | protected $currentUserRef; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Counter for the current sudo nesting level {@see sudo()}. |
||
| 62 | * |
||
| 63 | * @var int |
||
| 64 | */ |
||
| 65 | private $sudoNestingLevel = 0; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Instance of content service. |
||
| 69 | * |
||
| 70 | * @var \eZ\Publish\API\Repository\ContentService |
||
| 71 | */ |
||
| 72 | protected $contentService; |
||
| 73 | |||
| 74 | /** |
||
| 75 | * Instance of section service. |
||
| 76 | * |
||
| 77 | * @var \eZ\Publish\API\Repository\SectionService |
||
| 78 | */ |
||
| 79 | protected $sectionService; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Instance of role service. |
||
| 83 | * |
||
| 84 | * @var \eZ\Publish\API\Repository\RoleService |
||
| 85 | */ |
||
| 86 | protected $roleService; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Instance of search service. |
||
| 90 | * |
||
| 91 | * @var \eZ\Publish\API\Repository\SearchService |
||
| 92 | */ |
||
| 93 | protected $searchService; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * Instance of user service. |
||
| 97 | * |
||
| 98 | * @var \eZ\Publish\API\Repository\UserService |
||
| 99 | */ |
||
| 100 | protected $userService; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * Instance of language service. |
||
| 104 | * |
||
| 105 | * @var \eZ\Publish\API\Repository\LanguageService |
||
| 106 | */ |
||
| 107 | protected $languageService; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Instance of location service. |
||
| 111 | * |
||
| 112 | * @var \eZ\Publish\API\Repository\LocationService |
||
| 113 | */ |
||
| 114 | protected $locationService; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * Instance of Trash service. |
||
| 118 | * |
||
| 119 | * @var \eZ\Publish\API\Repository\TrashService |
||
| 120 | */ |
||
| 121 | protected $trashService; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * Instance of content type service. |
||
| 125 | * |
||
| 126 | * @var \eZ\Publish\API\Repository\ContentTypeService |
||
| 127 | */ |
||
| 128 | protected $contentTypeService; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * Instance of object state service. |
||
| 132 | * |
||
| 133 | * @var \eZ\Publish\API\Repository\ObjectStateService |
||
| 134 | */ |
||
| 135 | protected $objectStateService; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Instance of field type service. |
||
| 139 | * |
||
| 140 | * @var \eZ\Publish\API\Repository\FieldTypeService |
||
| 141 | */ |
||
| 142 | protected $fieldTypeService; |
||
| 143 | |||
| 144 | /** |
||
| 145 | * Instance of FieldTypeRegistry. |
||
| 146 | * |
||
| 147 | * @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry |
||
| 148 | */ |
||
| 149 | private $fieldTypeRegistry; |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Instance of NameableFieldTypeRegistry. |
||
| 153 | * |
||
| 154 | * @var \eZ\Publish\Core\Repository\Helper\NameableFieldTypeRegistry |
||
| 155 | */ |
||
| 156 | private $nameableFieldTypeRegistry; |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Instance of name schema resolver service. |
||
| 160 | * |
||
| 161 | * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService |
||
| 162 | */ |
||
| 163 | protected $nameSchemaService; |
||
| 164 | |||
| 165 | /** |
||
| 166 | * Instance of relation processor service. |
||
| 167 | * |
||
| 168 | * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor |
||
| 169 | */ |
||
| 170 | protected $relationProcessor; |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Instance of URL alias service. |
||
| 174 | * |
||
| 175 | * @var \eZ\Publish\Core\Repository\URLAliasService |
||
| 176 | */ |
||
| 177 | protected $urlAliasService; |
||
| 178 | |||
| 179 | /** |
||
| 180 | * Instance of URL wildcard service. |
||
| 181 | * |
||
| 182 | * @var \eZ\Publish\Core\Repository\URLWildcardService |
||
| 183 | */ |
||
| 184 | protected $urlWildcardService; |
||
| 185 | |||
| 186 | /** |
||
| 187 | * Service settings, first level key is service name. |
||
| 188 | * |
||
| 189 | * @var array |
||
| 190 | */ |
||
| 191 | protected $serviceSettings; |
||
| 192 | |||
| 193 | /** |
||
| 194 | * Instance of role service. |
||
| 195 | * |
||
| 196 | * @var \eZ\Publish\Core\Repository\Helper\LimitationService |
||
| 197 | */ |
||
| 198 | protected $limitationService; |
||
| 199 | |||
| 200 | /** |
||
| 201 | * @var \eZ\Publish\Core\Repository\Helper\RoleDomainMapper |
||
| 202 | */ |
||
| 203 | protected $roleDomainMapper; |
||
| 204 | |||
| 205 | /** |
||
| 206 | * Instance of domain mapper. |
||
| 207 | * |
||
| 208 | * @var \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
| 209 | */ |
||
| 210 | protected $domainMapper; |
||
| 211 | |||
| 212 | /** |
||
| 213 | * Instance of content type domain mapper. |
||
| 214 | * |
||
| 215 | * @var \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper |
||
| 216 | */ |
||
| 217 | protected $contentTypeDomainMapper; |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Instance of permissions criterion handler. |
||
| 221 | * |
||
| 222 | * @var \eZ\Publish\Core\Repository\PermissionsCriterionHandler |
||
| 223 | */ |
||
| 224 | protected $permissionsCriterionHandler; |
||
| 225 | |||
| 226 | /** |
||
| 227 | * Array of arrays of commit events indexed by the transaction count. |
||
| 228 | * |
||
| 229 | * @var array |
||
| 230 | */ |
||
| 231 | protected $commitEventsQueue = array(); |
||
| 232 | |||
| 233 | /** |
||
| 234 | * @var int |
||
| 235 | */ |
||
| 236 | protected $transactionDepth = 0; |
||
| 237 | |||
| 238 | /** |
||
| 239 | * @var int |
||
| 240 | */ |
||
| 241 | private $transactionCount = 0; |
||
| 242 | |||
| 243 | /** |
||
| 244 | * Constructor. |
||
| 245 | * |
||
| 246 | * Construct repository object with provided storage engine |
||
| 247 | * |
||
| 248 | * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler |
||
| 249 | * @param \eZ\Publish\SPI\Search\Handler $searchHandler |
||
| 250 | * @param array $serviceSettings |
||
| 251 | * @param \eZ\Publish\API\Repository\Values\User\UserReference|null $user |
||
| 252 | */ |
||
| 253 | public function __construct( |
||
| 254 | PersistenceHandler $persistenceHandler, |
||
| 255 | SearchHandler $searchHandler, |
||
| 256 | array $serviceSettings = array(), |
||
| 257 | APIUserReference $user = null |
||
| 258 | ) { |
||
| 259 | $this->persistenceHandler = $persistenceHandler; |
||
| 260 | $this->searchHandler = $searchHandler; |
||
| 261 | $this->serviceSettings = $serviceSettings + array( |
||
| 262 | 'content' => array(), |
||
| 263 | 'contentType' => array(), |
||
| 264 | 'location' => array(), |
||
| 265 | 'section' => array(), |
||
| 266 | 'role' => array(), |
||
| 267 | 'user' => array( |
||
| 268 | 'anonymousUserID' => 10, |
||
| 269 | ), |
||
| 270 | 'language' => array(), |
||
| 271 | 'trash' => array(), |
||
| 272 | 'io' => array(), |
||
| 273 | 'objectState' => array(), |
||
| 274 | 'search' => array(), |
||
| 275 | 'fieldType' => array(), |
||
| 276 | 'nameableFieldTypes' => array(), |
||
| 277 | 'urlAlias' => array(), |
||
| 278 | 'urlWildcard' => array(), |
||
| 279 | 'nameSchema' => array(), |
||
| 280 | 'languages' => array(), |
||
| 281 | ); |
||
| 282 | |||
| 283 | if (!empty($this->serviceSettings['languages'])) { |
||
| 284 | $this->serviceSettings['language']['languages'] = $this->serviceSettings['languages']; |
||
| 285 | } |
||
| 286 | |||
| 287 | if ($user instanceof User) { |
||
| 288 | $this->currentUser = $user; |
||
| 289 | $this->currentUserRef = new UserReference($user->getUserId()); |
||
| 290 | } elseif ($user instanceof APIUserReference) { |
||
| 291 | $this->currentUserRef = $user; |
||
| 292 | } else { |
||
| 293 | $this->currentUserRef = new UserReference($this->serviceSettings['user']['anonymousUserID']); |
||
| 294 | } |
||
| 295 | } |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Get current user. |
||
| 299 | * |
||
| 300 | * Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()} |
||
| 301 | * |
||
| 302 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
| 303 | */ |
||
| 304 | public function getCurrentUser() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * Get current user reference. |
||
| 317 | * |
||
| 318 | * @since 5.4.5 |
||
| 319 | * @return \eZ\Publish\API\Repository\Values\User\UserReference |
||
| 320 | */ |
||
| 321 | public function getCurrentUserReference() |
||
| 325 | |||
| 326 | /** |
||
| 327 | * Sets the current user to the given $user. |
||
| 328 | * |
||
| 329 | * @param \eZ\Publish\API\Repository\Values\User\UserReference $user |
||
| 330 | * |
||
| 331 | * @throws InvalidArgumentValue If UserReference does not contain a id |
||
| 332 | */ |
||
| 333 | public function setCurrentUser(APIUserReference $user) |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Allows API execution to be performed with full access sand-boxed. |
||
| 351 | * |
||
| 352 | * The closure sandbox will do a catch all on exceptions and rethrow after |
||
| 353 | * re-setting the sudo flag. |
||
| 354 | * |
||
| 355 | * Example use: |
||
| 356 | * $location = $repository->sudo( |
||
| 357 | * function ( Repository $repo ) use ( $locationId ) |
||
| 358 | * { |
||
| 359 | * return $repo->getLocationService()->loadLocation( $locationId ) |
||
| 360 | * } |
||
| 361 | * ); |
||
| 362 | * |
||
| 363 | * |
||
| 364 | * @param \Closure $callback |
||
| 365 | * @param \eZ\Publish\API\Repository\Repository $outerRepository |
||
| 366 | * |
||
| 367 | * @throws \RuntimeException Thrown on recursive sudo() use. |
||
| 368 | * @throws \Exception Re throws exceptions thrown inside $callback |
||
| 369 | * |
||
| 370 | * @return mixed |
||
| 371 | */ |
||
| 372 | public function sudo(\Closure $callback, RepositoryInterface $outerRepository = null) |
||
| 386 | |||
| 387 | /** |
||
| 388 | * Check if user has access to a given module / function. |
||
| 389 | * |
||
| 390 | * Low level function, use canUser instead if you have objects to check against. |
||
| 391 | * |
||
| 392 | * @param string $module |
||
| 393 | * @param string $function |
||
| 394 | * @param \eZ\Publish\API\Repository\Values\User\UserReference $user |
||
| 395 | * |
||
| 396 | * @return bool|array Bool if user has full or no access, array if limitations if not |
||
| 397 | */ |
||
| 398 | public function hasAccess($module, $function, APIUserReference $user = null) |
||
| 459 | |||
| 460 | /** |
||
| 461 | * Check if user has access to a given action on a given value object. |
||
| 462 | * |
||
| 463 | * Indicates if the current user is allowed to perform an action given by the function on the given |
||
| 464 | * objects. |
||
| 465 | * |
||
| 466 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If any of the arguments are invalid |
||
| 467 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If value of the LimitationValue is unsupported |
||
| 468 | * |
||
| 469 | * @param string $module The module, aka controller identifier to check permissions on |
||
| 470 | * @param string $function The function, aka the controller action to check permissions on |
||
| 471 | * @param \eZ\Publish\API\Repository\Values\ValueObject $object The object to check if the user has access to |
||
| 472 | * @param mixed $targets The location, parent or "assignment" value object, or an array of the same |
||
| 473 | * |
||
| 474 | * @return bool |
||
| 475 | */ |
||
| 476 | public function canUser($module, $function, ValueObject $object, $targets = null) |
||
| 561 | |||
| 562 | /** |
||
| 563 | * Get Content Service. |
||
| 564 | * |
||
| 565 | * Get service object to perform operations on Content objects and it's aggregate members. |
||
| 566 | * |
||
| 567 | * @return \eZ\Publish\API\Repository\ContentService |
||
| 568 | */ |
||
| 569 | View Code Duplication | public function getContentService() |
|
| 587 | |||
| 588 | /** |
||
| 589 | * Get Content Language Service. |
||
| 590 | * |
||
| 591 | * Get service object to perform operations on Content language objects |
||
| 592 | * |
||
| 593 | * @return \eZ\Publish\API\Repository\LanguageService |
||
| 594 | */ |
||
| 595 | public function getContentLanguageService() |
||
| 609 | |||
| 610 | /** |
||
| 611 | * Get Content Type Service. |
||
| 612 | * |
||
| 613 | * Get service object to perform operations on Content Type objects and it's aggregate members. |
||
| 614 | * ( Group, Field & FieldCategory ) |
||
| 615 | * |
||
| 616 | * @return \eZ\Publish\API\Repository\ContentTypeService |
||
| 617 | */ |
||
| 618 | View Code Duplication | public function getContentTypeService() |
|
| 619 | { |
||
| 620 | if ($this->contentTypeService !== null) { |
||
| 621 | return $this->contentTypeService; |
||
| 622 | } |
||
| 623 | |||
| 624 | $this->contentTypeService = new ContentTypeService( |
||
| 625 | $this, |
||
| 626 | $this->persistenceHandler->contentTypeHandler(), |
||
| 627 | $this->getDomainMapper(), |
||
| 628 | $this->getContentTypeDomainMapper(), |
||
| 629 | $this->getFieldTypeRegistry(), |
||
| 630 | $this->serviceSettings['contentType'] |
||
| 631 | ); |
||
| 632 | |||
| 633 | return $this->contentTypeService; |
||
| 634 | } |
||
| 635 | |||
| 636 | /** |
||
| 637 | * Get Content Location Service. |
||
| 638 | * |
||
| 639 | * Get service object to perform operations on Location objects and subtrees |
||
| 640 | * |
||
| 641 | * @return \eZ\Publish\API\Repository\LocationService |
||
| 642 | */ |
||
| 643 | public function getLocationService() |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Get Content Trash service. |
||
| 663 | * |
||
| 664 | * Trash service allows to perform operations related to location trash |
||
| 665 | * (trash/untrash, load/list from trash...) |
||
| 666 | * |
||
| 667 | * @return \eZ\Publish\API\Repository\TrashService |
||
| 668 | */ |
||
| 669 | public function getTrashService() |
||
| 684 | |||
| 685 | /** |
||
| 686 | * Get Content Section Service. |
||
| 687 | * |
||
| 688 | * Get Section service that lets you manipulate section objects |
||
| 689 | * |
||
| 690 | * @return \eZ\Publish\API\Repository\SectionService |
||
| 691 | */ |
||
| 692 | public function getSectionService() |
||
| 706 | |||
| 707 | /** |
||
| 708 | * Get User Service. |
||
| 709 | * |
||
| 710 | * Get service object to perform operations on Users and UserGroup |
||
| 711 | * |
||
| 712 | * @return \eZ\Publish\API\Repository\UserService |
||
| 713 | */ |
||
| 714 | public function getUserService() |
||
| 728 | |||
| 729 | /** |
||
| 730 | * Get URLAliasService. |
||
| 731 | * |
||
| 732 | * @return \eZ\Publish\API\Repository\URLAliasService |
||
| 733 | */ |
||
| 734 | public function getURLAliasService() |
||
| 748 | |||
| 749 | /** |
||
| 750 | * Get URLWildcardService. |
||
| 751 | * |
||
| 752 | * @return \eZ\Publish\API\Repository\URLWildcardService |
||
| 753 | */ |
||
| 754 | public function getURLWildcardService() |
||
| 768 | |||
| 769 | /** |
||
| 770 | * Get ObjectStateService. |
||
| 771 | * |
||
| 772 | * @return \eZ\Publish\API\Repository\ObjectStateService |
||
| 773 | */ |
||
| 774 | public function getObjectStateService() |
||
| 788 | |||
| 789 | /** |
||
| 790 | * Get RoleService. |
||
| 791 | * |
||
| 792 | * @return \eZ\Publish\API\Repository\RoleService |
||
| 793 | */ |
||
| 794 | public function getRoleService() |
||
| 810 | |||
| 811 | /** |
||
| 812 | * Get LimitationService. |
||
| 813 | * |
||
| 814 | * @return \eZ\Publish\Core\Repository\Helper\LimitationService |
||
| 815 | */ |
||
| 816 | protected function getLimitationService() |
||
| 826 | |||
| 827 | /** |
||
| 828 | * Get RoleDomainMapper. |
||
| 829 | * |
||
| 830 | * @return \eZ\Publish\Core\Repository\Helper\RoleDomainMapper |
||
| 831 | */ |
||
| 832 | protected function getRoleDomainMapper() |
||
| 842 | |||
| 843 | /** |
||
| 844 | * Get SearchService. |
||
| 845 | * |
||
| 846 | * @return \eZ\Publish\API\Repository\SearchService |
||
| 847 | */ |
||
| 848 | public function getSearchService() |
||
| 864 | |||
| 865 | /** |
||
| 866 | * Get FieldTypeService. |
||
| 867 | * |
||
| 868 | * @return \eZ\Publish\API\Repository\FieldTypeService |
||
| 869 | */ |
||
| 870 | public function getFieldTypeService() |
||
| 880 | |||
| 881 | /** |
||
| 882 | * @return Helper\FieldTypeRegistry |
||
| 883 | */ |
||
| 884 | protected function getFieldTypeRegistry() |
||
| 894 | |||
| 895 | /** |
||
| 896 | * @return Helper\NameableFieldTypeRegistry |
||
| 897 | */ |
||
| 898 | protected function getNameableFieldTypeRegistry() |
||
| 899 | { |
||
| 900 | if ($this->nameableFieldTypeRegistry !== null) { |
||
| 901 | return $this->nameableFieldTypeRegistry; |
||
| 902 | } |
||
| 903 | |||
| 904 | $this->nameableFieldTypeRegistry = new Helper\NameableFieldTypeRegistry($this->serviceSettings['nameableFieldTypes']); |
||
| 905 | |||
| 906 | return $this->nameableFieldTypeRegistry; |
||
| 907 | } |
||
| 908 | |||
| 909 | /** |
||
| 910 | * Get NameSchemaResolverService. |
||
| 911 | * |
||
| 912 | * |
||
| 913 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
| 914 | * |
||
| 915 | * @internal |
||
| 916 | * @private |
||
| 917 | * |
||
| 918 | * @return \eZ\Publish\Core\Repository\Helper\NameSchemaService |
||
| 919 | */ |
||
| 920 | public function getNameSchemaService() |
||
| 921 | { |
||
| 922 | if ($this->nameSchemaService !== null) { |
||
| 923 | return $this->nameSchemaService; |
||
| 924 | } |
||
| 925 | |||
| 926 | $this->nameSchemaService = new Helper\NameSchemaService( |
||
| 927 | $this->persistenceHandler->contentTypeHandler(), |
||
| 928 | $this->getContentTypeDomainMapper(), |
||
| 929 | $this->getNameableFieldTypeRegistry(), |
||
| 930 | $this->serviceSettings['nameSchema'] |
||
| 931 | ); |
||
| 932 | |||
| 933 | return $this->nameSchemaService; |
||
| 934 | } |
||
| 935 | |||
| 936 | /** |
||
| 937 | * Get RelationProcessor. |
||
| 938 | * |
||
| 939 | * |
||
| 940 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
| 941 | * |
||
| 942 | * @return \eZ\Publish\Core\Repository\Helper\RelationProcessor |
||
| 943 | */ |
||
| 944 | protected function getRelationProcessor() |
||
| 945 | { |
||
| 946 | if ($this->relationProcessor !== null) { |
||
| 947 | return $this->relationProcessor; |
||
| 948 | } |
||
| 949 | |||
| 950 | $this->relationProcessor = new Helper\RelationProcessor($this->persistenceHandler); |
||
| 951 | |||
| 952 | return $this->relationProcessor; |
||
| 953 | } |
||
| 954 | |||
| 955 | /** |
||
| 956 | * Get Content Domain Mapper. |
||
| 957 | * |
||
| 958 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
| 959 | * |
||
| 960 | * @return \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
| 961 | */ |
||
| 962 | protected function getDomainMapper() |
||
| 978 | |||
| 979 | /** |
||
| 980 | * Get ContentType Domain Mapper. |
||
| 981 | * |
||
| 982 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
| 983 | * |
||
| 984 | * @return \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper |
||
| 985 | */ |
||
| 986 | protected function getContentTypeDomainMapper() |
||
| 987 | { |
||
| 988 | if ($this->contentTypeDomainMapper !== null) { |
||
| 989 | return $this->contentTypeDomainMapper; |
||
| 990 | } |
||
| 991 | |||
| 992 | $this->contentTypeDomainMapper = new Helper\ContentTypeDomainMapper( |
||
| 993 | $this->persistenceHandler->contentLanguageHandler(), |
||
| 994 | $this->getFieldTypeRegistry() |
||
| 995 | ); |
||
| 996 | |||
| 997 | return $this->contentTypeDomainMapper; |
||
| 998 | } |
||
| 999 | |||
| 1000 | /** |
||
| 1001 | * Get PermissionsCriterionHandler. |
||
| 1002 | * |
||
| 1003 | * |
||
| 1004 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
| 1005 | * |
||
| 1006 | * @return \eZ\Publish\Core\Repository\PermissionsCriterionHandler |
||
| 1007 | */ |
||
| 1008 | protected function getPermissionsCriterionHandler() |
||
| 1014 | |||
| 1015 | /** |
||
| 1016 | * Begin transaction. |
||
| 1017 | * |
||
| 1018 | * Begins an transaction, make sure you'll call commit or rollback when done, |
||
| 1019 | * otherwise work will be lost. |
||
| 1020 | */ |
||
| 1021 | public function beginTransaction() |
||
| 1028 | |||
| 1029 | /** |
||
| 1030 | * Commit transaction. |
||
| 1031 | * |
||
| 1032 | * Commit transaction, or throw exceptions if no transactions has been started. |
||
| 1033 | * |
||
| 1034 | * @throws RuntimeException If no transaction has been started |
||
| 1035 | */ |
||
| 1036 | public function commit() |
||
| 1065 | |||
| 1066 | /** |
||
| 1067 | * Rollback transaction. |
||
| 1068 | * |
||
| 1069 | * Rollback transaction, or throw exceptions if no transactions has been started. |
||
| 1070 | * |
||
| 1071 | * @throws RuntimeException If no transaction has been started |
||
| 1072 | */ |
||
| 1073 | public function rollback() |
||
| 1084 | |||
| 1085 | /** |
||
| 1086 | * Enqueue an event to be triggered at commit or directly if no transaction has started. |
||
| 1087 | * |
||
| 1088 | * @param Callable $event |
||
| 1089 | */ |
||
| 1090 | public function commitEvent($event) |
||
| 1099 | |||
| 1100 | /** |
||
| 1101 | * Only for internal use. |
||
| 1102 | * |
||
| 1103 | * Creates a \DateTime object for $timestamp in the current time zone |
||
| 1104 | * |
||
| 1105 | * @param int $timestamp |
||
| 1106 | * |
||
| 1107 | * @return \DateTime |
||
| 1108 | */ |
||
| 1109 | View Code Duplication | public function createDateTime($timestamp = null) |
|
| 1118 | } |
||
| 1119 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.