Merge pull request #2896 from rectorphp/static-reatin

keep array function static
This commit is contained in:
Tomas Votruba 2020-02-21 00:41:09 +01:00 committed by GitHub
commit d4d0285a94
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -17,6 +17,7 @@ use Rector\Core\ValueObject\PhpVersionFeature;
/**
* @see https://wiki.php.net/rfc/arrow_functions_v2
*
* @see \Rector\Php74\Tests\Rector\Closure\ClosureToArrowFunctionRector\ClosureToArrowFunctionRectorTest
*/
final class ClosureToArrowFunctionRector extends AbstractRector
@ -92,6 +93,10 @@ PHP
$arrowFunction->expr = $return->expr;
if ($node->static === true) {
$arrowFunction->static = true;
}
return $arrowFunction;
}

View File

@ -0,0 +1,29 @@
<?php
namespace Rector\Php74\Tests\Rector\Closure\ClosureToArrowFunctionRector\Fixture;
class RetainStatic
{
public function run()
{
$bars = array_map(static function (int $value): int {
return $value * 2;
}, [1, 2, 3]);
}
}
?>
-----
<?php
namespace Rector\Php74\Tests\Rector\Closure\ClosureToArrowFunctionRector\Fixture;
class RetainStatic
{
public function run()
{
$bars = array_map(static fn(int $value): int => $value * 2, [1, 2, 3]);
}
}
?>