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 RoleService 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 RoleService, and based on these observations, apply Extract Interface, too.
| 1 | <?php  | 
            ||
| 45 | class RoleService implements APIRoleService, Sessionable  | 
            ||
| 46 | { | 
            ||
| 47 | /**  | 
            ||
| 48 | * @var \eZ\Publish\Core\REST\Client\UserService  | 
            ||
| 49 | */  | 
            ||
| 50 | private $userService;  | 
            ||
| 51 | |||
| 52 | /**  | 
            ||
| 53 | * @var \eZ\Publish\Core\REST\Client\HttpClient  | 
            ||
| 54 | */  | 
            ||
| 55 | private $client;  | 
            ||
| 56 | |||
| 57 | /**  | 
            ||
| 58 | * @var \eZ\Publish\Core\REST\Common\Input\Dispatcher  | 
            ||
| 59 | */  | 
            ||
| 60 | private $inputDispatcher;  | 
            ||
| 61 | |||
| 62 | /**  | 
            ||
| 63 | * @var \eZ\Publish\Core\REST\Common\Output\Visitor  | 
            ||
| 64 | */  | 
            ||
| 65 | private $outputVisitor;  | 
            ||
| 66 | |||
| 67 | /**  | 
            ||
| 68 | * @var \eZ\Publish\Core\REST\Common\RequestParser  | 
            ||
| 69 | */  | 
            ||
| 70 | private $requestParser;  | 
            ||
| 71 | |||
| 72 | /**  | 
            ||
| 73 | * @param \eZ\Publish\Core\REST\Client\UserService $userService  | 
            ||
| 74 | * @param \eZ\Publish\Core\REST\Client\HttpClient $client  | 
            ||
| 75 | * @param \eZ\Publish\Core\REST\Common\Input\Dispatcher $inputDispatcher  | 
            ||
| 76 | * @param \eZ\Publish\Core\REST\Common\Output\Visitor $outputVisitor  | 
            ||
| 77 | * @param \eZ\Publish\Core\REST\Common\RequestParser $requestParser  | 
            ||
| 78 | */  | 
            ||
| 79 | View Code Duplication | public function __construct(UserService $userService, HttpClient $client, Dispatcher $inputDispatcher, Visitor $outputVisitor, RequestParser $requestParser)  | 
            |
| 87 | |||
| 88 | /**  | 
            ||
| 89 | * Set session ID.  | 
            ||
| 90 | *  | 
            ||
| 91 | * Only for testing  | 
            ||
| 92 | *  | 
            ||
| 93 | * @param mixed $id  | 
            ||
| 94 | *  | 
            ||
| 95 | * @private  | 
            ||
| 96 | */  | 
            ||
| 97 | public function setSession($id)  | 
            ||
| 103 | |||
| 104 | /**  | 
            ||
| 105 | * Creates a new RoleDraft for existing Role.  | 
            ||
| 106 | *  | 
            ||
| 107 | * @since 6.0  | 
            ||
| 108 | *  | 
            ||
| 109 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a role  | 
            ||
| 110 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the Role already has a Role Draft that will need to be removed first  | 
            ||
| 111 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a policy limitation in the $roleCreateStruct is not valid  | 
            ||
| 112 | *  | 
            ||
| 113 | * @param \eZ\Publish\API\Repository\Values\User\Role $role  | 
            ||
| 114 | *  | 
            ||
| 115 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft  | 
            ||
| 116 | */  | 
            ||
| 117 | public function createRoleDraft(APIRole $role)  | 
            ||
| 121 | |||
| 122 | /**  | 
            ||
| 123 | * Loads a role for the given id.  | 
            ||
| 124 | *  | 
            ||
| 125 | * @since 6.0  | 
            ||
| 126 | *  | 
            ||
| 127 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role  | 
            ||
| 128 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given id was not found  | 
            ||
| 129 | *  | 
            ||
| 130 | * @param mixed $id  | 
            ||
| 131 | *  | 
            ||
| 132 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft  | 
            ||
| 133 | */  | 
            ||
| 134 | public function loadRoleDraft($id)  | 
            ||
| 138 | |||
| 139 | /**  | 
            ||
| 140 | * Loads a RoleDraft by the ID of the role it was created from.  | 
            ||
| 141 | *  | 
            ||
| 142 | * @param mixed $roleId ID of the role the draft was created from.  | 
            ||
| 143 | *  | 
            ||
| 144 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role  | 
            ||
| 145 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a RoleDraft with the given id was not found  | 
            ||
| 146 | *  | 
            ||
| 147 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft  | 
            ||
| 148 | */  | 
            ||
| 149 | public function loadRoleDraftByRoleId($roleId)  | 
            ||
| 153 | |||
| 154 | /**  | 
            ||
| 155 | * Updates the properties of a role draft.  | 
            ||
| 156 | *  | 
            ||
| 157 | * @since 6.0  | 
            ||
| 158 | *  | 
            ||
| 159 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a role  | 
            ||
| 160 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the identifier of the role already exists  | 
            ||
| 161 | *  | 
            ||
| 162 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft  | 
            ||
| 163 | * @param \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct $roleUpdateStruct  | 
            ||
| 164 | *  | 
            ||
| 165 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft  | 
            ||
| 166 | */  | 
            ||
| 167 | public function updateRoleDraft(APIRoleDraft $roleDraft, RoleUpdateStruct $roleUpdateStruct)  | 
            ||
| 171 | |||
| 172 | /**  | 
            ||
| 173 | * Adds a new policy to the role draft.  | 
            ||
| 174 | *  | 
            ||
| 175 | * @since 6.0  | 
            ||
| 176 | *  | 
            ||
| 177 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to add a policy  | 
            ||
| 178 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy create  | 
            ||
| 179 | * struct or if limitation is not allowed on module/function  | 
            ||
| 180 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyCreateStruct is not valid  | 
            ||
| 181 | *  | 
            ||
| 182 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft  | 
            ||
| 183 | * @param \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct $policyCreateStruct  | 
            ||
| 184 | *  | 
            ||
| 185 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft  | 
            ||
| 186 | */  | 
            ||
| 187 | public function addPolicyByRoleDraft(APIRoleDraft $roleDraft, APIPolicyCreateStruct $policyCreateStruct)  | 
            ||
| 191 | |||
| 192 | /**  | 
            ||
| 193 | * Removes a policy from a role draft.  | 
            ||
| 194 | *  | 
            ||
| 195 | * @since 6.0  | 
            ||
| 196 | *  | 
            ||
| 197 | *  | 
            ||
| 198 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft  | 
            ||
| 199 | * @param PolicyDraft $policyDraft the policy to remove from the role  | 
            ||
| 200 | * @return APIRoleDraft if the authenticated user is not allowed to remove a policy  | 
            ||
| 201 | */  | 
            ||
| 202 | public function removePolicyByRoleDraft(APIRoleDraft $roleDraft, PolicyDraft $policyDraft)  | 
            ||
| 206 | |||
| 207 | /**  | 
            ||
| 208 | * Updates the limitations of a policy. The module and function cannot be changed and  | 
            ||
| 209 | * the limitations are replaced by the ones in $roleUpdateStruct.  | 
            ||
| 210 | *  | 
            ||
| 211 | * @since 6.0  | 
            ||
| 212 | *  | 
            ||
| 213 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a policy  | 
            ||
| 214 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy update  | 
            ||
| 215 | * struct or if limitation is not allowed on module/function  | 
            ||
| 216 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyUpdateStruct is not valid  | 
            ||
| 217 | *  | 
            ||
| 218 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft  | 
            ||
| 219 | * @param \eZ\Publish\API\Repository\Values\User\PolicyDraft $policy  | 
            ||
| 220 | * @param \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct $policyUpdateStruct  | 
            ||
| 221 | *  | 
            ||
| 222 | * @return \eZ\Publish\API\Repository\Values\User\PolicyDraft  | 
            ||
| 223 | */  | 
            ||
| 224 | public function updatePolicyByRoleDraft(APIRoleDraft $roleDraft, PolicyDraft $policy, APIPolicyUpdateStruct $policyUpdateStruct)  | 
            ||
| 228 | |||
| 229 | /**  | 
            ||
| 230 | * Deletes the given role.  | 
            ||
| 231 | *  | 
            ||
| 232 | * @since 6.0  | 
            ||
| 233 | *  | 
            ||
| 234 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this role  | 
            ||
| 235 | *  | 
            ||
| 236 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft  | 
            ||
| 237 | */  | 
            ||
| 238 | public function deleteRoleDraft(APIRoleDraft $roleDraft)  | 
            ||
| 242 | |||
| 243 | /**  | 
            ||
| 244 | * Publishes a given Role draft.  | 
            ||
| 245 | *  | 
            ||
| 246 | * @since 6.0  | 
            ||
| 247 | *  | 
            ||
| 248 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this role  | 
            ||
| 249 | *  | 
            ||
| 250 | * @param \eZ\Publish\API\Repository\Values\User\RoleDraft $roleDraft  | 
            ||
| 251 | */  | 
            ||
| 252 | public function publishRoleDraft(APIRoleDraft $roleDraft)  | 
            ||
| 256 | |||
| 257 | /**  | 
            ||
| 258 | * Creates a new Role draft.  | 
            ||
| 259 | *  | 
            ||
| 260 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to create a role  | 
            ||
| 261 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the name of the role already exists or if limitation of the  | 
            ||
| 262 | * same type is repeated in the policy create struct or if  | 
            ||
| 263 | * limitation is not allowed on module/function  | 
            ||
| 264 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a policy limitation in the $roleCreateStruct is not valid  | 
            ||
| 265 | *  | 
            ||
| 266 | * @param \eZ\Publish\API\Repository\Values\User\RoleCreateStruct $roleCreateStruct  | 
            ||
| 267 | *  | 
            ||
| 268 | * @return \eZ\Publish\API\Repository\Values\User\RoleDraft  | 
            ||
| 269 | */  | 
            ||
| 270 | public function createRole(APIRoleCreateStruct $roleCreateStruct)  | 
            ||
| 317 | |||
| 318 | /**  | 
            ||
| 319 | * Updates the name of the role.  | 
            ||
| 320 | *  | 
            ||
| 321 |      * @deprecated since 6.0, use {@see updateRoleDraft} | 
            ||
| 322 | *  | 
            ||
| 323 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a role  | 
            ||
| 324 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if the name of the role already exists  | 
            ||
| 325 | *  | 
            ||
| 326 | * @param \eZ\Publish\API\Repository\Values\User\Role $role  | 
            ||
| 327 | * @param \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct $roleUpdateStruct  | 
            ||
| 328 | *  | 
            ||
| 329 | * @return \eZ\Publish\API\Repository\Values\User\Role  | 
            ||
| 330 | */  | 
            ||
| 331 | public function updateRole(APIRole $role, RoleUpdateStruct $roleUpdateStruct)  | 
            ||
| 345 | |||
| 346 | /**  | 
            ||
| 347 | * Adds a new policy to the role.  | 
            ||
| 348 | *  | 
            ||
| 349 |      * @deprecated since 6.0, use {@see addPolicyByRoleDraft} | 
            ||
| 350 | *  | 
            ||
| 351 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to add a policy  | 
            ||
| 352 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy create  | 
            ||
| 353 | * struct or if limitation is not allowed on module/function  | 
            ||
| 354 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyCreateStruct is not valid  | 
            ||
| 355 | *  | 
            ||
| 356 | * @param \eZ\Publish\API\Repository\Values\User\Role $role  | 
            ||
| 357 | * @param \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct $policyCreateStruct  | 
            ||
| 358 | *  | 
            ||
| 359 | * @return \eZ\Publish\API\Repository\Values\User\Role  | 
            ||
| 360 | */  | 
            ||
| 361 | public function addPolicy(APIRole $role, APIPolicyCreateStruct $policyCreateStruct)  | 
            ||
| 396 | |||
| 397 | /**  | 
            ||
| 398 | * Removes a policy from the role.  | 
            ||
| 399 | *  | 
            ||
| 400 |      * @deprecated since 5.3, use {@link removePolicyByRoleDraft()} instead. | 
            ||
| 401 | *  | 
            ||
| 402 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a policy  | 
            ||
| 403 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if policy does not belong to the given role  | 
            ||
| 404 | *  | 
            ||
| 405 | * @param \eZ\Publish\API\Repository\Values\User\Role $role  | 
            ||
| 406 | * @param \eZ\Publish\API\Repository\Values\User\Policy $policy the policy to remove from the role  | 
            ||
| 407 | *  | 
            ||
| 408 | * @return \eZ\Publish\API\Repository\Values\User\Role the updated role  | 
            ||
| 409 | */  | 
            ||
| 410 | public function removePolicy(APIRole $role, APIPolicy $policy)  | 
            ||
| 437 | |||
| 438 | /**  | 
            ||
| 439 | * Deletes a policy.  | 
            ||
| 440 | *  | 
            ||
| 441 |      * @deprecated since 6.0, use {@link removePolicyByRoleDraft()} instead. | 
            ||
| 442 | *  | 
            ||
| 443 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a policy  | 
            ||
| 444 | *  | 
            ||
| 445 | * @param \eZ\Publish\API\Repository\Values\User\Policy $policy the policy to delete  | 
            ||
| 446 | */  | 
            ||
| 447 | public function deletePolicy(APIPolicy $policy)  | 
            ||
| 451 | |||
| 452 | /**  | 
            ||
| 453 | * Updates the limitations of a policy. The module and function cannot be changed and  | 
            ||
| 454 | * the limitations are replaced by the ones in $roleUpdateStruct.  | 
            ||
| 455 | *  | 
            ||
| 456 |      * @deprecated since 6.0, use {@link updatePolicyByRoleDraft()} instead. | 
            ||
| 457 | *  | 
            ||
| 458 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to update a policy  | 
            ||
| 459 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException if limitation of the same type is repeated in policy update  | 
            ||
| 460 | * struct or if limitation is not allowed on module/function  | 
            ||
| 461 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if a limitation in the $policyUpdateStruct is not valid  | 
            ||
| 462 | *  | 
            ||
| 463 | * @param \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct $policyUpdateStruct  | 
            ||
| 464 | * @param \eZ\Publish\API\Repository\Values\User\Policy $policy  | 
            ||
| 465 | *  | 
            ||
| 466 | * @return \eZ\Publish\API\Repository\Values\User\Policy  | 
            ||
| 467 | */  | 
            ||
| 468 | public function updatePolicy(APIPolicy $policy, APIPolicyUpdateStruct $policyUpdateStruct)  | 
            ||
| 489 | |||
| 490 | /**  | 
            ||
| 491 | * Loads a role for the given id.  | 
            ||
| 492 | *  | 
            ||
| 493 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role  | 
            ||
| 494 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given name was not found  | 
            ||
| 495 | *  | 
            ||
| 496 | * @param mixed $id  | 
            ||
| 497 | *  | 
            ||
| 498 | * @return \eZ\Publish\API\Repository\Values\User\Role  | 
            ||
| 499 | */  | 
            ||
| 500 | public function loadRole($id)  | 
            ||
| 530 | |||
| 531 | /**  | 
            ||
| 532 | * Loads a role for the given name.  | 
            ||
| 533 | *  | 
            ||
| 534 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role  | 
            ||
| 535 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a role with the given name was not found  | 
            ||
| 536 | *  | 
            ||
| 537 | * @param string $name  | 
            ||
| 538 | *  | 
            ||
| 539 | * @return \eZ\Publish\API\Repository\Values\User\Role  | 
            ||
| 540 | */  | 
            ||
| 541 | View Code Duplication | public function loadRoleByIdentifier($name)  | 
            |
| 555 | |||
| 556 | /**  | 
            ||
| 557 | * Loads all roles.  | 
            ||
| 558 | *  | 
            ||
| 559 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read the roles  | 
            ||
| 560 | *  | 
            ||
| 561 | * @return \eZ\Publish\API\Repository\Values\User\Role[]  | 
            ||
| 562 | */  | 
            ||
| 563 | public function loadRoles()  | 
            ||
| 575 | |||
| 576 | /**  | 
            ||
| 577 | * Deletes the given role.  | 
            ||
| 578 | *  | 
            ||
| 579 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to delete this role  | 
            ||
| 580 | *  | 
            ||
| 581 | * @param \eZ\Publish\API\Repository\Values\User\Role $role  | 
            ||
| 582 | */  | 
            ||
| 583 | View Code Duplication | public function deleteRole(APIRole $role)  | 
            |
| 601 | |||
| 602 | /**  | 
            ||
| 603 | * Loads all policies from roles which are assigned to a user or to user groups to which the user belongs.  | 
            ||
| 604 | *  | 
            ||
| 605 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if a user with the given id was not found  | 
            ||
| 606 | *  | 
            ||
| 607 | * @param mixed $userId  | 
            ||
| 608 | *  | 
            ||
| 609 | * @return \eZ\Publish\API\Repository\Values\User\Policy[]  | 
            ||
| 610 | */  | 
            ||
| 611 | View Code Duplication | public function loadPoliciesByUserId($userId)  | 
            |
| 624 | |||
| 625 | /**  | 
            ||
| 626 | * Assigns a role to the given user group.  | 
            ||
| 627 | *  | 
            ||
| 628 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role  | 
            ||
| 629 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid  | 
            ||
| 630 | *  | 
            ||
| 631 | * @param \eZ\Publish\API\Repository\Values\User\Role $role  | 
            ||
| 632 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup  | 
            ||
| 633 | * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation)  | 
            ||
| 634 | */  | 
            ||
| 635 | View Code Duplication | public function assignRoleToUserGroup(APIRole $role, UserGroup $userGroup, RoleLimitation $roleLimitation = null)  | 
            |
| 655 | |||
| 656 | /**  | 
            ||
| 657 | * removes a role from the given user group.  | 
            ||
| 658 | *  | 
            ||
| 659 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role  | 
            ||
| 660 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the role is not assigned to the given user group  | 
            ||
| 661 | *  | 
            ||
| 662 | * @param \eZ\Publish\API\Repository\Values\User\Role $role  | 
            ||
| 663 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup  | 
            ||
| 664 | */  | 
            ||
| 665 | View Code Duplication | public function unassignRoleFromUserGroup(APIRole $role, UserGroup $userGroup)  | 
            |
| 689 | |||
| 690 | /**  | 
            ||
| 691 | * Assigns a role to the given user.  | 
            ||
| 692 | *  | 
            ||
| 693 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to assign a role  | 
            ||
| 694 | * @throws \eZ\Publish\API\Repository\Exceptions\LimitationValidationException if $roleLimitation is not valid  | 
            ||
| 695 | *  | 
            ||
| 696 | * @todo add limitations  | 
            ||
| 697 | *  | 
            ||
| 698 | * @param \eZ\Publish\API\Repository\Values\User\Role $role  | 
            ||
| 699 | * @param \eZ\Publish\API\Repository\Values\User\User $user  | 
            ||
| 700 | * @param \eZ\Publish\API\Repository\Values\User\Limitation\RoleLimitation $roleLimitation an optional role limitation (which is either a subtree limitation or section limitation)  | 
            ||
| 701 | */  | 
            ||
| 702 | View Code Duplication | public function assignRoleToUser(APIRole $role, User $user, RoleLimitation $roleLimitation = null)  | 
            |
| 722 | |||
| 723 | /**  | 
            ||
| 724 | * removes a role from the given user.  | 
            ||
| 725 | *  | 
            ||
| 726 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role  | 
            ||
| 727 | * @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException If the role is not assigned to the user  | 
            ||
| 728 | *  | 
            ||
| 729 | * @param \eZ\Publish\API\Repository\Values\User\Role $role  | 
            ||
| 730 | * @param \eZ\Publish\API\Repository\Values\User\User $user  | 
            ||
| 731 | */  | 
            ||
| 732 | View Code Duplication | public function unassignRoleFromUser(APIRole $role, User $user)  | 
            |
| 756 | |||
| 757 | /**  | 
            ||
| 758 | * Removes the given role assignment.  | 
            ||
| 759 | *  | 
            ||
| 760 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to remove a role assignment  | 
            ||
| 761 | *  | 
            ||
| 762 | * @param \eZ\Publish\API\Repository\Values\User\RoleAssignment $roleAssignment  | 
            ||
| 763 | */  | 
            ||
| 764 | public function removeRoleAssignment(APIRoleAssignment $roleAssignment)  | 
            ||
| 768 | |||
| 769 | /**  | 
            ||
| 770 | * Loads a user assignment for the given id.  | 
            ||
| 771 | *  | 
            ||
| 772 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read this role  | 
            ||
| 773 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException If the role assignment was not found  | 
            ||
| 774 | *  | 
            ||
| 775 | * @param mixed $roleAssignmentId  | 
            ||
| 776 | *  | 
            ||
| 777 | * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment  | 
            ||
| 778 | */  | 
            ||
| 779 | public function loadRoleAssignment($roleAssignmentId)  | 
            ||
| 783 | |||
| 784 | /**  | 
            ||
| 785 | * Returns the assigned user and user groups to this role.  | 
            ||
| 786 | *  | 
            ||
| 787 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read a role  | 
            ||
| 788 | *  | 
            ||
| 789 | * @param \eZ\Publish\API\Repository\Values\User\Role $role  | 
            ||
| 790 | *  | 
            ||
| 791 | * @return \eZ\Publish\API\Repository\Values\User\RoleAssignment[]  | 
            ||
| 792 | */  | 
            ||
| 793 | public function getRoleAssignments(APIRole $role)  | 
            ||
| 797 | |||
| 798 | /**  | 
            ||
| 799 | * @see \eZ\Publish\API\Repository\RoleService::getRoleAssignmentsForUser()  | 
            ||
| 800 | */  | 
            ||
| 801 | View Code Duplication | public function getRoleAssignmentsForUser(User $user, $inherited = false)  | 
            |
| 826 | |||
| 827 | /**  | 
            ||
| 828 | * Returns the roles assigned to the given user group.  | 
            ||
| 829 | *  | 
            ||
| 830 | * @throws \eZ\Publish\API\Repository\Exceptions\UnauthorizedException if the authenticated user is not allowed to read a user group  | 
            ||
| 831 | *  | 
            ||
| 832 | * @param \eZ\Publish\API\Repository\Values\User\UserGroup $userGroup  | 
            ||
| 833 | *  | 
            ||
| 834 | * @return \eZ\Publish\API\Repository\Values\User\UserGroupRoleAssignment[]  | 
            ||
| 835 | */  | 
            ||
| 836 | View Code Duplication | public function getRoleAssignmentsForUserGroup(UserGroup $userGroup)  | 
            |
| 861 | |||
| 862 | /**  | 
            ||
| 863 | * Instantiates a role create class.  | 
            ||
| 864 | *  | 
            ||
| 865 | * @param string $name  | 
            ||
| 866 | *  | 
            ||
| 867 | * @return \eZ\Publish\API\Repository\Values\User\RoleCreateStruct  | 
            ||
| 868 | */  | 
            ||
| 869 | public function newRoleCreateStruct($name)  | 
            ||
| 873 | |||
| 874 | /**  | 
            ||
| 875 | * Instantiates a policy create class.  | 
            ||
| 876 | *  | 
            ||
| 877 | * @param string $module  | 
            ||
| 878 | * @param string $function  | 
            ||
| 879 | *  | 
            ||
| 880 | * @return \eZ\Publish\API\Repository\Values\User\PolicyCreateStruct  | 
            ||
| 881 | */  | 
            ||
| 882 | public function newPolicyCreateStruct($module, $function)  | 
            ||
| 886 | |||
| 887 | /**  | 
            ||
| 888 | * Instantiates a policy update class.  | 
            ||
| 889 | *  | 
            ||
| 890 | * @return \eZ\Publish\API\Repository\Values\User\PolicyUpdateStruct  | 
            ||
| 891 | */  | 
            ||
| 892 | public function newPolicyUpdateStruct()  | 
            ||
| 896 | |||
| 897 | /**  | 
            ||
| 898 | * Instantiates a policy update class.  | 
            ||
| 899 | *  | 
            ||
| 900 | * @return \eZ\Publish\API\Repository\Values\User\RoleUpdateStruct  | 
            ||
| 901 | */  | 
            ||
| 902 | public function newRoleUpdateStruct()  | 
            ||
| 906 | |||
| 907 | /**  | 
            ||
| 908 | * Returns the LimitationType registered with the given identifier.  | 
            ||
| 909 | *  | 
            ||
| 910 | * @param string $identifier  | 
            ||
| 911 | *  | 
            ||
| 912 | * @return \eZ\Publish\SPI\Limitation\Type  | 
            ||
| 913 | *  | 
            ||
| 914 | * @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException if there is no LimitationType with $identifier  | 
            ||
| 915 | */  | 
            ||
| 916 | public function getLimitationType($identifier)  | 
            ||
| 920 | |||
| 921 | /**  | 
            ||
| 922 | * Returns the LimitationType's assigned to a given module/function.  | 
            ||
| 923 | *  | 
            ||
| 924 | * Typically used for:  | 
            ||
| 925 | * - Internal validation limitation value use on Policies  | 
            ||
| 926 | * - Role admin gui for editing policy limitations incl list limitation options via valueSchema()  | 
            ||
| 927 | *  | 
            ||
| 928 | * @param string $module Legacy name of "controller", it's a unique identifier like "content"  | 
            ||
| 929 | * @param string $function Legacy name of a controller "action", it's a unique within the controller like "read"  | 
            ||
| 930 | *  | 
            ||
| 931 | * @return \eZ\Publish\SPI\Limitation\Type[]  | 
            ||
| 932 | *  | 
            ||
| 933 | * @throws \eZ\Publish\API\Repository\Exceptions\BadStateException If module/function to limitation type mapping  | 
            ||
| 934 | * refers to a non existing identifier.  | 
            ||
| 935 | */  | 
            ||
| 936 | public function getLimitationTypesByModuleFunction($module, $function)  | 
            ||
| 940 | }  | 
            ||
| 941 | 
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: