Passed
Pull Request — master (#18)
by Marc
03:37
created

Update::toArray()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

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