Passed
Pull Request — master (#35)
by Michel
04:04
created

Message::setCommand()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
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
    /**
28
     * @param int $queryType
29
     * @param array $query
30
     * @param OptionsInterface $options
31
     */
32 22
    public function __construct(int $queryType = null, array $query = null, OptionsInterface $options = null)
33
    {
34 22
        $this->queryType = $queryType ?? QueryType::START;
35 22
        $this->query = $query ?? [];
36 22
        $this->options = $options ?? new Options();
37 22
    }
38
39
    /**
40
     * @inheritdoc
41
     */
42 1
    public function getQueryType(): int
43
    {
44 1
        return $this->queryType;
45
    }
46
47
    /**
48
     * @inheritdoc
49
     */
50 1
    public function setQueryType(int $queryType): void
51
    {
52 1
        $this->queryType = $queryType;
53
    }
54 1
55
    /**
56
     * @inheritdoc
57
     */
58
    public function setCommand(int $queryType): MessageInterface
59
    {
60 17
        $this->queryType = $queryType;
61
62 17
        return $this;
63
    }
64 17
65
    /**
66
     * @inheritdoc
67
     */
68
    public function setQuery($query): MessageInterface
69
    {
70 18
        $this->query = (array) $query;
71
72 18
        return $this;
73
    }
74
75
    /**
76
     * @inheritdoc
77
     */
78 20
    public function getOptions(): OptionsInterface
79
    {
80 20
        return $this->options;
81
    }
82 20
83
    /**
84
     * @inheritdoc
85
     */
86
    public function setOptions(OptionsInterface $options): MessageInterface
87
    {
88 18
        $this->options = $options;
89
90
        return $this;
91 18
    }
92 18
93 18
    /**
94
     * @inheritdoc
95
     */
96
    public function toArray(): array
97
    {
98
        return [
99
            $this->queryType,
100 16
            $this->query,
101
            (object) $this->getOptions()
102 16
        ];
103
    }
104
105
    /**
106
     * @return array
107
     */
108
    public function jsonSerialize(): array
109
    {
110
        return $this->toArray();
111
    }
112
}
113