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

Section   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
dl 36
loc 36
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A visit() 8 8 1
A visitSectionAttributes() 17 17 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 Section 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\Core\REST\Common\Output\ValueObjectVisitor;
12
use eZ\Publish\Core\REST\Common\Output\Generator;
13
use eZ\Publish\Core\REST\Common\Output\Visitor;
14
use eZ\Publish\API\Repository\Values\Content\Section as SectionValue;
15
16
/**
17
 * Section value object visitor.
18
 */
19 View Code Duplication
class Section extends ValueObjectVisitor
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in 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...
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 \eZ\Publish\API\Repository\Values\Content\Section $data
27
     */
28
    public function visit(Visitor $visitor, Generator $generator, $data)
29
    {
30
        $generator->startObjectElement('Section');
31
        $visitor->setHeader('Content-Type', $generator->getMediaType('Section'));
32
        $visitor->setHeader('Accept-Patch', $generator->getMediaType('SectionInput'));
33
        $this->visitSectionAttributes($visitor, $generator, $data);
34
        $generator->endObjectElement('Section');
35
    }
36
37
    protected function visitSectionAttributes(Visitor $visitor, Generator $generator, SectionValue $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_loadSection', array('sectionId' => $data->id))
42
        );
43
        $generator->endAttribute('href');
44
45
        $generator->startValueElement('sectionId', $data->id);
46
        $generator->endValueElement('sectionId');
47
48
        $generator->startValueElement('identifier', $data->identifier);
49
        $generator->endValueElement('identifier');
50
51
        $generator->startValueElement('name', $data->name);
52
        $generator->endValueElement('name');
53
    }
54
}
55