Code Duplication    Length = 24-28 lines in 3 locations

eZ/Publish/Core/REST/Server/Controller/ContentType.php 1 location

@@ 440-467 (lines=28) @@
437
     *
438
     * @return \eZ\Publish\Core\REST\Server\Values\RestContentType
439
     */
440
    public function updateContentTypeDraft($contentTypeId, Request $request)
441
    {
442
        $contentTypeDraft = $this->contentTypeService->loadContentTypeDraft($contentTypeId);
443
        $contentTypeUpdateStruct = $this->inputDispatcher->parse(
444
            new Message(
445
                array(
446
                    'Content-Type' => $request->headers->get('Content-Type'),
447
                ),
448
                $request->getContent()
449
            )
450
        );
451
452
        try {
453
            $this->contentTypeService->updateContentTypeDraft(
454
                $contentTypeDraft,
455
                $contentTypeUpdateStruct
456
            );
457
        } catch (InvalidArgumentException $e) {
458
            throw new ForbiddenException($e->getMessage());
459
        }
460
461
        return new Values\RestContentType(
462
            // Reload the content type draft to get the updated values
463
            $this->contentTypeService->loadContentTypeDraft(
464
                $contentTypeDraft->id
465
            )
466
        );
467
    }
468
469
    /**
470
     * Creates a new field definition for the given content type draft.

eZ/Publish/Core/REST/Server/Controller/ObjectState.php 1 location

@@ 94-120 (lines=27) @@
91
     *
92
     * @return \eZ\Publish\Core\REST\Server\Values\CreatedObjectState
93
     */
94
    public function createObjectState($objectStateGroupId, Request $request)
95
    {
96
        $objectStateGroup = $this->objectStateService->loadObjectStateGroup($objectStateGroupId);
97
98
        try {
99
            $createdObjectState = $this->objectStateService->createObjectState(
100
                $objectStateGroup,
101
                $this->inputDispatcher->parse(
102
                    new Message(
103
                        array('Content-Type' => $request->headers->get('Content-Type')),
104
                        $request->getContent()
105
                    )
106
                )
107
            );
108
        } catch (InvalidArgumentException $e) {
109
            throw new ForbiddenException($e->getMessage());
110
        }
111
112
        return new Values\CreatedObjectState(
113
            array(
114
                'objectState' => new RestObjectState(
115
                    $createdObjectState,
116
                    $objectStateGroup->id
117
                ),
118
            )
119
        );
120
    }
121
122
    /**
123
     * Loads an object state group.

eZ/Publish/Core/REST/Server/Controller/Role.php 1 location

@@ 430-453 (lines=24) @@
427
     *
428
     * @return \eZ\Publish\Core\REST\Server\Values\CreatedPolicy
429
     */
430
    public function addPolicyByRoleDraft($roleId, Request $request)
431
    {
432
        $createStruct = $this->inputDispatcher->parse(
433
            new Message(
434
                array('Content-Type' => $request->headers->get('Content-Type')),
435
                $request->getContent()
436
            )
437
        );
438
439
        try {
440
            $role = $this->roleService->addPolicyByRoleDraft(
441
                $this->roleService->loadRoleDraft($roleId),
442
                $createStruct
443
            );
444
        } catch (LimitationValidationException $e) {
445
            throw new BadRequestException($e->getMessage());
446
        }
447
448
        return new Values\CreatedPolicy(
449
            array(
450
                'policy' => $this->getLastAddedPolicy($role),
451
            )
452
        );
453
    }
454
455
    /**
456
     * Get the last added policy for $role.