Completed
Push — feature-EZP-25696 ( d6b5d6...ab4954 )
by André
356:19 queued 326:15
created

Query   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 34
rs 10
c 0
b 0
f 0
wmc 5
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B visit() 0 31 5
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