Passed
Pull Request — master (#34)
by Marc
05:44
created

Filter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
dl 0
loc 49
rs 10
c 0
b 0
f 0
ccs 14
cts 14
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 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\Message\MessageInterface;
7
use TBolier\RethinkQL\Query\QueryInterface;
8
use TBolier\RethinkQL\Query\Transformation\AbstractTransformationCompound;
9
use TBolier\RethinkQL\RethinkInterface;
10
use TBolier\RethinkQL\Types\Term\TermType;
11
12
class Filter extends AbstractTransformationCompound
13
{
14
    /**
15
     * @var array
16
     */
17
    private $predicate;
18
19
    /**
20
     * @var QueryInterface
21
     */
22
    private $query;
23
24
    /**
25
     * @param RethinkInterface $rethink
26
     * @param MessageInterface $message
27
     * @param QueryInterface $query
28 5
     * @param array $predicate
29
     */
30
    public function __construct(
31
        RethinkInterface $rethink,
32
        MessageInterface $message,
33
        QueryInterface $query,
34 5
        array $predicate
35
    ) {
36 5
        parent::__construct($rethink, $message);
37 5
38 5
        $this->query = $query;
39 5
        $this->predicate = [$predicate];
40 5
        $this->rethink = $rethink;
41
        $this->message = $message;
42
    }
43
44
    /**
45 5
     * @inheritdoc
46
     */
47 5
    public function toArray(): array
48 5
    {
49 5
        $jsonDocuments = [];
50
        foreach ($this->predicate as $key => $document) {
51
            $jsonDocuments[] = json_encode($document);
52
        }
53 5
54
        return [
55 5
            TermType::FILTER,
56
            [
57
                $this->query->toArray(),
58 5
                [
59
                    TermType::JSON,
60
                    $jsonDocuments,
61
                ],
62
            ],
63
        ];
64
    }
65
}
66