From 8112f56b4ab79e744aa659b3d9de8634e333b099 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Tue, 7 Jul 2020 09:09:55 +0200 Subject: [PATCH] PHP 8.0 | Tokenizer/PHP: array return type keyword to T_STRING vs PHP8 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. --- src/Tokenizers/PHP.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Tokenizers/PHP.php b/src/Tokenizers/PHP.php index 1ad85c4156..5e6edd2038 100644 --- a/src/Tokenizers/PHP.php +++ b/src/Tokenizers/PHP.php @@ -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, ]; @@ -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) {