Completed
Push — EZP-30548-Romanian_special_cha... ( 38d0c8...2c2658 )
by
unknown
41:58 queued 18:37
created

LogicalOperator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 54
rs 10
c 0
b 0
f 0
wmc 8
lcom 0
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 4 1
A getFlattenedCriteriaData() 0 18 5
A isZeroBasedArray() 0 6 2
1
<?php
2
3
/**
4
 * File containing the LogicalOperator 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\Criterion;
10
11
use eZ\Publish\Core\REST\Common\Input\ParsingDispatcher;
12
use eZ\Publish\Core\REST\Server\Input\Parser\Criterion;
13
14
/**
15
 * Parser for LogicalOperator Criterion.
16
 */
17
class LogicalOperator extends Criterion
18
{
19
    /**
20
     * Parses input structure to a Criterion object.
21
     *
22
     * @param array $data
23
     * @param \eZ\Publish\Core\REST\Common\Input\ParsingDispatcher $parsingDispatcher
24
     *
25
     * @throws \eZ\Publish\Core\REST\Common\Exceptions\Parser
26
     *
27
     * @return \eZ\Publish\API\Repository\Values\Content\Query\Criterion\LogicalOperator
28
     */
29
    public function parse(array $data, ParsingDispatcher $parsingDispatcher)
30
    {
31
        throw new \Exception('@todo implement');
32
    }
33
34
    /**
35
     * @param array $criteriaByType
36
     * @return array
37
     */
38
    protected function getFlattenedCriteriaData(array $criteriaByType)
39
    {
40
        $criteria = [];
41
        foreach ($criteriaByType as $type => $criterion) {
42
            if (!is_array($criterion) || !$this->isZeroBasedArray($criterion)) {
43
                $criterion = [$criterion];
44
            }
45
46
            foreach ($criterion as $criterionElement) {
47
                $criteria[] = [
48
                    'type' => $type,
49
                    'data' => $criterionElement,
50
                ];
51
            }
52
        }
53
54
        return $criteria;
55
    }
56
57
    /**
58
     * Checks if the given $value is zero based.
59
     *
60
     * @param array $value
61
     *
62
     * @return bool
63
     */
64
    protected function isZeroBasedArray(array $value)
65
    {
66
        reset($value);
67
68
        return empty($value) || key($value) === 0;
69
    }
70
}
71