Insert   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 15
c 1
b 0
f 0
dl 0
loc 37
rs 10
ccs 8
cts 8
cp 1

2 Methods

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