Filter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 19
c 1
b 0
f 0
dl 0
loc 43
rs 10
ccs 13
cts 13
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A toArray() 0 14 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