1212 */
1313class DecoderTest extends TestCase
1414{
15+ /**
16+ * @var array<array<string, mixed>>
17+ */
1518 private $ arrays = [
1619 [
1720 'expected ' => [],
@@ -37,6 +40,9 @@ class DecoderTest extends TestCase
3740 ],
3841 ];
3942
43+ /**
44+ * @var array<array<string, mixed>>
45+ */
4046 private $ booleans = [
4147 [
4248 'expected ' => false ,
@@ -48,6 +54,9 @@ class DecoderTest extends TestCase
4854 ],
4955 ];
5056
57+ /**
58+ * @var array<array<string, mixed>>
59+ */
5160 private $ doubles = [
5261 ['expected ' => 0.0 , 'input ' => [0x68 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ]],
5362 ['expected ' => 0.5 , 'input ' => [0x68 , 0x3F , 0xE0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 , 0x0 ]],
@@ -59,6 +68,9 @@ class DecoderTest extends TestCase
5968 ['expected ' => -1073741824.12457 , 'input ' => [0x68 , 0xC1 , 0xD0 , 0x0 , 0x0 , 0x0 , 0x7 , 0xF8 , 0xF4 ]],
6069 ];
6170
71+ /**
72+ * @var array<array<string, mixed>>
73+ */
6274 private $ floats = [
6375 ['expected ' => 0.0 , 'input ' => [0x4 , 0x8 , 0x0 , 0x0 , 0x0 , 0x0 ]],
6476 ['expected ' => 1.0 , 'input ' => [0x4 , 0x8 , 0x3F , 0x80 , 0x0 , 0x0 ]],
@@ -73,6 +85,9 @@ class DecoderTest extends TestCase
7385
7486 // PHP can't have arrays/objects as keys. Maybe redo all of the tests
7587 // this way so that we can use one test runner
88+ /**
89+ * @var array<array<string, mixed>>
90+ */
7691 private $ maps = [
7792 [
7893 'expected ' => [],
@@ -137,22 +152,28 @@ class DecoderTest extends TestCase
137152 ],
138153 ];
139154
140- private function pointers ()
155+ /**
156+ * @return array<array<string, mixed>>
157+ */
158+ private function pointers (): array
141159 {
142160 return [
143- ['expected ' => 0 , 'input ' => [0x20 , 0x0 ]],
144- ['expected ' => 5 , 'input ' => [0x20 , 0x5 ]],
145- ['expected ' => 10 , 'input ' => [0x20 , 0xa ]],
146- ['expected ' => 1023 , 'input ' => [0x23 , 0xff ]],
147- ['expected ' => 3017 , 'input ' => [0x28 , 0x3 , 0xc9 ]],
148- ['expected ' => 524283 , 'input ' => [0x2f , 0xf7 , 0xfb ]],
149- ['expected ' => 526335 , 'input ' => [0x2f , 0xff , 0xff ]],
150- ['expected ' => 134217726 , 'input ' => [0x37 , 0xf7 , 0xf7 , 0xfe ]],
151- ['expected ' => PHP_INT_MAX < 4294967295 ? '2147483647 ' : 2147483647 , 'input ' => [0x38 , 0x7f , 0xff , 0xff , 0xff ]],
152- ['expected ' => PHP_INT_MAX < 4294967295 ? '4294967295 ' : 4294967295 , 'input ' => [0x38 , 0xff , 0xff , 0xff , 0xff ]],
153- ];
161+ ['expected ' => 0 , 'input ' => [0x20 , 0x0 ]],
162+ ['expected ' => 5 , 'input ' => [0x20 , 0x5 ]],
163+ ['expected ' => 10 , 'input ' => [0x20 , 0xa ]],
164+ ['expected ' => 1023 , 'input ' => [0x23 , 0xff ]],
165+ ['expected ' => 3017 , 'input ' => [0x28 , 0x3 , 0xc9 ]],
166+ ['expected ' => 524283 , 'input ' => [0x2f , 0xf7 , 0xfb ]],
167+ ['expected ' => 526335 , 'input ' => [0x2f , 0xff , 0xff ]],
168+ ['expected ' => 134217726 , 'input ' => [0x37 , 0xf7 , 0xf7 , 0xfe ]],
169+ ['expected ' => PHP_INT_MAX < 4294967295 ? '2147483647 ' : 2147483647 , 'input ' => [0x38 , 0x7f , 0xff , 0xff , 0xff ]],
170+ ['expected ' => PHP_INT_MAX < 4294967295 ? '4294967295 ' : 4294967295 , 'input ' => [0x38 , 0xff , 0xff , 0xff , 0xff ]],
171+ ];
154172 }
155173
174+ /**
175+ * @var array<array<string, mixed>>
176+ */
156177 private $ uint16 = [
157178 ['expected ' => 0 , 'input ' => [0xa0 ]],
158179 ['expected ' => 255 , 'input ' => [0xa1 , 0xff ]],
@@ -161,6 +182,9 @@ private function pointers()
161182 ['expected ' => 65535 , 'input ' => [0xa2 , 0xff , 0xff ]],
162183 ];
163184
185+ /**
186+ * @var array<array<string, mixed>>
187+ */
164188 private $ int32 = [
165189 ['expected ' => 0 , 'input ' => [0x0 , 0x1 ]],
166190 ['expected ' => -1 , 'input ' => [0x4 , 0x1 , 0xff , 0xff , 0xff , 0xff ]],
@@ -176,7 +200,10 @@ private function pointers()
176200 ['expected ' => -2147483647 , 'input ' => [0x4 , 0x1 , 0x80 , 0x0 , 0x0 , 0x1 ]],
177201 ];
178202
179- private function strings ()
203+ /**
204+ * @return array<array<string, mixed>>
205+ */
206+ private function strings (): array
180207 {
181208 $ strings = [
182209 ['expected ' => '' , 'input ' => [0x40 ]],
@@ -228,20 +255,26 @@ private function strings()
228255 return $ strings ;
229256 }
230257
231- private function uint32 ()
258+ /**
259+ * @return array<array<string, mixed>>
260+ */
261+ private function uint32 (): array
232262 {
233263 return [
234- ['expected ' => 0 , 'input ' => [0xc0 ]],
235- ['expected ' => 255 , 'input ' => [0xc1 , 0xff ]],
236- ['expected ' => 500 , 'input ' => [0xc2 , 0x1 , 0xf4 ]],
237- ['expected ' => 10872 , 'input ' => [0xc2 , 0x2a , 0x78 ]],
238- ['expected ' => 65535 , 'input ' => [0xc2 , 0xff , 0xff ]],
239- ['expected ' => 16777215 , 'input ' => [0xc3 , 0xff , 0xff , 0xff ]],
240- ['expected ' => PHP_INT_MAX < 4294967295 ? '4294967295 ' : 4294967295 , 'input ' => [0xc4 , 0xff , 0xff , 0xff , 0xff ]],
241- ];
264+ ['expected ' => 0 , 'input ' => [0xc0 ]],
265+ ['expected ' => 255 , 'input ' => [0xc1 , 0xff ]],
266+ ['expected ' => 500 , 'input ' => [0xc2 , 0x1 , 0xf4 ]],
267+ ['expected ' => 10872 , 'input ' => [0xc2 , 0x2a , 0x78 ]],
268+ ['expected ' => 65535 , 'input ' => [0xc2 , 0xff , 0xff ]],
269+ ['expected ' => 16777215 , 'input ' => [0xc3 , 0xff , 0xff , 0xff ]],
270+ ['expected ' => PHP_INT_MAX < 4294967295 ? '4294967295 ' : 4294967295 , 'input ' => [0xc4 , 0xff , 0xff , 0xff , 0xff ]],
271+ ];
242272 }
243273
244- private function bytes ()
274+ /**
275+ * @return array<array<string, mixed>>
276+ */
277+ private function bytes (): array
245278 {
246279 // ugly deep clone
247280 $ bytes = unserialize (serialize ($ this ->strings ()));
@@ -253,7 +286,7 @@ private function bytes()
253286 return $ bytes ;
254287 }
255288
256- public function generateLargeUint ($ bits )
289+ public function generateLargeUint (int $ bits ): array
257290 {
258291 $ ctrlByte = $ bits === 64 ? 0x2 : 0x3 ;
259292
@@ -270,8 +303,6 @@ public function generateLargeUint($bits)
270303 $ expected = bcsub (bcpow ('2 ' , (string ) (8 * $ power )), '1 ' );
271304 } else {
272305 $ this ->markTestSkipped ('This test requires gmp or bcmath. ' );
273-
274- return ;
275306 }
276307 $ input = [$ power , $ ctrlByte ];
277308 for ($ i = 2 ; $ i < 2 + $ power ; ++$ i ) {
@@ -348,14 +379,14 @@ public function testUint128(): void
348379 $ this ->validateTypeDecoding ('uint128 ' , $ this ->generateLargeUint (128 ));
349380 }
350381
351- private function validateTypeDecoding ($ type , $ tests ): void
382+ private function validateTypeDecoding (string $ type , array $ tests ): void
352383 {
353384 foreach ($ tests as $ expected => $ input ) {
354385 $ this ->checkDecoding ($ type , $ input , $ expected );
355386 }
356387 }
357388
358- private function validateTypeDecodingList ($ type , $ tests ): void
389+ private function validateTypeDecodingList (string $ type , array $ tests ): void
359390 {
360391 foreach ($ tests as $ test ) {
361392 $ this ->checkDecoding (
@@ -367,7 +398,8 @@ private function validateTypeDecodingList($type, $tests): void
367398 }
368399 }
369400
370- private function checkDecoding ($ type , $ input , $ expected , $ name = null ): void
401+ // @phpstan-ignore-next-line
402+ private function checkDecoding (string $ type , array $ input , $ expected , $ name = null ): void
371403 {
372404 $ name = $ name || $ expected ;
373405 $ description = "decoded $ type - $ name " ;
0 commit comments