Skip to content

Commit

Permalink
Fixed bug #2773 : PSR2.Methods.FunctionCallSignature false positive w…
Browse files Browse the repository at this point in the history
…hen arrow function has array return type
  • Loading branch information
gsherwood committed Jan 6, 2020
1 parent 692237d commit 30b5457
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
- Fixed bug #2763 : PSR12 standard reports errors for multi-line FOR definitions
- Fixed bug #2768 : Generic.Files.LineLength false positive for non-breakable strings at exactly the soft limit
-- Thanks to Alex Miles for the patch
- Fixed bug #2773 : PSR2.Methods.FunctionCallSignature false positive when arrow function has array return type
- Fixed bug #2791 : PSR12.Functions.NullableTypeDeclaration false positive when ternary operator used with instanceof
-- Thanks to Juliette Reinders Folmer for the patch
</notes>
Expand Down
1 change: 1 addition & 0 deletions src/Tokenizers/PHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -1816,6 +1816,7 @@ protected function processAdditional()
$ignore = Util\Tokens::$emptyTokens;
$ignore += [
T_STRING => T_STRING,
T_ARRAY => T_ARRAY,
T_COLON => T_COLON,
T_NS_SEPARATOR => T_NS_SEPARATOR,
T_NULLABLE => T_NULLABLE,
Expand Down
5 changes: 4 additions & 1 deletion tests/Core/File/FindEndOfStatementTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ $a = [
'b' => fn() => return 1,
];

/* testArrowFunction */
/* testStaticArrowFunction */
static fn ($a) => $a;

/* testArrowFunctionReturnValue */
fn(): array => [a($a, $b)];

return 0;
24 changes: 20 additions & 4 deletions tests/Core/File/FindEndOfStatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,21 +189,37 @@ public function testArrowFunctionArrayValue()


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

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

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

}//end testArrowFunction()
}//end testStaticArrowFunction()


/**
* Test arrow function with return value.
*
* @return void
*/
public function testArrowFunctionReturnValue()
{
$start = (self::$phpcsFile->findNext(T_COMMENT, 0, null, false, '/* testArrowFunctionReturnValue */') + 2);
$found = self::$phpcsFile->findEndOfStatement($start);

$tokens = self::$phpcsFile->getTokens();
$this->assertSame($tokens[($start + 18)], $tokens[$found]);

}//end testArrowFunctionReturnValue()


}//end class

0 comments on commit 30b5457

Please sign in to comment.