Skip to content

Commit 30b5457

Browse files
committed
Fixed bug #2773 : PSR2.Methods.FunctionCallSignature false positive when arrow function has array return type
1 parent 692237d commit 30b5457

File tree

4 files changed

+26
-5
lines changed

4 files changed

+26
-5
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
5454
- Fixed bug #2763 : PSR12 standard reports errors for multi-line FOR definitions
5555
- Fixed bug #2768 : Generic.Files.LineLength false positive for non-breakable strings at exactly the soft limit
5656
-- Thanks to Alex Miles for the patch
57+
- Fixed bug #2773 : PSR2.Methods.FunctionCallSignature false positive when arrow function has array return type
5758
- Fixed bug #2791 : PSR12.Functions.NullableTypeDeclaration false positive when ternary operator used with instanceof
5859
-- Thanks to Juliette Reinders Folmer for the patch
5960
</notes>

src/Tokenizers/PHP.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,6 +1816,7 @@ protected function processAdditional()
18161816
$ignore = Util\Tokens::$emptyTokens;
18171817
$ignore += [
18181818
T_STRING => T_STRING,
1819+
T_ARRAY => T_ARRAY,
18191820
T_COLON => T_COLON,
18201821
T_NS_SEPARATOR => T_NS_SEPARATOR,
18211822
T_NULLABLE => T_NULLABLE,

tests/Core/File/FindEndOfStatementTest.inc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ $a = [
3636
'b' => fn() => return 1,
3737
];
3838

39-
/* testArrowFunction */
39+
/* testStaticArrowFunction */
4040
static fn ($a) => $a;
4141

42+
/* testArrowFunctionReturnValue */
43+
fn(): array => [a($a, $b)];
44+
4245
return 0;

tests/Core/File/FindEndOfStatementTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,37 @@ public function testArrowFunctionArrayValue()
189189

190190

191191
/**
192-
* Test end of statement for fn closure.
192+
* Test static arrow function.
193193
*
194194
* @return void
195195
*/
196-
public function testArrowFunction()
196+
public function testStaticArrowFunction()
197197
{
198-
$static = (self::$phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testArrowFunction */') + 2);
198+
$static = (self::$phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testStaticArrowFunction */') + 2);
199199
$fn = self::$phpcsFile->findNext(T_FN, ($static + 1));
200200

201201
$endOfStatementStatic = self::$phpcsFile->findEndOfStatement($static);
202202
$endOfStatementFn = self::$phpcsFile->findEndOfStatement($fn);
203203

204204
$this->assertSame($endOfStatementFn, $endOfStatementStatic);
205205

206-
}//end testArrowFunction()
206+
}//end testStaticArrowFunction()
207+
208+
209+
/**
210+
* Test arrow function with return value.
211+
*
212+
* @return void
213+
*/
214+
public function testArrowFunctionReturnValue()
215+
{
216+
$start = (self::$phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testArrowFunctionReturnValue */') + 2);
217+
$found = self::$phpcsFile->findEndOfStatement($start);
218+
219+
$tokens = self::$phpcsFile->getTokens();
220+
$this->assertSame($tokens[($start + 18)], $tokens[$found]);
221+
222+
}//end testArrowFunctionReturnValue()
207223

208224

209225
}//end class

0 commit comments

Comments
 (0)