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

ExprMessage::setQueryType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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