ExprMessage::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 5
rs 10
ccs 0
cts 0
cp 0
cc 1
nc 1
nop 3
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
    public function __construct(int $queryType = null, string $query = '', OptionsInterface $options = null)
27
    {
28
        $this->queryType = $queryType ?? QueryType::START;
29
        $this->query = $query ?? '';
30
        $this->options = $options ?? new Options();
31 2
    }
32
33 2
    public function getQueryType(): int
34 2
    {
35 2
        return $this->queryType;
36 2
    }
37
38
    public function setCommand(int $queryType): MessageInterface
39
    {
40
        $this->queryType = $queryType;
41
42
        return $this;
43
    }
44
45
    public function setQuery($query): MessageInterface
46
    {
47
        $this->query = (string) $query;
48
49
        return $this;
50
    }
51
52
    public function getOptions(): OptionsInterface
53
    {
54
        return $this->options;
55
    }
56
57
    public function setOptions(OptionsInterface $options): MessageInterface
58
    {
59
        $this->options = $options;
60
61
        return $this;
62
    }
63
64
    public function toArray(): array
65
    {
66
        return [
67
            $this->queryType,
68
            $this->query,
69 1
            (object) $this->getOptions(),
70
        ];
71 1
    }
72
73
    public function jsonSerialize(): array
74
    {
75
        return $this->toArray();
76
    }
77
}
78