Message::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
rs 10
c 0
b 0
f 0
ccs 1
cts 1
cp 1
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace TBolier\RethinkQL\Message;
5
6
use TBolier\RethinkQL\Query\Options;
7
use TBolier\RethinkQL\Query\OptionsInterface;
8
use TBolier\RethinkQL\Types\Query\QueryType;
9
10
class Message implements MessageInterface
11
{
12
    /**
13
     * @var int
14
     */
15
    private $queryType;
16
17
    /**
18
     * @var array
19
     */
20
    private $query;
21
22
    /**
23
     * @var OptionsInterface
24
     */
25
    private $options;
26
27
    public function __construct(int $queryType = null, array $query = null, OptionsInterface $options = null)
28
    {
29
        $this->queryType = $queryType ?? QueryType::START;
30
        $this->query = $query ?? [];
31
        $this->options = $options ?? new Options();
32 22
    }
33
34 22
    public function getQueryType(): int
35 22
    {
36 22
        return $this->queryType;
37 22
    }
38
39
    public function setCommand(int $queryType): MessageInterface
40
    {
41
        $this->queryType = $queryType;
42 1
43
        return $this;
44 1
    }
45
46
    public function setQuery($query): MessageInterface
47
    {
48
        $this->query = (array) $query;
49
50 1
        return $this;
51
    }
52 1
53
    public function getOptions(): OptionsInterface
54 1
    {
55
        return $this->options;
56
    }
57
58
    public function setOptions(OptionsInterface $options): MessageInterface
59
    {
60 17
        $this->options = $options;
61
62 17
        return $this;
63
    }
64 17
65
    public function toArray(): array
66
    {
67
        return [
68
            $this->queryType,
69
            $this->query,
70 18
            (object) $this->getOptions()
71
        ];
72 18
    }
73
74
    public function jsonSerialize(): array
75
    {
76
        return $this->toArray();
77
    }
78
}
79