Completed
Push — EZP-26146-location-swap-urlali... ( 8c8e66...1d10ee )
by
unknown
327:46 queued 295:37
created

Query::visit()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 31
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 17
nc 9
nop 3
dl 0
loc 31
rs 8.439
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
4
 * @license For full copyright and license information view LICENSE file distributed with this source code.
5
 */
6
namespace eZ\Publish\Core\REST\Client\Output\ValueObjectVisitor;
7
8
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
9
use eZ\Publish\Core\REST\Common\Output\Generator;
10
use eZ\Publish\Core\REST\Common\Output\ValueObjectVisitor;
11
use eZ\Publish\Core\REST\Common\Output\Visitor;
12
use eZ\Publish\Core\Base\Exceptions;
13
use eZ\Publish\API\Repository\Values\Content\LocationQuery as LocationQueryValue;
14
use eZ\Publish\API\Repository\Values\Content\Query as ContentQueryValue;
15
16
class Query extends ValueObjectVisitor
17
{
18
    public function visit(Visitor $visitor, Generator $generator, $data)
19
    {
20
        if ($data instanceof LocationQueryValue) {
21
            $rootObjectElement = 'LocationQuery';
22
        } else if ($data instanceof ContentQueryValue) {
23
            $rootObjectElement = 'ContentQuery';
24
        } else {
25
            throw new Exceptions\InvalidArgumentException("ViewInput Query", "No content nor location query found in ViewInput");
26
        }
27
        $generator->startObjectElement($rootObjectElement, 'Query');
28
29
        if (isset($data->filter)) {
30
            $generator->startHashElement('Filter');
31
            $visitor->visitValueObject($data->filter);
32
            $generator->endHashElement('Filter');
33
        }
34
35
        if (isset($data->query)) {
36
            $generator->startHashElement('Query');
37
            $visitor->visitValueObject($data->query);
38
            $generator->endhashElement('Query');
39
        }
40
41
        // $generator->startObjectElement('SortClauses');
42
        // foreach ($data->sortClauses as $sortClause) {
43
        //     $visitor->visitValueObject($sortClause);
44
        // }
45
        // $generator->endObjectElement('SortClauses');
46
47
        $generator->endObjectElement($rootObjectElement);
48
    }
49
}
50