Skip to content

Commit 4e14760

Browse files
committed
New array indexes for the reference and variadic tokens
1 parent f833d48 commit 4e14760

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/Files/File.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1278,14 +1278,18 @@ public function getDeclarationName($stackPtr)
12781278
* 'token' => integer, // The stack pointer to the variable name.
12791279
* 'content' => string, // The full content of the variable definition.
12801280
* 'pass_by_reference' => boolean, // Is the variable passed by reference?
1281+
* 'reference_token' => integer, // The stack pointer to the reference operator
1282+
* // or FALSE if the param is not passed by reference.
12811283
* 'variable_length' => boolean, // Is the param of variable length through use of `...` ?
1284+
* 'variadic_token' => integer, // The stack pointer to the ... operator
1285+
* // or FALSE if the param is not variable length.
12821286
* 'type_hint' => string, // The type hint for the variable.
12831287
* 'type_hint_token' => integer, // The stack pointer to the start of the type hint
12841288
* // or FALSE if there is no type hint.
12851289
* 'type_hint_end_token' => integer, // The stack pointer to the end of the type hint
12861290
* // or FALSE if there is no type hint.
12871291
* 'nullable_type' => boolean, // TRUE if the var type is nullable.
1288-
* 'comma_token' => boolean, // The stack pointer to the comma after the param
1292+
* 'comma_token' => integer, // The stack pointer to the comma after the param
12891293
* // or FALSE if this is the last param.
12901294
* )
12911295
* </code>
@@ -1329,7 +1333,9 @@ public function getMethodParameters($stackPtr)
13291333
$equalToken = null;
13301334
$paramCount = 0;
13311335
$passByReference = false;
1336+
$referenceToken = false;
13321337
$variableLength = false;
1338+
$variadicToken = false;
13331339
$typeHint = '';
13341340
$typeHintToken = false;
13351341
$typeHintEndToken = false;
@@ -1358,13 +1364,15 @@ public function getMethodParameters($stackPtr)
13581364
case T_BITWISE_AND:
13591365
if ($defaultStart === null) {
13601366
$passByReference = true;
1367+
$referenceToken = $i;
13611368
}
13621369
break;
13631370
case T_VARIABLE:
13641371
$currVar = $i;
13651372
break;
13661373
case T_ELLIPSIS:
13671374
$variableLength = true;
1375+
$variadicToken = $i;
13681376
break;
13691377
case T_CALLABLE:
13701378
if ($typeHintToken === false) {
@@ -1459,7 +1467,9 @@ public function getMethodParameters($stackPtr)
14591467
}
14601468

14611469
$vars[$paramCount]['pass_by_reference'] = $passByReference;
1470+
$vars[$paramCount]['reference_token'] = $referenceToken;
14621471
$vars[$paramCount]['variable_length'] = $variableLength;
1472+
$vars[$paramCount]['variadic_token'] = $variadicToken;
14631473
$vars[$paramCount]['type_hint'] = $typeHint;
14641474
$vars[$paramCount]['type_hint_token'] = $typeHintToken;
14651475
$vars[$paramCount]['type_hint_end_token'] = $typeHintEndToken;
@@ -1476,7 +1486,9 @@ public function getMethodParameters($stackPtr)
14761486
$equalToken = null;
14771487
$paramStart = ($i + 1);
14781488
$passByReference = false;
1489+
$referenceToken = false;
14791490
$variableLength = false;
1491+
$variadicToken = false;
14801492
$typeHint = '';
14811493
$typeHintToken = false;
14821494
$nullableType = false;

tests/Core/File/GetMethodParametersTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ public function testPassByReference()
9090
unset($found[0]['type_hint_token']);
9191
unset($found[0]['type_hint_end_token']);
9292
unset($found[0]['comma_token']);
93+
unset($found[0]['reference_token']);
94+
unset($found[0]['variadic_token']);
9395
$this->assertSame($expected, $found);
9496

9597
}//end testPassByReference()
@@ -126,6 +128,8 @@ public function testArrayHint()
126128
unset($found[0]['type_hint_token']);
127129
unset($found[0]['type_hint_end_token']);
128130
unset($found[0]['comma_token']);
131+
unset($found[0]['reference_token']);
132+
unset($found[0]['variadic_token']);
129133
$this->assertSame($expected, $found);
130134

131135
}//end testArrayHint()
@@ -175,6 +179,10 @@ public function testTypeHint()
175179
unset($found[1]['type_hint_end_token']);
176180
unset($found[0]['comma_token']);
177181
unset($found[1]['comma_token']);
182+
unset($found[0]['reference_token']);
183+
unset($found[1]['reference_token']);
184+
unset($found[0]['variadic_token']);
185+
unset($found[1]['variadic_token']);
178186
$this->assertSame($expected, $found);
179187

180188
}//end testTypeHint()
@@ -211,6 +219,8 @@ public function testSelfTypeHint()
211219
unset($found[0]['type_hint_token']);
212220
unset($found[0]['type_hint_end_token']);
213221
unset($found[0]['comma_token']);
222+
unset($found[0]['reference_token']);
223+
unset($found[0]['variadic_token']);
214224
$this->assertSame($expected, $found);
215225

216226
}//end testSelfTypeHint()
@@ -260,6 +270,10 @@ public function testNullableTypeHint()
260270
unset($found[1]['type_hint_end_token']);
261271
unset($found[0]['comma_token']);
262272
unset($found[1]['comma_token']);
273+
unset($found[0]['reference_token']);
274+
unset($found[1]['reference_token']);
275+
unset($found[0]['variadic_token']);
276+
unset($found[1]['variadic_token']);
263277
$this->assertSame($expected, $found);
264278

265279
}//end testNullableTypeHint()
@@ -296,6 +310,8 @@ public function testVariable()
296310
unset($found[0]['type_hint_token']);
297311
unset($found[0]['type_hint_end_token']);
298312
unset($found[0]['comma_token']);
313+
unset($found[0]['reference_token']);
314+
unset($found[0]['variadic_token']);
299315
$this->assertSame($expected, $found);
300316

301317
}//end testVariable()
@@ -333,6 +349,8 @@ public function testSingleDefaultValue()
333349
unset($found[0]['type_hint_token']);
334350
unset($found[0]['type_hint_end_token']);
335351
unset($found[0]['comma_token']);
352+
unset($found[0]['reference_token']);
353+
unset($found[0]['variadic_token']);
336354
unset($found[0]['default_token']);
337355
unset($found[0]['default_equal_token']);
338356
$this->assertSame($expected, $found);
@@ -385,6 +403,10 @@ public function testDefaultValues()
385403
unset($found[1]['type_hint_end_token']);
386404
unset($found[0]['comma_token']);
387405
unset($found[1]['comma_token']);
406+
unset($found[0]['reference_token']);
407+
unset($found[1]['reference_token']);
408+
unset($found[0]['variadic_token']);
409+
unset($found[1]['variadic_token']);
388410
unset($found[0]['default_token']);
389411
unset($found[1]['default_token']);
390412
unset($found[0]['default_equal_token']);
@@ -426,6 +448,8 @@ public function testBitwiseAndConstantExpressionDefaultValue()
426448
unset($found[0]['type_hint_token']);
427449
unset($found[0]['type_hint_end_token']);
428450
unset($found[0]['comma_token']);
451+
unset($found[0]['reference_token']);
452+
unset($found[0]['variadic_token']);
429453
unset($found[0]['default_token']);
430454
unset($found[0]['default_equal_token']);
431455
$this->assertSame($expected, $found);

0 commit comments

Comments
 (0)