Code Duplication    Length = 36-36 lines in 2 locations

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

@@ 904-939 (lines=36) @@
901
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
902
     * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation)
903
     */
904
    public function assignRoleToUserGroup(APIRole $role, UserGroup $userGroup, RoleLimitation $roleLimitation = null)
905
    {
906
        if ($this->repository->canUser('role', 'assign', $userGroup, $role) !== true) {
907
            throw new UnauthorizedException('role', 'assign');
908
        }
909
910
        if ($roleLimitation === null) {
911
            $limitation = null;
912
        } else {
913
            $limitationValidationErrors = $this->limitationService->validateLimitation($roleLimitation);
914
            if (!empty($limitationValidationErrors)) {
915
                throw new LimitationValidationException($limitationValidationErrors);
916
            }
917
918
            $limitation = array($roleLimitation->getIdentifier() => $roleLimitation->limitationValues);
919
        }
920
921
        // Check if objects exists
922
        $spiRole = $this->userHandler->loadRole($role->id);
923
        $loadedUserGroup = $this->repository->getUserService()->loadUserGroup($userGroup->id);
924
925
        $limitation = $this->checkAssignmentAndFilterLimitationValues($loadedUserGroup->id, $spiRole, $limitation);
926
927
        $this->repository->beginTransaction();
928
        try {
929
            $this->userHandler->assignRole(
930
                $loadedUserGroup->id,
931
                $spiRole->id,
932
                $limitation
933
            );
934
            $this->repository->commit();
935
        } catch (Exception $e) {
936
            $this->repository->rollback();
937
            throw $e;
938
        }
939
    }
940
941
    /**
942
     * removes a role from the given user group.
@@ 993-1028 (lines=36) @@
990
     * @param \eZ\Publish\API\Repository\Values\User\User $user
991
     * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation)
992
     */
993
    public function assignRoleToUser(APIRole $role, User $user, RoleLimitation $roleLimitation = null)
994
    {
995
        if ($this->repository->canUser('role', 'assign', $user, $role) !== true) {
996
            throw new UnauthorizedException('role', 'assign');
997
        }
998
999
        if ($roleLimitation === null) {
1000
            $limitation = null;
1001
        } else {
1002
            $limitationValidationErrors = $this->limitationService->validateLimitation($roleLimitation);
1003
            if (!empty($limitationValidationErrors)) {
1004
                throw new LimitationValidationException($limitationValidationErrors);
1005
            }
1006
1007
            $limitation = array($roleLimitation->getIdentifier() => $roleLimitation->limitationValues);
1008
        }
1009
1010
        // Check if objects exists
1011
        $spiRole = $this->userHandler->loadRole($role->id);
1012
        $spiUser = $this->userHandler->load($user->id);
1013
1014
        $limitation = $this->checkAssignmentAndFilterLimitationValues($spiUser->id, $spiRole, $limitation);
1015
1016
        $this->repository->beginTransaction();
1017
        try {
1018
            $this->userHandler->assignRole(
1019
                $spiUser->id,
1020
                $spiRole->id,
1021
                $limitation
1022
            );
1023
            $this->repository->commit();
1024
        } catch (Exception $e) {
1025
            $this->repository->rollback();
1026
            throw $e;
1027
        }
1028
    }
1029
1030
    /**
1031
     * removes a role from the given user.