Passed
Pull Request — master (#18)
by Timon
08:58
created

ExprMessage::getQueryType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
     * @var array
17
     */
18
    private $query;
19
    /**
20
     * @var int
21
     */
22
    private $queryType;
23
24
    /**
25
     * @param int $queryType
26
     * @param array $query
27
     * @param OptionsInterface $options
28
     */
29 2
    public function __construct(int $queryType = null, array $query = null, OptionsInterface $options = null)
30
    {
31 2
        $this->queryType = $queryType ?? QueryType::START;
32 2
        $this->query = $query ?? [];
33 2
        $this->options = $options ?? new Options();
34 2
    }
35
36
    /**
37
     * @inheritdoc
38
     */
39
    public function getQueryType(): int
40
    {
41
        return $this->queryType;
42
    }
43
44
    /**
45
     * @inheritdoc
46
     */
47 2
    public function setCommand(int $queryType): MessageInterface
48
    {
49 2
        $this->queryType = $queryType;
50
51 2
        return $this;
52
    }
53
54
    /**
55
     * @inheritdoc
56
     */
57 2
    public function setQuery($query): MessageInterface
58
    {
59 2
        $this->query = $query;
0 ignored issues
show
Documentation Bug introduced by
It seems like $query can also be of type string. However, the property $query is declared as type array. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
60
61 2
        return $this;
62
    }
63
64
    /**
65
     * @inheritdoc
66
     */
67 1
    public function getOptions(): OptionsInterface
68
    {
69 1
        return $this->options;
70
    }
71
72
    /**
73
     * @inheritdoc
74
     */
75 2
    public function setOptions(OptionsInterface $options): MessageInterface
76
    {
77 2
        $this->options = $options;
78
79 2
        return $this;
80
    }
81
82
    /**
83
     * @inheritdoc
84
     */
85 1
    public function toArray(): array
86
    {
87
        return [
88 1
            $this->queryType,
89 1
            $this->query,
90 1
            (object)$this->getOptions(),
91
        ];
92
    }
93
94
    /**
95
     * @return array
96
     */
97 1
    public function jsonSerialize(): array
98
    {
99 1
        return $this->toArray();
100
    }
101
}
102