1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Facile\MongoDbBundle\Models; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class QueryLog. |
9
|
|
|
* @internal |
10
|
|
|
*/ |
11
|
|
|
class QueryLog |
12
|
|
|
{ |
13
|
|
|
/** @var float */ |
14
|
|
|
private $start; |
15
|
|
|
/** @var string */ |
16
|
|
|
private $method; |
17
|
|
|
/** @var string */ |
18
|
|
|
private $collection; |
19
|
|
|
/** @var array|object */ |
20
|
|
|
private $filters; |
21
|
|
|
/** @var array */ |
22
|
|
|
private $data; |
23
|
|
|
/** @var array */ |
24
|
|
|
private $options; |
25
|
|
|
/** @var int */ |
26
|
|
|
private $executionTime; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* QueryLog constructor. |
30
|
|
|
*/ |
31
|
14 |
|
public function __construct() |
32
|
|
|
{ |
33
|
14 |
|
$this->start = microtime(true); |
34
|
14 |
|
$this->collection = 'undefined'; |
35
|
14 |
|
$this->method = 'undefined'; |
36
|
14 |
|
$this->filters = []; |
37
|
14 |
|
$this->data = []; |
38
|
14 |
|
$this->options = []; |
39
|
14 |
|
$this->executionTime = 0; |
40
|
14 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @return float |
44
|
|
|
*/ |
45
|
11 |
|
public function getStart(): float |
46
|
|
|
{ |
47
|
11 |
|
return $this->start; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @param float $start |
52
|
|
|
*/ |
53
|
|
|
public function setStart(float $start) |
54
|
|
|
{ |
55
|
|
|
$this->start = $start; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* @return string |
60
|
|
|
*/ |
61
|
1 |
|
public function getCollection(): string |
62
|
|
|
{ |
63
|
1 |
|
return $this->collection; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $collection |
68
|
|
|
*/ |
69
|
13 |
|
public function setCollection(string $collection) |
70
|
|
|
{ |
71
|
13 |
|
$this->collection = $collection; |
72
|
13 |
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return string |
76
|
|
|
*/ |
77
|
1 |
|
public function getMethod(): string |
78
|
|
|
{ |
79
|
1 |
|
return $this->method; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @param string $method |
84
|
|
|
*/ |
85
|
12 |
|
public function setMethod(string $method) |
86
|
|
|
{ |
87
|
12 |
|
$this->method = $method; |
88
|
12 |
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return array |
92
|
|
|
*/ |
93
|
|
|
public function getFilters(): array |
94
|
|
|
{ |
95
|
|
|
return $this->filters; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @param array|object $filters |
100
|
|
|
*/ |
101
|
11 |
|
public function setFilters($filters) |
102
|
|
|
{ |
103
|
11 |
|
$this->filters = (array) $filters ?? []; |
104
|
11 |
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @return array|object |
108
|
|
|
*/ |
109
|
1 |
|
public function getData() |
110
|
|
|
{ |
111
|
1 |
|
return $this->data; |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* @param array|object $data |
116
|
|
|
*/ |
117
|
13 |
|
public function setData($data) |
118
|
|
|
{ |
119
|
13 |
|
$this->data = $data ?? []; |
|
|
|
|
120
|
13 |
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @return array |
124
|
|
|
*/ |
125
|
|
|
public function getOptions(): array |
126
|
|
|
{ |
127
|
|
|
return $this->options; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* @param array $options |
132
|
|
|
*/ |
133
|
11 |
|
public function setOptions(array $options) |
134
|
|
|
{ |
135
|
11 |
|
$this->options = $options; |
136
|
11 |
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* @return float |
140
|
|
|
*/ |
141
|
2 |
|
public function getExecutionTime(): float |
142
|
|
|
{ |
143
|
2 |
|
return $this->executionTime; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* @param float $executionTime |
148
|
|
|
*/ |
149
|
12 |
|
public function setExecutionTime(float $executionTime) |
150
|
|
|
{ |
151
|
12 |
|
$this->executionTime = $executionTime; |
|
|
|
|
152
|
12 |
|
} |
153
|
|
|
} |
154
|
|
|
|
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 theid
property of an instance of theAccount
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.