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

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