Filter::toArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 14
rs 10
ccs 6
cts 6
cp 1
cc 2
nc 2
nop 0
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace TBolier\RethinkQL\Query\Operation;
5
6
use TBolier\RethinkQL\Query\AbstractQuery;
7
use TBolier\RethinkQL\Query\Aggregation\AggregationTrait;
8
use TBolier\RethinkQL\Query\Manipulation\ManipulationTrait;
9
use TBolier\RethinkQL\Query\QueryInterface;
10
use TBolier\RethinkQL\Query\Transformation\TransformationTrait;
11
use TBolier\RethinkQL\RethinkInterface;
12
use TBolier\RethinkQL\Types\Term\TermType;
13
14
class Filter extends AbstractQuery
15
{
16
    use TransformationTrait;
17
    use OperationTrait;
18
    use AggregationTrait;
19
    use ManipulationTrait;
20
21
    /**
22
     * @var array
23
     */
24
    private $predicate;
25
26
    /**
27
     * @var QueryInterface
28 5
     */
29
    private $query;
30
31
    public function __construct(
32
        RethinkInterface $rethink,
33
        QueryInterface $query,
34 5
        array $predicate
35
    ) {
36 5
        parent::__construct($rethink);
37 5
38 5
        $this->query = $query;
39 5
        $this->predicate = [$predicate];
40 5
        $this->rethink = $rethink;
41
    }
42
43
    public function toArray(): array
44
    {
45 5
        $jsonDocuments = [];
46
        foreach ($this->predicate as $key => $document) {
47 5
            $jsonDocuments[] = json_encode($document);
48 5
        }
49 5
50
        return [
51
            TermType::FILTER,
52
            [
53 5
                $this->query->toArray(),
54
                [
55 5
                    TermType::JSON,
56
                    $jsonDocuments,
57
                ],
58 5
            ],
59
        ];
60
    }
61
}
62