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

CriterionParser   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A parse() 0 8 2
1
<?php
2
3
/**
4
 * File containing the facet builder Criterion 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\CriterionFacetBuilder;
15
16
/**
17
 * Parser for Criterion facet builder.
18
 */
19
class CriterionParser 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\CriterionFacetBuilder
30
     */
31
    public function parse(array $data, ParsingDispatcher $parsingDispatcher)
32
    {
33
        if (!array_key_exists('Criterion', $data)) {
34
            throw new Exceptions\Parser('Invalid <Criterion> format');
35
        }
36
37
        return new CriterionFacetBuilder($data['Criterion']);
38
    }
39
}
40