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

Role   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 38
Duplicated Lines 21.05 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
dl 8
loc 38
rs 10
c 0
b 0
f 0
wmc 3
lcom 1
cbo 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A visit() 8 8 2
A visitRoleAttributes() 0 19 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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