Completed
Push — master ( 65ba07...f0ec2b )
by André
104:16 queued 82:47
created

TermParser::parse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * File containing the facet builder Term parser 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\Input\Parser\FacetBuilder;
10
11
use eZ\Publish\Core\REST\Common\Input\BaseParser;
12
use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
13
use eZ\Publish\Core\REST\Common\Exceptions;
14
use eZ\Publish\API\Repository\Values\Content\Query\FacetBuilder\TermFacetBuilder;
15
16
/**
17
 * Parser for Term facet builder.
18
 */
19
class TermParser extends BaseParser
20
{
21
    /**
22
     * Parses input structure to a FacetBuilder object.
23
     *
24
     * @param array $data
25
     * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
26
     *
27
     * @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser
28
     *
29
     * @return \eZ\Publish\API\Repository\Values\Content\Query\FacetBuilder\TermFacetBuilder
30
     */
31
    public function parse(array $data, ParsingDispatcher $parsingDispatcher)
32
    {
33
        if (!array_key_exists('Term', $data)) {
34
            throw new Exceptions\Parser('Invalid <Term> format');
35
        }
36
37
        return new TermFacetBuilder($data['Term']);
38
    }
39
}
40