Skip to content

Commit

Permalink
Tokenizer/PHP: add support for static return type to arrow function…
Browse files Browse the repository at this point in the history
… tokenization

Includes unit test.
  • Loading branch information
jrfnl committed Jul 15, 2020
1 parent 5b0b6ab commit 285f465
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
3 changes: 3 additions & 0 deletions tests/Core/Tokenizer/BackfillFnTokenTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
3 changes: 2 additions & 1 deletion tests/Core/Tokenizer/BackfillFnTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -481,6 +481,7 @@ public function testKeywordReturnTypes()
'Parent',
'Callable',
'Array',
'Static',
];

foreach ($testMarkers as $marker) {
Expand Down

0 comments on commit 285f465

Please sign in to comment.