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

Update::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 4
crap 1
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 Update extends AbstractQuery
13
{
14
    /**
15
     * @var array
16
     */
17
    private $documents;
18
19
    /**
20
     * @var QueryInterface
21
     */
22
    private $query;
23
24
    /**
25
     * @param RethinkInterface $rethink
26
     * @param MessageInterface $message
27
     * @param QueryInterface $query
28
     * @param array $documents
29
     */
30 1
    public function __construct(
31
        RethinkInterface $rethink,
32
        MessageInterface $message,
33
        QueryInterface $query,
34
        array $documents
35
    ) {
36 1
        parent::__construct($rethink, $message);
37
38 1
        $this->query = $query;
39 1
        $this->documents = $documents;
40 1
        $this->rethink = $rethink;
41 1
        $this->message = $message;
42 1
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47 1
    public function toArray(): array
48
    {
49 1
        $jsonDocuments = [];
50 1
        foreach ($this->documents as $key => $document) {
51 1
            $jsonDocuments[] = json_encode($document);
52
        }
53
54
        return [
55 1
            TermType::UPDATE,
56
            [
57 1
                $this->query->toArray(),
58
                [
59
                    TermType::JSON,
60 1
                    $jsonDocuments,
61
                ],
62
            ],
63
        ];
64
    }
65
}
66