Passed
Pull Request — master (#18)
by Marc
03:37
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\Query\MessageInterface;
7
use TBolier\RethinkQL\Query\QueryInterface;
8
use TBolier\RethinkQL\RethinkInterface;
9
use TBolier\RethinkQL\Types\Term\TermType;
10
11
class Insert 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 8
    public function __construct(
29
        RethinkInterface $rethink,
30
        MessageInterface $message,
31
        QueryInterface $query,
32
        array $documents
33
    ) {
34 8
        parent::__construct($rethink, $message);
35
36 8
        $this->query = $query;
37 8
        $this->predicate = $documents;
38 8
        $this->rethink = $rethink;
39 8
        $this->message = $message;
40 8
    }
41
42
    /**
43
     * @inheritdoc
44
     */
45 8
    public function toArray(): array
46
    {
47 8
        $jsonDocuments = [];
48 8
        foreach ($this->predicate as $key => $document) {
49 8
            $jsonDocuments[] = json_encode($document);
50
        }
51
52
        return [
53 8
            TermType::INSERT,
54
            [
55 8
                $this->query->toArray(),
56
                [
57
                    TermType::JSON,
58 8
                    $jsonDocuments,
59
                ],
60
            ],
61
        ];
62
    }
63
}
64