Code Duplication    Length = 31-31 lines in 2 locations

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

@@ 1005-1035 (lines=31) @@
1002
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
1003
     * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup
1004
     */
1005
    public function unassignRoleFromUserGroup(APIRole $role, UserGroup $userGroup)
1006
    {
1007
        if ($this->repository->canUser('role', 'assign', $userGroup, $role) !== true) {
1008
            throw new UnauthorizedException('role', 'assign');
1009
        }
1010
1011
        $spiRoleAssignments = $this->userHandler->loadRoleAssignmentsByGroupId($userGroup->id);
1012
        $isAssigned = false;
1013
        foreach ($spiRoleAssignments as $spiRoleAssignment) {
1014
            if ($spiRoleAssignment->roleId === $role->id) {
1015
                $isAssigned = true;
1016
                break;
1017
            }
1018
        }
1019
1020
        if (!$isAssigned) {
1021
            throw new InvalidArgumentException(
1022
                '$userGroup',
1023
                'Role is not assigned to the given UserGroup'
1024
            );
1025
        }
1026
1027
        $this->repository->beginTransaction();
1028
        try {
1029
            $this->userHandler->unassignRole($userGroup->id, $role->id);
1030
            $this->repository->commit();
1031
        } catch (Exception $e) {
1032
            $this->repository->rollback();
1033
            throw $e;
1034
        }
1035
    }
1036
1037
    /**
1038
     * Assigns a role to the given user.
@@ 1094-1124 (lines=31) @@
1091
     * @param \eZ\Publish\API\Repository\Values\User\Role $role
1092
     * @param \eZ\Publish\API\Repository\Values\User\User $user
1093
     */
1094
    public function unassignRoleFromUser(APIRole $role, User $user)
1095
    {
1096
        if ($this->repository->canUser('role', 'assign', $user, $role) !== true) {
1097
            throw new UnauthorizedException('role', 'assign');
1098
        }
1099
1100
        $spiRoleAssignments = $this->userHandler->loadRoleAssignmentsByGroupId($user->id);
1101
        $isAssigned = false;
1102
        foreach ($spiRoleAssignments as $spiRoleAssignment) {
1103
            if ($spiRoleAssignment->roleId === $role->id) {
1104
                $isAssigned = true;
1105
                break;
1106
            }
1107
        }
1108
1109
        if (!$isAssigned) {
1110
            throw new InvalidArgumentException(
1111
                '$user',
1112
                'Role is not assigned to the given User'
1113
            );
1114
        }
1115
1116
        $this->repository->beginTransaction();
1117
        try {
1118
            $this->userHandler->unassignRole($user->id, $role->id);
1119
            $this->repository->commit();
1120
        } catch (Exception $e) {
1121
            $this->repository->rollback();
1122
            throw $e;
1123
        }
1124
    }
1125
1126
    /**
1127
     * Removes the given role assignment.