From 285f4651fdad878a4257a6082d30bd5051775fa9 Mon Sep 17 00:00:00 2001 From: jrfnl Date: Wed, 15 Jul 2020 07:47:35 +0200 Subject: [PATCH] Tokenizer/PHP: add support for `static` return type to arrow function tokenization Includes unit test. --- src/Tokenizers/PHP.php | 1 + tests/Core/Tokenizer/BackfillFnTokenTest.inc | 3 +++ tests/Core/Tokenizer/BackfillFnTokenTest.php | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Tokenizers/PHP.php b/src/Tokenizers/PHP.php index 2fc86a86d6..7224fb27ec 100644 --- a/src/Tokenizers/PHP.php +++ b/src/Tokenizers/PHP.php @@ -1829,6 +1829,7 @@ protected function processAdditional() T_CALLABLE => T_CALLABLE, T_PARENT => T_PARENT, T_SELF => T_SELF, + T_STATIC => T_STATIC, ]; $closer = $this->tokens[$x]['parenthesis_closer']; diff --git a/tests/Core/Tokenizer/BackfillFnTokenTest.inc b/tests/Core/Tokenizer/BackfillFnTokenTest.inc index 7714a78680..083fe6979c 100644 --- a/tests/Core/Tokenizer/BackfillFnTokenTest.inc +++ b/tests/Core/Tokenizer/BackfillFnTokenTest.inc @@ -75,6 +75,9 @@ fn(callable $a) : callable => $a; /* testArrayReturnType */ fn(array $a) : array => $a; +/* testStaticReturnType */ +fn(array $a) : static => $a; + /* testTernary */ $fn = fn($a) => $a ? /* testTernaryThen */ fn() : string => 'a' : /* testTernaryElse */ fn() : string => 'b'; diff --git a/tests/Core/Tokenizer/BackfillFnTokenTest.php b/tests/Core/Tokenizer/BackfillFnTokenTest.php index 4dbb8b43c4..45bbbb4415 100644 --- a/tests/Core/Tokenizer/BackfillFnTokenTest.php +++ b/tests/Core/Tokenizer/BackfillFnTokenTest.php @@ -466,7 +466,7 @@ public function testNullableNamespace() /** - * Test arrow functions that use self/parent/callable return types. + * Test arrow functions that use self/parent/callable/array/static return types. * * @covers PHP_CodeSniffer\Tokenizers\PHP::processAdditional * @@ -481,6 +481,7 @@ public function testKeywordReturnTypes() 'Parent', 'Callable', 'Array', + 'Static', ]; foreach ($testMarkers as $marker) {