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 | * @deprecated since 6.6, to be removed. Current user handling is moved to PermissionResolver. |
||
| 48 | * |
||
| 49 | * Currently logged in user object if already loaded. |
||
| 50 | * |
||
| 51 | * @var \eZ\Publish\API\Repository\Values\User\User|null |
||
| 52 | */ |
||
| 53 | protected $currentUser; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @deprecated since 6.6, to be removed. Current user handling is moved to PermissionResolver. |
||
| 57 | * |
||
| 58 | * Currently logged in user reference for permission purposes. |
||
| 59 | * |
||
| 60 | * @var \eZ\Publish\API\Repository\Values\User\UserReference |
||
| 61 | */ |
||
| 62 | protected $currentUserRef; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Instance of content service. |
||
| 66 | * |
||
| 67 | * @var \eZ\Publish\API\Repository\ContentService |
||
| 68 | */ |
||
| 69 | protected $contentService; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Instance of section service. |
||
| 73 | * |
||
| 74 | * @var \eZ\Publish\API\Repository\SectionService |
||
| 75 | */ |
||
| 76 | protected $sectionService; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Instance of role service. |
||
| 80 | * |
||
| 81 | * @var \eZ\Publish\API\Repository\RoleService |
||
| 82 | */ |
||
| 83 | protected $roleService; |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Instance of search service. |
||
| 87 | * |
||
| 88 | * @var \eZ\Publish\API\Repository\SearchService |
||
| 89 | */ |
||
| 90 | protected $searchService; |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Instance of user service. |
||
| 94 | * |
||
| 95 | * @var \eZ\Publish\API\Repository\UserService |
||
| 96 | */ |
||
| 97 | protected $userService; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Instance of language service. |
||
| 101 | * |
||
| 102 | * @var \eZ\Publish\API\Repository\LanguageService |
||
| 103 | */ |
||
| 104 | protected $languageService; |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Instance of location service. |
||
| 108 | * |
||
| 109 | * @var \eZ\Publish\API\Repository\LocationService |
||
| 110 | */ |
||
| 111 | protected $locationService; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Instance of Trash service. |
||
| 115 | * |
||
| 116 | * @var \eZ\Publish\API\Repository\TrashService |
||
| 117 | */ |
||
| 118 | protected $trashService; |
||
| 119 | |||
| 120 | /** |
||
| 121 | * Instance of content type service. |
||
| 122 | * |
||
| 123 | * @var \eZ\Publish\API\Repository\ContentTypeService |
||
| 124 | */ |
||
| 125 | protected $contentTypeService; |
||
| 126 | |||
| 127 | /** |
||
| 128 | * Instance of object state service. |
||
| 129 | * |
||
| 130 | * @var \eZ\Publish\API\Repository\ObjectStateService |
||
| 131 | */ |
||
| 132 | protected $objectStateService; |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Instance of field type service. |
||
| 136 | * |
||
| 137 | * @var \eZ\Publish\API\Repository\FieldTypeService |
||
| 138 | */ |
||
| 139 | protected $fieldTypeService; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * Instance of FieldTypeRegistry. |
||
| 143 | * |
||
| 144 | * @var \eZ\Publish\Core\Repository\Helper\FieldTypeRegistry |
||
| 145 | */ |
||
| 146 | private $fieldTypeRegistry; |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Instance of NameableFieldTypeRegistry. |
||
| 150 | * |
||
| 151 | * @var \eZ\Publish\Core\Repository\Helper\NameableFieldTypeRegistry |
||
| 152 | */ |
||
| 153 | private $nameableFieldTypeRegistry; |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Instance of name schema resolver service. |
||
| 157 | * |
||
| 158 | * @var \eZ\Publish\Core\Repository\Helper\NameSchemaService |
||
| 159 | */ |
||
| 160 | protected $nameSchemaService; |
||
| 161 | |||
| 162 | /** |
||
| 163 | * Instance of relation processor service. |
||
| 164 | * |
||
| 165 | * @var \eZ\Publish\Core\Repository\Helper\RelationProcessor |
||
| 166 | */ |
||
| 167 | protected $relationProcessor; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Instance of URL alias service. |
||
| 171 | * |
||
| 172 | * @var \eZ\Publish\Core\Repository\URLAliasService |
||
| 173 | */ |
||
| 174 | protected $urlAliasService; |
||
| 175 | |||
| 176 | /** |
||
| 177 | * Instance of URL wildcard service. |
||
| 178 | * |
||
| 179 | * @var \eZ\Publish\Core\Repository\URLWildcardService |
||
| 180 | */ |
||
| 181 | protected $urlWildcardService; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * Instance of URL service. |
||
| 185 | * |
||
| 186 | * @var \eZ\Publish\Core\Repository\URLService |
||
| 187 | */ |
||
| 188 | protected $urlService; |
||
| 189 | |||
| 190 | /** |
||
| 191 | * Service settings, first level key is service name. |
||
| 192 | * |
||
| 193 | * @var array |
||
| 194 | */ |
||
| 195 | protected $serviceSettings; |
||
| 196 | |||
| 197 | /** |
||
| 198 | * Instance of role service. |
||
| 199 | * |
||
| 200 | * @var \eZ\Publish\Core\Repository\Helper\LimitationService |
||
| 201 | */ |
||
| 202 | protected $limitationService; |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @var \eZ\Publish\Core\Repository\Helper\RoleDomainMapper |
||
| 206 | */ |
||
| 207 | protected $roleDomainMapper; |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Instance of domain mapper. |
||
| 211 | * |
||
| 212 | * @var \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
| 213 | */ |
||
| 214 | protected $domainMapper; |
||
| 215 | |||
| 216 | /** |
||
| 217 | * Instance of content type domain mapper. |
||
| 218 | * |
||
| 219 | * @var \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper |
||
| 220 | */ |
||
| 221 | protected $contentTypeDomainMapper; |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Instance of permissions-resolver and -criterion resolver. |
||
| 225 | * |
||
| 226 | * @var \eZ\Publish\API\Repository\PermissionCriterionResolver|\eZ\Publish\API\Repository\PermissionResolver |
||
| 227 | */ |
||
| 228 | protected $permissionsHandler; |
||
| 229 | |||
| 230 | /** |
||
| 231 | * @var \eZ\Publish\Core\Search\Common\BackgroundIndexer|null |
||
| 232 | */ |
||
| 233 | protected $backgroundIndexer; |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Array of arrays of commit events indexed by the transaction count. |
||
| 237 | * |
||
| 238 | * @var array |
||
| 239 | */ |
||
| 240 | protected $commitEventsQueue = []; |
||
| 241 | |||
| 242 | /** |
||
| 243 | * @var int |
||
| 244 | */ |
||
| 245 | protected $transactionDepth = 0; |
||
| 246 | |||
| 247 | /** |
||
| 248 | * @var int |
||
| 249 | */ |
||
| 250 | private $transactionCount = 0; |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @var \Psr\Log\LoggerInterface |
||
| 254 | */ |
||
| 255 | private $logger; |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Constructor. |
||
| 259 | * |
||
| 260 | * Construct repository object with provided storage engine |
||
| 261 | * |
||
| 262 | * @param \eZ\Publish\SPI\Persistence\Handler $persistenceHandler |
||
| 263 | * @param \eZ\Publish\SPI\Search\Handler $searchHandler |
||
| 264 | * @param \eZ\Publish\Core\Search\Common\BackgroundIndexer $backgroundIndexer |
||
| 265 | * @param \eZ\Publish\Core\Repository\Helper\RelationProcessor $relationProcessor |
||
| 266 | * @param array $serviceSettings |
||
| 267 | * @param \eZ\Publish\API\Repository\Values\User\UserReference|null $user |
||
| 268 | * @param \Psr\Log\LoggerInterface|null $logger |
||
| 269 | */ |
||
| 270 | public function __construct( |
||
| 320 | |||
| 321 | /** |
||
| 322 | * @deprecated since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. |
||
| 323 | * |
||
| 324 | * Get current user. |
||
| 325 | * |
||
| 326 | * Loads the full user object if not already loaded, if you only need to know user id use {@see getCurrentUserReference()} |
||
| 327 | * |
||
| 328 | * @return \eZ\Publish\API\Repository\Values\User\User |
||
| 329 | */ |
||
| 330 | public function getCurrentUser() |
||
| 340 | |||
| 341 | /** |
||
| 342 | * @deprecated since 6.6, to be removed. Use PermissionResolver::getCurrentUserReference() instead. |
||
| 343 | * |
||
| 344 | * Get current user reference. |
||
| 345 | * |
||
| 346 | * @since 5.4.5 |
||
| 347 | * @return \eZ\Publish\API\Repository\Values\User\UserReference |
||
| 348 | */ |
||
| 349 | public function getCurrentUserReference() |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @deprecated since 6.6, to be removed. Use PermissionResolver::setCurrentUserReference() instead. |
||
| 356 | * |
||
| 357 | * Sets the current user to the given $user. |
||
| 358 | * |
||
| 359 | * @param \eZ\Publish\API\Repository\Values\User\UserReference $user |
||
| 360 | * |
||
| 361 | * @throws InvalidArgumentValue If UserReference does not contain a id |
||
| 362 | */ |
||
| 363 | public function setCurrentUser(APIUserReference $user) |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Allows API execution to be performed with full access sand-boxed. |
||
| 383 | * |
||
| 384 | * The closure sandbox will do a catch all on exceptions and rethrow after |
||
| 385 | * re-setting the sudo flag. |
||
| 386 | * |
||
| 387 | * Example use: |
||
| 388 | * $location = $repository->sudo( |
||
| 389 | * function ( Repository $repo ) use ( $locationId ) |
||
| 390 | * { |
||
| 391 | * return $repo->getLocationService()->loadLocation( $locationId ) |
||
| 392 | * } |
||
| 393 | * ); |
||
| 394 | * |
||
| 395 | * |
||
| 396 | * @param \Closure $callback |
||
| 397 | * @param \eZ\Publish\API\Repository\Repository $outerRepository |
||
| 398 | * |
||
| 399 | * @throws \RuntimeException Thrown on recursive sudo() use. |
||
| 400 | * @throws \Exception Re throws exceptions thrown inside $callback |
||
| 401 | * |
||
| 402 | * @return mixed |
||
| 403 | */ |
||
| 404 | public function sudo(\Closure $callback, RepositoryInterface $outerRepository = null) |
||
| 411 | |||
| 412 | /** |
||
| 413 | * @deprecated since 6.6, to be removed. Use PermissionResolver::hasAccess() instead. |
||
| 414 | * |
||
| 415 | * Check if user has access to a given module / function. |
||
| 416 | * |
||
| 417 | * Low level function, use canUser instead if you have objects to check against. |
||
| 418 | * |
||
| 419 | * @param string $module |
||
| 420 | * @param string $function |
||
| 421 | * @param \eZ\Publish\API\Repository\Values\User\UserReference $user |
||
| 422 | * |
||
| 423 | * @return bool|array Bool if user has full or no access, array if limitations if not |
||
| 424 | */ |
||
| 425 | public function hasAccess($module, $function, APIUserReference $user = null) |
||
| 429 | |||
| 430 | /** |
||
| 431 | * @deprecated since 6.6, to be removed. Use PermissionResolver::canUser() instead. |
||
| 432 | * |
||
| 433 | * Check if user has access to a given action on a given value object. |
||
| 434 | * |
||
| 435 | * Indicates if the current user is allowed to perform an action given by the function on the given |
||
| 436 | * objects. |
||
| 437 | * |
||
| 438 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If any of the arguments are invalid |
||
| 439 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If value of the LimitationValue is unsupported |
||
| 440 | * |
||
| 441 | * @param string $module The module, aka controller identifier to check permissions on |
||
| 442 | * @param string $function The function, aka the controller action to check permissions on |
||
| 443 | * @param \eZ\Publish\API\Repository\Values\ValueObject $object The object to check if the user has access to |
||
| 444 | * @param mixed $targets The location, parent or "assignment" value object, or an array of the same |
||
| 445 | * |
||
| 446 | * @return bool |
||
| 447 | */ |
||
| 448 | public function canUser($module, $function, ValueObject $object, $targets = null) |
||
| 464 | |||
| 465 | /** |
||
| 466 | * Get Content Service. |
||
| 467 | * |
||
| 468 | * Get service object to perform operations on Content objects and it's aggregate members. |
||
| 469 | * |
||
| 470 | * @return \eZ\Publish\API\Repository\ContentService |
||
| 471 | */ |
||
| 472 | View Code Duplication | public function getContentService() |
|
| 490 | |||
| 491 | /** |
||
| 492 | * Get Content Language Service. |
||
| 493 | * |
||
| 494 | * Get service object to perform operations on Content language objects |
||
| 495 | * |
||
| 496 | * @return \eZ\Publish\API\Repository\LanguageService |
||
| 497 | */ |
||
| 498 | public function getContentLanguageService() |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Get Content Type Service. |
||
| 515 | * |
||
| 516 | * Get service object to perform operations on Content Type objects and it's aggregate members. |
||
| 517 | * ( Group, Field & FieldCategory ) |
||
| 518 | * |
||
| 519 | * @return \eZ\Publish\API\Repository\ContentTypeService |
||
| 520 | */ |
||
| 521 | View Code Duplication | public function getContentTypeService() |
|
| 538 | |||
| 539 | /** |
||
| 540 | * Get Content Location Service. |
||
| 541 | * |
||
| 542 | * Get service object to perform operations on Location objects and subtrees |
||
| 543 | * |
||
| 544 | * @return \eZ\Publish\API\Repository\LocationService |
||
| 545 | */ |
||
| 546 | public function getLocationService() |
||
| 564 | |||
| 565 | /** |
||
| 566 | * Get Content Trash service. |
||
| 567 | * |
||
| 568 | * Trash service allows to perform operations related to location trash |
||
| 569 | * (trash/untrash, load/list from trash...) |
||
| 570 | * |
||
| 571 | * @return \eZ\Publish\API\Repository\TrashService |
||
| 572 | */ |
||
| 573 | public function getTrashService() |
||
| 589 | |||
| 590 | /** |
||
| 591 | * Get Content Section Service. |
||
| 592 | * |
||
| 593 | * Get Section service that lets you manipulate section objects |
||
| 594 | * |
||
| 595 | * @return \eZ\Publish\API\Repository\SectionService |
||
| 596 | */ |
||
| 597 | public function getSectionService() |
||
| 611 | |||
| 612 | /** |
||
| 613 | * Get User Service. |
||
| 614 | * |
||
| 615 | * Get service object to perform operations on Users and UserGroup |
||
| 616 | * |
||
| 617 | * @return \eZ\Publish\API\Repository\UserService |
||
| 618 | */ |
||
| 619 | public function getUserService() |
||
| 633 | |||
| 634 | /** |
||
| 635 | * Get URLAliasService. |
||
| 636 | * |
||
| 637 | * @return \eZ\Publish\API\Repository\URLAliasService |
||
| 638 | */ |
||
| 639 | public function getURLAliasService() |
||
| 654 | |||
| 655 | /** |
||
| 656 | * Get URLWildcardService. |
||
| 657 | * |
||
| 658 | * @return \eZ\Publish\API\Repository\URLWildcardService |
||
| 659 | */ |
||
| 660 | public function getURLWildcardService() |
||
| 674 | |||
| 675 | /** |
||
| 676 | * Get URLService. |
||
| 677 | * |
||
| 678 | * @return \eZ\Publish\API\Repository\URLService |
||
| 679 | */ |
||
| 680 | public function getURLService() |
||
| 693 | |||
| 694 | /** |
||
| 695 | * Get ObjectStateService. |
||
| 696 | * |
||
| 697 | * @return \eZ\Publish\API\Repository\ObjectStateService |
||
| 698 | */ |
||
| 699 | public function getObjectStateService() |
||
| 713 | |||
| 714 | /** |
||
| 715 | * Get RoleService. |
||
| 716 | * |
||
| 717 | * @return \eZ\Publish\API\Repository\RoleService |
||
| 718 | */ |
||
| 719 | public function getRoleService() |
||
| 735 | |||
| 736 | /** |
||
| 737 | * Get LimitationService. |
||
| 738 | * |
||
| 739 | * @return \eZ\Publish\Core\Repository\Helper\LimitationService |
||
| 740 | */ |
||
| 741 | protected function getLimitationService() |
||
| 751 | |||
| 752 | /** |
||
| 753 | * Get RoleDomainMapper. |
||
| 754 | * |
||
| 755 | * @return \eZ\Publish\Core\Repository\Helper\RoleDomainMapper |
||
| 756 | */ |
||
| 757 | protected function getRoleDomainMapper() |
||
| 767 | |||
| 768 | /** |
||
| 769 | * Get SearchService. |
||
| 770 | * |
||
| 771 | * @return \eZ\Publish\API\Repository\SearchService |
||
| 772 | */ |
||
| 773 | public function getSearchService() |
||
| 790 | |||
| 791 | /** |
||
| 792 | * Get FieldTypeService. |
||
| 793 | * |
||
| 794 | * @return \eZ\Publish\API\Repository\FieldTypeService |
||
| 795 | */ |
||
| 796 | public function getFieldTypeService() |
||
| 806 | |||
| 807 | /** |
||
| 808 | * Get PermissionResolver. |
||
| 809 | * |
||
| 810 | * @return \eZ\Publish\API\Repository\PermissionResolver |
||
| 811 | */ |
||
| 812 | public function getPermissionResolver() |
||
| 816 | |||
| 817 | /** |
||
| 818 | * @return Helper\FieldTypeRegistry |
||
| 819 | */ |
||
| 820 | protected function getFieldTypeRegistry() |
||
| 830 | |||
| 831 | /** |
||
| 832 | * @return Helper\NameableFieldTypeRegistry |
||
| 833 | */ |
||
| 834 | protected function getNameableFieldTypeRegistry() |
||
| 844 | |||
| 845 | /** |
||
| 846 | * Get NameSchemaResolverService. |
||
| 847 | * |
||
| 848 | * |
||
| 849 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
| 850 | * |
||
| 851 | * @internal |
||
| 852 | * @private |
||
| 853 | * |
||
| 854 | * @return \eZ\Publish\Core\Repository\Helper\NameSchemaService |
||
| 855 | */ |
||
| 856 | public function getNameSchemaService() |
||
| 871 | |||
| 872 | /** |
||
| 873 | * Get RelationProcessor. |
||
| 874 | * |
||
| 875 | * |
||
| 876 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
| 877 | * |
||
| 878 | * @return \eZ\Publish\Core\Repository\Helper\RelationProcessor |
||
| 879 | */ |
||
| 880 | protected function getRelationProcessor() |
||
| 884 | |||
| 885 | /** |
||
| 886 | * Get Content Domain Mapper. |
||
| 887 | * |
||
| 888 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
| 889 | * |
||
| 890 | * @return \eZ\Publish\Core\Repository\Helper\DomainMapper |
||
| 891 | */ |
||
| 892 | protected function getDomainMapper() |
||
| 908 | |||
| 909 | /** |
||
| 910 | * Get ContentType Domain Mapper. |
||
| 911 | * |
||
| 912 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
| 913 | * |
||
| 914 | * @return \eZ\Publish\Core\Repository\Helper\ContentTypeDomainMapper |
||
| 915 | */ |
||
| 916 | protected function getContentTypeDomainMapper() |
||
| 929 | |||
| 930 | /** |
||
| 931 | * Get PermissionCriterionResolver. |
||
| 932 | * |
||
| 933 | * @todo Move out from this & other repo instances when services becomes proper services in DIC terms using factory. |
||
| 934 | * |
||
| 935 | * @return \eZ\Publish\API\Repository\PermissionCriterionResolver |
||
| 936 | */ |
||
| 937 | protected function getPermissionCriterionResolver() |
||
| 941 | |||
| 942 | /** |
||
| 943 | * @return \eZ\Publish\API\Repository\PermissionCriterionResolver|\eZ\Publish\API\Repository\PermissionResolver |
||
| 944 | */ |
||
| 945 | protected function getCachedPermissionsResolver() |
||
| 964 | |||
| 965 | /** |
||
| 966 | * Begin transaction. |
||
| 967 | * |
||
| 968 | * Begins an transaction, make sure you'll call commit or rollback when done, |
||
| 969 | * otherwise work will be lost. |
||
| 970 | */ |
||
| 971 | public function beginTransaction() |
||
| 978 | |||
| 979 | /** |
||
| 980 | * Commit transaction. |
||
| 981 | * |
||
| 982 | * Commit transaction, or throw exceptions if no transactions has been started. |
||
| 983 | * |
||
| 984 | * @throws RuntimeException If no transaction has been started |
||
| 985 | */ |
||
| 986 | public function commit() |
||
| 1015 | |||
| 1016 | /** |
||
| 1017 | * Rollback transaction. |
||
| 1018 | * |
||
| 1019 | * Rollback transaction, or throw exceptions if no transactions has been started. |
||
| 1020 | * |
||
| 1021 | * @throws RuntimeException If no transaction has been started |
||
| 1022 | */ |
||
| 1023 | public function rollback() |
||
| 1034 | |||
| 1035 | /** |
||
| 1036 | * Enqueue an event to be triggered at commit or directly if no transaction has started. |
||
| 1037 | * |
||
| 1038 | * @param callable $event |
||
| 1039 | */ |
||
| 1040 | public function commitEvent($event) |
||
| 1049 | |||
| 1050 | /** |
||
| 1051 | * Only for internal use. |
||
| 1052 | * |
||
| 1053 | * Creates a \DateTime object for $timestamp in the current time zone |
||
| 1054 | * |
||
| 1055 | * @param int $timestamp |
||
| 1056 | * |
||
| 1057 | * @return \DateTime |
||
| 1058 | */ |
||
| 1059 | View Code Duplication | public function createDateTime($timestamp = null) |
|
| 1068 | } |
||
| 1069 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: