Passed
Pull Request — master (#18)
by Timon
08:58
created

Filter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 48
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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