Code Duplication    Length = 12-12 lines in 3 locations

eZ/Publish/Core/REST/Server/Controller/Role.php 3 locations

@@ 499-510 (lines=12) @@
496
        try {
497
            // First try to treat $roleId as a role draft ID.
498
            $role = $this->roleService->loadRoleDraft($roleId);
499
            foreach ($role->getPolicies() as $policy) {
500
                if ($policy->id == $policyId) {
501
                    try {
502
                        return $this->roleService->updatePolicy(
503
                            $policy,
504
                            $updateStruct
505
                        );
506
                    } catch (LimitationValidationException $e) {
507
                        throw new BadRequestException($e->getMessage());
508
                    }
509
                }
510
            }
511
        } catch (NotFoundException $e) {
512
            // Then try to treat $roleId as a role ID.
513
            $role = $this->roleService->loadRole($roleId);
@@ 514-525 (lines=12) @@
511
        } catch (NotFoundException $e) {
512
            // Then try to treat $roleId as a role ID.
513
            $role = $this->roleService->loadRole($roleId);
514
            foreach ($role->getPolicies() as $policy) {
515
                if ($policy->id == $policyId) {
516
                    try {
517
                        return $this->roleService->updatePolicy(
518
                            $policy,
519
                            $updateStruct
520
                        );
521
                    } catch (LimitationValidationException $e) {
522
                        throw new BadRequestException($e->getMessage());
523
                    }
524
                }
525
            }
526
        }
527
528
        throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'.");
@@ 554-565 (lines=12) @@
551
        );
552
553
        $role = $this->roleService->loadRoleDraft($roleId);
554
        foreach ($role->getPolicies() as $policy) {
555
            if ($policy->id == $policyId) {
556
                try {
557
                    return $this->roleService->updatePolicy(
558
                        $policy,
559
                        $updateStruct
560
                    );
561
                } catch (LimitationValidationException $e) {
562
                    throw new BadRequestException($e->getMessage());
563
                }
564
            }
565
        }
566
567
        throw new Exceptions\NotFoundException("Policy not found: '{$request->getPathInfo()}'.");
568
    }