From 0e4fe7404d19701687c27a2991feae9641fa7359 Mon Sep 17 00:00:00 2001 From: Greg Sherwood Date: Tue, 21 Jan 2020 15:40:06 +1100 Subject: [PATCH] Fixed detection of array return types for arrow functions --- package.xml | 1 + .../Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc | 5 +++++ .../Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc.fixed | 5 +++++ src/Tokenizers/PHP.php | 3 ++- 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/package.xml b/package.xml index df5acb298b..53af623c8e 100644 --- a/package.xml +++ b/package.xml @@ -31,6 +31,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> - The PHP 7.4 numeric separator backfill is no longer run on PHP version 7.4.0 or greater - File::getCondition() now accepts a 3rd argument that allows for the closest matching token to be returned -- By default, it continues to return the first matched token found from the top of the file + - Fixed detection of array return types for arrow functions - Added Generic.PHP.DisallowRequestSuperglobal to ban the use of the $_REQUEST superglobal -- Thanks to Morerice for the contribution - PSR12.ControlStructures.BooleanOperatorPlacement can now be configured to enforce a specific operator position diff --git a/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc b/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc index 614b871ecf..60c2ef96f6 100644 --- a/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc +++ b/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc @@ -21,3 +21,8 @@ abstract function foo(): array; abstract function foo(): Foo\Bar; abstract function foo(): \Foo\Bar; + +array_map( + static fn (array $value): array => array_filter($value), + [] +); diff --git a/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc.fixed b/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc.fixed index 4bea3c5d90..e37971f238 100644 --- a/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc.fixed +++ b/src/Standards/Generic/Tests/Arrays/DisallowLongArraySyntaxUnitTest.1.inc.fixed @@ -21,3 +21,8 @@ abstract function foo(): array; abstract function foo(): Foo\Bar; abstract function foo(): \Foo\Bar; + +array_map( + static fn (array $value): array => array_filter($value), + [] +); diff --git a/src/Tokenizers/PHP.php b/src/Tokenizers/PHP.php index 5ef96a6566..1722498dfd 100644 --- a/src/Tokenizers/PHP.php +++ b/src/Tokenizers/PHP.php @@ -1216,7 +1216,8 @@ protected function tokenize($string) */ if ($tokenIsArray === true - && $token[0] === T_FUNCTION + && ($token[0] === T_FUNCTION + || $token[0] === T_FN) && $finalTokens[$lastNotEmptyToken]['code'] !== T_USE ) { for ($x = ($stackPtr + 1); $x < $numTokens; $x++) {