Completed
Push — master ( 4896ac...e378d5 )
by Łukasz
24:08
created

BookmarkList::visitAttributes()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 12
nc 2
nop 3
dl 0
loc 20
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
declare(strict_types=1);
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\Core\REST\Server\Values\BookmarkList as BookmarkListValue;
15
16
class BookmarkList extends ValueObjectVisitor
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function visit(Visitor $visitor, Generator $generator, $data)
22
    {
23
        $generator->startObjectElement('BookmarkList');
24
        $visitor->setHeader('Content-Type', $generator->getMediaType('BookmarkList'));
25
26
        $this->visitAttributes($visitor, $generator, $data);
27
        $generator->endObjectElement('BookmarkList');
28
    }
29
30
    protected function visitAttributes(Visitor $visitor, Generator $generator, BookmarkListValue $data): void
31
    {
32
        $generator->startValueElement('count', $data->totalCount);
33
        $generator->endValueElement('count');
34
35
        $generator->startList('items');
36
        foreach ($data->items as $restLocation) {
37
            $generator->startObjectElement('Bookmark');
38
39
            $generator->startAttribute('_href', $this->router->generate('ezpublish_rest_isBookmarked', [
40
                'locationId' => $restLocation->location->id,
41
            ]));
42
            $generator->endAttribute('_href');
43
44
            $visitor->visitValueObject($restLocation);
45
            $generator->endObjectElement('Bookmark');
46
        }
47
48
        $generator->endList('items');
49
    }
50
}
51