1 | <?php |
||
13 | class Snowflake |
||
14 | { |
||
15 | const MAX_TIMESTAMP_LENGTH = 41; |
||
16 | |||
17 | const MAX_DATACENTER_LENGTH = 5; |
||
18 | |||
19 | const MAX_WORKID_LENGTH = 5; |
||
20 | |||
21 | const MAX_SEQUENCE_LENGTH = 12; |
||
22 | |||
23 | const MAX_FIRST_LENGTH = 1; |
||
24 | |||
25 | /** |
||
26 | * The data center id. |
||
27 | * |
||
28 | * @var int |
||
29 | */ |
||
30 | protected $datacenter; |
||
31 | |||
32 | /** |
||
33 | * The worker id. |
||
34 | * |
||
35 | * @var int |
||
36 | */ |
||
37 | protected $workerid; |
||
38 | |||
39 | /** |
||
40 | * The Sequence Resolver instance. |
||
41 | * |
||
42 | * @var \Godruoyi\Snowflake\SequenceResolver|null |
||
43 | */ |
||
44 | protected $sequence; |
||
45 | |||
46 | /** |
||
47 | * The start timestamp. |
||
48 | * |
||
49 | * @var int |
||
50 | */ |
||
51 | protected $startTime; |
||
52 | |||
53 | /** |
||
54 | * Build Snowflake Instance. |
||
55 | * |
||
56 | * @param int $datacenter |
||
57 | * @param int $workerid |
||
58 | */ |
||
59 | 10 | public function __construct(int $datacenter = null, int $workerid = null) |
|
68 | |||
69 | /** |
||
70 | * Get snowflake id. |
||
71 | * |
||
72 | * @return int |
||
73 | */ |
||
74 | 5 | public function id() |
|
91 | |||
92 | /** |
||
93 | * Parse snowflake id. |
||
94 | * |
||
95 | * @param string $id |
||
96 | * |
||
97 | * @return array |
||
98 | */ |
||
99 | 3 | public function parseId(string $id, $transform = false): array |
|
114 | |||
115 | /** |
||
116 | * Get current microtime timestamp. |
||
117 | * |
||
118 | * @return int |
||
119 | */ |
||
120 | 7 | public function getCurrentMicrotime() |
|
124 | |||
125 | /** |
||
126 | * Set start time (millisecond). |
||
127 | * |
||
128 | * @param int $startTime |
||
129 | */ |
||
130 | 2 | public function setStartTimeStamp(int $startTime) |
|
141 | |||
142 | /** |
||
143 | * Get start timestamp (millisecond), If not set default to 2019-08-08 08:08:08. |
||
144 | * |
||
145 | * @return int |
||
146 | */ |
||
147 | 6 | public function getStartTimeStamp() |
|
158 | |||
159 | /** |
||
160 | * Set Sequence Resolver. |
||
161 | * |
||
162 | * @param SequenceResolver|callable $sequence |
||
163 | */ |
||
164 | 3 | public function setSequenceResolver($sequence) |
|
170 | |||
171 | /** |
||
172 | * Get Sequence Resolver. |
||
173 | * |
||
174 | * @return \Godruoyi\Snowflake\SequenceResolver|callable|null |
||
175 | */ |
||
176 | 6 | public function getSequenceResolver() |
|
180 | |||
181 | /** |
||
182 | * Get Default Sequence Resolver. |
||
183 | * |
||
184 | * @return \Godruoyi\Snowflake\SequenceResolver |
||
185 | */ |
||
186 | 4 | public function getDefaultSequenceResolver(): SequenceResolver |
|
190 | |||
191 | /** |
||
192 | * Call resolver. |
||
193 | * |
||
194 | * @param callable|\Godruoyi\Snowflake\SequenceResolver $resolver |
||
195 | * @param int $maxSequence |
||
196 | * |
||
197 | * @return int |
||
198 | */ |
||
199 | 5 | protected function callResolver($currentTime) |
|
211 | } |
||
212 |
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.