Passed
Pull Request — master (#18)
by Timon
02:57
created

ExprMessage::setOptions()   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
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
     * @inheritdoc
48
     */
49
    public function setCommand(int $queryType): MessageInterface
50
    {
51
        $this->queryType = $queryType;
52
53
        return $this;
54
    }
55
56
    /**
57
     * @inheritdoc
58
     */
59
    public function setQuery($query): MessageInterface
60
    {
61
        $this->query = (string) $query;
62
63
        return $this;
64
    }
65
66
    /**
67
     * @inheritdoc
68
     */
69 1
    public function getOptions(): OptionsInterface
70
    {
71 1
        return $this->options;
72
    }
73
74
    /**
75
     * @inheritdoc
76
     */
77 2
    public function setOptions(OptionsInterface $options): MessageInterface
78
    {
79 2
        $this->options = $options;
80
81 2
        return $this;
82
    }
83
84
    /**
85
     * @inheritdoc
86
     */
87 1
    public function toArray(): array
88
    {
89
        return [
90 1
            $this->queryType,
91 1
            $this->query,
92 1
            (object)$this->getOptions(),
93
        ];
94
    }
95
96
    /**
97
     * @return array
98
     */
99 1
    public function jsonSerialize(): array
100
    {
101 1
        return $this->toArray();
102
    }
103
}
104