Passed
Pull Request — master (#18)
by Timon
02:57
created

Insert   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 53
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 53
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

2 Methods

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