Skip to content

Commit

Permalink
New array indexes for the reference and variadic tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Aug 27, 2019
1 parent f833d48 commit 4e14760
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Files/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -1278,14 +1278,18 @@ public function getDeclarationName($stackPtr)
* 'token' => integer, // The stack pointer to the variable name.
* 'content' => string, // The full content of the variable definition.
* 'pass_by_reference' => boolean, // Is the variable passed by reference?
* 'reference_token' => integer, // The stack pointer to the reference operator
* // or FALSE if the param is not passed by reference.
* 'variable_length' => boolean, // Is the param of variable length through use of `...` ?
* 'variadic_token' => integer, // The stack pointer to the ... operator
* // or FALSE if the param is not variable length.
* 'type_hint' => string, // The type hint for the variable.
* 'type_hint_token' => integer, // The stack pointer to the start of the type hint
* // or FALSE if there is no type hint.
* 'type_hint_end_token' => integer, // The stack pointer to the end of the type hint
* // or FALSE if there is no type hint.
* 'nullable_type' => boolean, // TRUE if the var type is nullable.
* 'comma_token' => boolean, // The stack pointer to the comma after the param
* 'comma_token' => integer, // The stack pointer to the comma after the param
* // or FALSE if this is the last param.
* )
* </code>
Expand Down Expand Up @@ -1329,7 +1333,9 @@ public function getMethodParameters($stackPtr)
$equalToken = null;
$paramCount = 0;
$passByReference = false;
$referenceToken = false;
$variableLength = false;
$variadicToken = false;
$typeHint = '';
$typeHintToken = false;
$typeHintEndToken = false;
Expand Down Expand Up @@ -1358,13 +1364,15 @@ public function getMethodParameters($stackPtr)
case T_BITWISE_AND:
if ($defaultStart === null) {
$passByReference = true;
$referenceToken = $i;
}
break;
case T_VARIABLE:
$currVar = $i;
break;
case T_ELLIPSIS:
$variableLength = true;
$variadicToken = $i;
break;
case T_CALLABLE:
if ($typeHintToken === false) {
Expand Down Expand Up @@ -1459,7 +1467,9 @@ public function getMethodParameters($stackPtr)
}

$vars[$paramCount]['pass_by_reference'] = $passByReference;
$vars[$paramCount]['reference_token'] = $referenceToken;
$vars[$paramCount]['variable_length'] = $variableLength;
$vars[$paramCount]['variadic_token'] = $variadicToken;
$vars[$paramCount]['type_hint'] = $typeHint;
$vars[$paramCount]['type_hint_token'] = $typeHintToken;
$vars[$paramCount]['type_hint_end_token'] = $typeHintEndToken;
Expand All @@ -1476,7 +1486,9 @@ public function getMethodParameters($stackPtr)
$equalToken = null;
$paramStart = ($i + 1);
$passByReference = false;
$referenceToken = false;
$variableLength = false;
$variadicToken = false;
$typeHint = '';
$typeHintToken = false;
$nullableType = false;
Expand Down
24 changes: 24 additions & 0 deletions tests/Core/File/GetMethodParametersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public function testPassByReference()
unset($found[0]['type_hint_token']);
unset($found[0]['type_hint_end_token']);
unset($found[0]['comma_token']);
unset($found[0]['reference_token']);
unset($found[0]['variadic_token']);
$this->assertSame($expected, $found);

}//end testPassByReference()
Expand Down Expand Up @@ -126,6 +128,8 @@ public function testArrayHint()
unset($found[0]['type_hint_token']);
unset($found[0]['type_hint_end_token']);
unset($found[0]['comma_token']);
unset($found[0]['reference_token']);
unset($found[0]['variadic_token']);
$this->assertSame($expected, $found);

}//end testArrayHint()
Expand Down Expand Up @@ -175,6 +179,10 @@ public function testTypeHint()
unset($found[1]['type_hint_end_token']);
unset($found[0]['comma_token']);
unset($found[1]['comma_token']);
unset($found[0]['reference_token']);
unset($found[1]['reference_token']);
unset($found[0]['variadic_token']);
unset($found[1]['variadic_token']);
$this->assertSame($expected, $found);

}//end testTypeHint()
Expand Down Expand Up @@ -211,6 +219,8 @@ public function testSelfTypeHint()
unset($found[0]['type_hint_token']);
unset($found[0]['type_hint_end_token']);
unset($found[0]['comma_token']);
unset($found[0]['reference_token']);
unset($found[0]['variadic_token']);
$this->assertSame($expected, $found);

}//end testSelfTypeHint()
Expand Down Expand Up @@ -260,6 +270,10 @@ public function testNullableTypeHint()
unset($found[1]['type_hint_end_token']);
unset($found[0]['comma_token']);
unset($found[1]['comma_token']);
unset($found[0]['reference_token']);
unset($found[1]['reference_token']);
unset($found[0]['variadic_token']);
unset($found[1]['variadic_token']);
$this->assertSame($expected, $found);

}//end testNullableTypeHint()
Expand Down Expand Up @@ -296,6 +310,8 @@ public function testVariable()
unset($found[0]['type_hint_token']);
unset($found[0]['type_hint_end_token']);
unset($found[0]['comma_token']);
unset($found[0]['reference_token']);
unset($found[0]['variadic_token']);
$this->assertSame($expected, $found);

}//end testVariable()
Expand Down Expand Up @@ -333,6 +349,8 @@ public function testSingleDefaultValue()
unset($found[0]['type_hint_token']);
unset($found[0]['type_hint_end_token']);
unset($found[0]['comma_token']);
unset($found[0]['reference_token']);
unset($found[0]['variadic_token']);
unset($found[0]['default_token']);
unset($found[0]['default_equal_token']);
$this->assertSame($expected, $found);
Expand Down Expand Up @@ -385,6 +403,10 @@ public function testDefaultValues()
unset($found[1]['type_hint_end_token']);
unset($found[0]['comma_token']);
unset($found[1]['comma_token']);
unset($found[0]['reference_token']);
unset($found[1]['reference_token']);
unset($found[0]['variadic_token']);
unset($found[1]['variadic_token']);
unset($found[0]['default_token']);
unset($found[1]['default_token']);
unset($found[0]['default_equal_token']);
Expand Down Expand Up @@ -426,6 +448,8 @@ public function testBitwiseAndConstantExpressionDefaultValue()
unset($found[0]['type_hint_token']);
unset($found[0]['type_hint_end_token']);
unset($found[0]['comma_token']);
unset($found[0]['reference_token']);
unset($found[0]['variadic_token']);
unset($found[0]['default_token']);
unset($found[0]['default_equal_token']);
$this->assertSame($expected, $found);
Expand Down

0 comments on commit 4e14760

Please sign in to comment.