Completed
Push — master ( 553bc5...721b68 )
by
unknown
49:35 queued 26:20
created

Role::visitRoleAttributes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 13
nc 1
nop 3
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the Role ValueObjectVisitor class.
5
 *
6
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
7
 * @license For full copyright and license information view LICENSE file distributed with this source code.
8
 */
9
namespace eZ\Publish\Core\REST\Server\Output\ValueObjectVisitor;
10
11
use eZ\Publish\API\Repository\Values\User\RoleDraft;
12
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
13
use eZ\Publish\Core\REST\Common\Output\Generator;
14
use eZ\Publish\Core\REST\Common\Output\Visitor;
15
16
/**
17
 * Role value object visitor.
18
 */
19
class Role extends ValueObjectVisitor
20
{
21
    /**
22
     * Visit struct returned by controllers.
23
     *
24
     * @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor
25
     * @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
26
     * @param Role|RoleDraft $data
27
     */
28 View Code Duplication
    public function visit(Visitor $visitor, Generator $generator, $data)
29
    {
30
        $generator->startObjectElement('Role');
31
        $visitor->setHeader('Content-Type', $generator->getMediaType($data instanceof RoleDraft ? 'RoleDraft' : 'Role'));
32
        $visitor->setHeader('Accept-Patch', $generator->getMediaType('RoleInput'));
33
        $this->visitRoleAttributes($visitor, $generator, $data);
34
        $generator->endObjectElement('Role');
35
    }
36
37
    protected function visitRoleAttributes(Visitor $visitor, Generator $generator, $data)
0 ignored issues
show
Unused Code introduced by
The parameter $visitor is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
38
    {
39
        $generator->startAttribute(
40
            'href',
41
            $this->router->generate('ezpublish_rest_loadRole', array('roleId' => $data->id))
42
        );
43
        $generator->endAttribute('href');
44
45
        $generator->startValueElement('identifier', $data->identifier);
46
        $generator->endValueElement('identifier');
47
48
        $generator->startObjectElement('Policies', 'PolicyList');
49
        $generator->startAttribute(
50
            'href',
51
            $this->router->generate('ezpublish_rest_loadPolicies', array('roleId' => $data->id))
52
        );
53
        $generator->endAttribute('href');
54
        $generator->endObjectElement('Policies');
55
    }
56
}
57