Completed
Branch 1707_add_explain_command (4124c6)
by Alessandro
02:34
created

Query::setOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php declare(strict_types=1);
2
3
namespace Facile\MongoDbBundle\Models;
4
5
/**
6
 * Class Query.
7
 * @internal
8
 */
9
final class Query
10
{
11
    /** @var float */
12
    private $start;
13
    /** @var string */
14
    private $method;
15
    /** @var string */
16
    private $collection;
17
    /** @var array|object */
18
    private $filters;
19
    /** @var array */
20
    private $data;
21
    /** @var array */
22
    private $options;
23
    /** @var int */
24
    private $executionTime;
25
    /** @var string */
26
    private $readPreference;
27
    /** @var string */
28
    private $client;
29
    /** @var string */
30
    private $database;
31
32
    /**
33
     * Query constructor.
34
     */
35 19
    public function __construct()
36
    {
37 19
        $this->start = microtime(true);
38 19
        $this->client = 'undefined';
39 19
        $this->database = 'undefined';
40 19
        $this->collection = 'undefined';
41 19
        $this->method = 'undefined';
42 19
        $this->filters = [];
43 19
        $this->data = [];
44 19
        $this->options = [];
45 19
        $this->executionTime = 0;
46 19
        $this->readPreference = 'undefined';
47 19
    }
48
49
    /**
50
     * @return float
51
     */
52 12
    public function getStart(): float
53
    {
54 12
        return $this->start;
55
    }
56
57
    /**
58
     * @return string
59
     */
60 1
    public function getCollection(): string
61
    {
62 1
        return $this->collection;
63
    }
64
65
    /**
66
     * @param string $collection
67
     */
68 14
    public function setCollection(string $collection)
69
    {
70 14
        $this->collection = $collection;
71 14
    }
72
73
    /**
74
     * @return string
75
     */
76 1
    public function getMethod(): string
77
    {
78 1
        return $this->method;
79
    }
80
81
    /**
82
     * @param string $method
83
     */
84 13
    public function setMethod(string $method)
85
    {
86 13
        $this->method = $method;
87 13
    }
88
89
    /**
90
     * @return array
91
     */
92 15
    public function getFilters(): array
93
    {
94 15
        return $this->filters;
95
    }
96
97
    /**
98
     * @param array|object $filters
99
     */
100 16
    public function setFilters($filters)
101
    {
102 16
        $this->filters = (array)$filters ?? [];
103 16
    }
104
105
    /**
106
     * @return array|object
107
     */
108 10
    public function getData()
109
    {
110 10
        return $this->data;
111
    }
112
113
    /**
114
     * @param array|object $data
115
     */
116 17
    public function setData($data)
117
    {
118 17
        $this->data = $data ?? [];
0 ignored issues
show
Documentation Bug introduced by
It seems like $data ?? array() can also be of type object. However, the property $data 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...
119 17
    }
120
121
    /**
122
     * @return array
123
     */
124 16
    public function getOptions(): array
125
    {
126 16
        return $this->options;
127
    }
128
129
    /**
130
     * @param array $options
131
     */
132 16
    public function setOptions(array $options)
133
    {
134 16
        $this->options = $options;
135 16
    }
136
137
    /**
138
     * @return float
139
     */
140 2
    public function getExecutionTime(): float
141
    {
142 2
        return $this->executionTime;
143
    }
144
145
    /**
146
     * @param float $executionTime
147
     */
148 13
    public function setExecutionTime(float $executionTime)
149
    {
150 13
        $this->executionTime = $executionTime;
0 ignored issues
show
Documentation Bug introduced by
The property $executionTime was declared of type integer, but $executionTime is of type double. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
151 13
    }
152
153
    /**
154
     * @return string
155
     */
156
    public function getReadPreference(): string
157
    {
158
        return $this->readPreference;
159
    }
160
161
    /**
162
     * @param string $readPreference
163
     */
164 12
    public function setReadPreference(string $readPreference)
165
    {
166 12
        $this->readPreference = $readPreference;
167 12
    }
168
169
    /**
170
     * @return string
171
     */
172
    public function getClient(): string
173
    {
174
        return $this->client;
175
    }
176
177
    /**
178
     * @param string $client
179
     */
180 12
    public function setClient(string $client)
181
    {
182 12
        $this->client = $client;
183 12
    }
184
185
    /**
186
     * @return string
187
     */
188
    public function getDatabase(): string
189
    {
190
        return $this->database;
191
    }
192
193
    /**
194
     * @param string $database
195
     */
196 12
    public function setDatabase(string $database)
197
    {
198 12
        $this->database = $database;
199 12
    }
200
}
201