Skip to content

Commit 0e4fe74

Browse files
committed
Fixed detection of array return types for arrow functions
1 parent bb50f79 commit 0e4fe74

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
3131
- The PHP 7.4 numeric separator backfill is no longer run on PHP version 7.4.0 or greater
3232
- File::getCondition() now accepts a 3rd argument that allows for the closest matching token to be returned
3333
-- By default, it continues to return the first matched token found from the top of the file
34+
- Fixed detection of array return types for arrow functions
3435
- Added Generic.PHP.DisallowRequestSuperglobal to ban the use of the $_REQUEST superglobal
3536
-- Thanks to Morerice for the contribution
3637
- PSR12.ControlStructures.BooleanOperatorPlacement can now be configured to enforce a specific operator position

src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ abstract function foo(): array;
2121
abstract function foo(): Foo\Bar;
2222

2323
abstract function foo(): \Foo\Bar;
24+
25+
array_map(
26+
static fn (array $value): array => array_filter($value),
27+
[]
28+
);

src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc.fixed

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,8 @@ abstract function foo(): array;
2121
abstract function foo(): Foo\Bar;
2222

2323
abstract function foo(): \Foo\Bar;
24+
25+
array_map(
26+
static fn (array $value): array => array_filter($value),
27+
[]
28+
);

src/Tokenizers/PHP.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,8 @@ protected function tokenize($string)
12161216
*/
12171217

12181218
if ($tokenIsArray === true
1219-
&& $token[0] === T_FUNCTION
1219+
&& ($token[0] === T_FUNCTION
1220+
|| $token[0] === T_FN)
12201221
&& $finalTokens[$lastNotEmptyToken]['code'] !== T_USE
12211222
) {
12221223
for ($x = ($stackPtr + 1); $x < $numTokens; $x++) {

0 commit comments

Comments
 (0)