Skip to content

Commit

Permalink
PHP 8.0 | Tokenizer/PHP: array return type keyword to T_STRING vs PHP…
Browse files Browse the repository at this point in the history
…8 union types

`array` keywords used as return types in PHP 8 union types would only be correctly changed to `T_STRING` if they were the first type in the union.

Fixed now.

Includes adding `T_STATIC` to the array of allowed tokens. While previously it wasn't an issue that the token was not included in the array, it is necessary for the token to be there to support union types.

This change will be tested via the union type related tests for the `File::getMethodProperties()` method.
  • Loading branch information
jrfnl committed Sep 20, 2020
1 parent 63c2b22 commit 8112f56
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,7 @@ function return types. We want to keep the parenthesis map clean,
T_SELF => T_SELF,
T_PARENT => T_PARENT,
T_NAMESPACE => T_NAMESPACE,
T_STATIC => T_STATIC,
T_NS_SEPARATOR => T_NS_SEPARATOR,
];

Expand Down Expand Up @@ -1509,12 +1510,14 @@ function return types. We want to keep the parenthesis map clean,
}//end for

// Any T_ARRAY tokens we find between here and the next
// token that can't be part of the return type need to be
// token that can't be part of the return type, need to be
// converted to T_STRING tokens.
for ($x; $x < $numTokens; $x++) {
if (is_array($tokens[$x]) === false || isset($allowed[$tokens[$x][0]]) === false) {
if ((is_array($tokens[$x]) === false && $tokens[$x] !== '|')
|| (is_array($tokens[$x]) === true && isset($allowed[$tokens[$x][0]]) === false)
) {
break;
} else if ($tokens[$x][0] === T_ARRAY) {
} else if (is_array($tokens[$x]) === true && $tokens[$x][0] === T_ARRAY) {
$tokens[$x][0] = T_STRING;

if (PHP_CODESNIFFER_VERBOSITY > 1) {
Expand Down

0 comments on commit 8112f56

Please sign in to comment.