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

Message::setCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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