Update::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 12
rs 10
ccs 6
cts 6
cp 1
cc 1
nc 1
nop 0
crap 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 Update extends AbstractQuery
12
{
13
    /**
14
     * @var array
15
     */
16
    private $elements;
17
18
    /**
19
     * @var QueryInterface
20
     */
21
    private $query;
22
23
    public function __construct(
24
        RethinkInterface $rethink,
25
        QueryInterface $query,
26
        array $elements
27
    ) {
28
        parent::__construct($rethink);
29
30 1
        $this->query = $query;
31
        $this->elements = $elements;
32
        $this->rethink = $rethink;
33
    }
34
35
    public function toArray(): array
36 1
    {
37
        $jsonElements = json_encode($this->elements);
38 1
39 1
        return [
40 1
            TermType::UPDATE,
41 1
            [
42 1
                $this->query->toArray(),
43
                [
44
                    TermType::JSON,
45
                    [
46
                        $jsonElements
47 1
                    ],
48
                ],
49 1
            ],
50 1
        ];
51 1
    }
52
}
53