Code Duplication    Length = 17-21 lines in 6 locations

eZ/Publish/Core/Repository/ObjectStateService.php 2 locations

@@ 234-250 (lines=17) @@
231
     *
232
     * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectStateGroup $objectStateGroup
233
     */
234
    public function deleteObjectStateGroup(APIObjectStateGroup $objectStateGroup)
235
    {
236
        if (!$this->repository->canUser('state', 'administrate', $objectStateGroup)) {
237
            throw new UnauthorizedException('state', 'administrate');
238
        }
239
240
        $loadedObjectStateGroup = $this->loadObjectStateGroup($objectStateGroup->id);
241
242
        $this->repository->beginTransaction();
243
        try {
244
            $this->objectStateHandler->deleteGroup($loadedObjectStateGroup->id);
245
            $this->repository->commit();
246
        } catch (Exception $e) {
247
            $this->repository->rollback();
248
            throw $e;
249
        }
250
    }
251
252
    /**
253
     * Creates a new object state in the given group.
@@ 424-440 (lines=17) @@
421
     *
422
     * @param \eZ\Publish\API\Repository\Values\ObjectState\ObjectState $objectState
423
     */
424
    public function deleteObjectState(APIObjectState $objectState)
425
    {
426
        if (!$this->repository->canUser('state', 'administrate', $objectState)) {
427
            throw new UnauthorizedException('state', 'administrate');
428
        }
429
430
        $loadedObjectState = $this->loadObjectState($objectState->id);
431
432
        $this->repository->beginTransaction();
433
        try {
434
            $this->objectStateHandler->delete($loadedObjectState->id);
435
            $this->repository->commit();
436
        } catch (Exception $e) {
437
            $this->repository->rollback();
438
            throw $e;
439
        }
440
    }
441
442
    /**
443
     * Sets the object-state of a state group to $state for the given content.

eZ/Publish/Core/Repository/RoleService.php 2 locations

@@ 813-829 (lines=17) @@
810
     *
811
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
812
     */
813
    public function deleteRole(APIRole $role)
814
    {
815
        if ($this->repository->hasAccess('role', 'delete') !== true) {
816
            throw new UnauthorizedException('role', 'delete');
817
        }
818
819
        $loadedRole = $this->loadRole($role->id);
820
821
        $this->repository->beginTransaction();
822
        try {
823
            $this->userHandler->deleteRole($loadedRole->id);
824
            $this->repository->commit();
825
        } catch (Exception $e) {
826
            $this->repository->rollback();
827
            throw $e;
828
        }
829
    }
830
831
    /**
832
     * Loads all policies from roles which are assigned to a user or to user groups to which the user belongs.
@@ 1041-1057 (lines=17) @@
1038
     *
1039
     * @param \eZ\Publish\API\Repository\Values\User\RoleAssignment $roleAssignment
1040
     */
1041
    public function removeRoleAssignment(RoleAssignment $roleAssignment)
1042
    {
1043
        if ($this->repository->canUser('role', 'assign', $roleAssignment) !== true) {
1044
            throw new UnauthorizedException('role', 'assign');
1045
        }
1046
1047
        $spiRoleAssignment = $this->userHandler->loadRoleAssignment($roleAssignment->id);
1048
1049
        $this->repository->beginTransaction();
1050
        try {
1051
            $this->userHandler->removeRoleAssignment($spiRoleAssignment->id);
1052
            $this->repository->commit();
1053
        } catch (Exception $e) {
1054
            $this->repository->rollback();
1055
            throw $e;
1056
        }
1057
    }
1058
1059
    /**
1060
     * Loads a role assignment for the given id.

eZ/Publish/Core/Repository/ContentTypeService.php 1 location

@@ 1633-1653 (lines=21) @@
1630
     * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
1631
     * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException
1632
     */
1633
    public function removeContentTypeTranslation(APIContentTypeDraft $contentTypeDraft, string $languageCode): APIContentTypeDraft
1634
    {
1635
        if (!$this->repository->canUser('class', 'update', $contentTypeDraft)) {
1636
            throw new UnauthorizedException('ContentType', 'update');
1637
        }
1638
1639
        $this->repository->beginTransaction();
1640
        try {
1641
            $contentType = $this->contentTypeHandler->removeContentTypeTranslation(
1642
                $contentTypeDraft->id,
1643
                $languageCode
1644
            );
1645
1646
            $this->repository->commit();
1647
        } catch (Exception $e) {
1648
            $this->repository->rollback();
1649
            throw $e;
1650
        }
1651
1652
        return $this->contentTypeDomainMapper->buildContentTypeDraftDomainObject($contentType);
1653
    }
1654
}
1655

eZ/Publish/Core/Repository/URLWildcardService.php 1 location

@@ 121-137 (lines=17) @@
118
     *
119
     * @param \eZ\Publish\API\Repository\Values\Content\UrlWildcard $urlWildcard the url wildcard to remove
120
     */
121
    public function remove(URLWildcard $urlWildcard): void
122
    {
123
        if (!$this->repository->canUser('content', 'urltranslator', $urlWildcard)) {
124
            throw new UnauthorizedException('content', 'urltranslator');
125
        }
126
127
        $this->repository->beginTransaction();
128
        try {
129
            $this->urlWildcardHandler->remove(
130
                $urlWildcard->id
131
            );
132
            $this->repository->commit();
133
        } catch (Exception $e) {
134
            $this->repository->rollback();
135
            throw $e;
136
        }
137
    }
138
139
    /**
140
     * Loads a url wild card.