Code Duplication    Length = 24-28 lines in 4 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 2 locations

@@ 386-409 (lines=24) @@
383
     *
384
     * @return \eZ\Publish\Core\REST\Server\Values\CreatedPolicy
385
     */
386
    public function addPolicy($roleId, Request $request)
387
    {
388
        $createStruct = $this->inputDispatcher->parse(
389
            new Message(
390
                array('Content-Type' => $request->headers->get('Content-Type')),
391
                $request->getContent()
392
            )
393
        );
394
395
        try {
396
            $role = $this->roleService->addPolicy(
397
                $this->roleService->loadRole($roleId),
398
                $createStruct
399
            );
400
        } catch (LimitationValidationException $e) {
401
            throw new BadRequestException($e->getMessage());
402
        }
403
404
        return new Values\CreatedPolicy(
405
            array(
406
                'policy' => $this->getLastAddedPolicy($role),
407
            )
408
        );
409
    }
410
411
    /**
412
     * Adds a policy to a role draft.
@@ 420-443 (lines=24) @@
417
     *
418
     * @return \eZ\Publish\Core\REST\Server\Values\CreatedPolicy
419
     */
420
    public function addPolicyByRoleDraft($roleId, Request $request)
421
    {
422
        $createStruct = $this->inputDispatcher->parse(
423
            new Message(
424
                array('Content-Type' => $request->headers->get('Content-Type')),
425
                $request->getContent()
426
            )
427
        );
428
429
        try {
430
            $role = $this->roleService->addPolicyByRoleDraft(
431
                $this->roleService->loadRoleDraft($roleId),
432
                $createStruct
433
            );
434
        } catch (LimitationValidationException $e) {
435
            throw new BadRequestException($e->getMessage());
436
        }
437
438
        return new Values\CreatedPolicy(
439
            array(
440
                'policy' => $this->getLastAddedPolicy($role),
441
            )
442
        );
443
    }
444
445
    /**
446
     * Get the last added policy for $role.