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

Policy::visit()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 1
nop 3
dl 8
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the Policy 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\PolicyDraft;
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
use eZ\Publish\API\Repository\Values\User\Policy as PolicyValue;
16
17
/**
18
 * Policy value object visitor.
19
 */
20
class Policy extends ValueObjectVisitor
21
{
22
    /**
23
     * Visit struct returned by controllers.
24
     *
25
     * @param \eZ\Publish\Core\REST\Common\Output\Visitor $visitor
26
     * @param \eZ\Publish\Core\REST\Common\Output\Generator $generator
27
     * @param Policy|PolicyDraft $data
28
     */
29 View Code Duplication
    public function visit(Visitor $visitor, Generator $generator, $data)
30
    {
31
        $generator->startObjectElement('Policy');
32
        $visitor->setHeader('Content-Type', $generator->getMediaType($data instanceof PolicyDraft ? 'PolicyDraft' : 'Policy'));
33
        $visitor->setHeader('Accept-Patch', $generator->getMediaType('PolicyUpdate'));
34
        $this->visitPolicyAttributes($visitor, $generator, $data);
0 ignored issues
show
Bug introduced by
It seems like $data defined by parameter $data on line 29 can also be of type object<eZ\Publish\Core\R...ueObjectVisitor\Policy>; however, eZ\Publish\Core\REST\Ser...visitPolicyAttributes() does only seem to accept object<eZ\Publish\API\Re...ory\Values\User\Policy>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
35
        $generator->endObjectElement('Policy');
36
    }
37
38
    protected function visitPolicyAttributes(Visitor $visitor, Generator $generator, PolicyValue $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...
39
    {
40
        $generator->startAttribute(
41
            'href',
42
            $this->router->generate('ezpublish_rest_loadPolicy', array('roleId' => $data->roleId, 'policyId' => $data->id))
43
        );
44
        $generator->endAttribute('href');
45
46
        $generator->startValueElement('id', $data->id);
47
        $generator->endValueElement('id');
48
49
        if ($data instanceof PolicyDraft) {
50
            $generator->startValueElement('originalId', $data->originalId);
51
            $generator->endValueElement('originalId');
52
        }
53
54
        $generator->startValueElement('module', $data->module);
55
        $generator->endValueElement('module');
56
57
        $generator->startValueElement('function', $data->function);
58
        $generator->endValueElement('function');
59
60
        $limitations = $data->getLimitations();
61 View Code Duplication
        if (!empty($limitations)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
62
            $generator->startHashElement('limitations');
63
            $generator->startList('limitation');
64
65
            foreach ($limitations as $limitation) {
66
                $this->visitLimitation($generator, $limitation);
67
            }
68
69
            $generator->endList('limitation');
70
            $generator->endHashElement('limitations');
71
        }
72
    }
73
}
74