Skip to content

Commit c397163

Browse files
committed
Refactor to ArrowFunction
1 parent 3ee5862 commit c397163

File tree

3 files changed

+13
-27
lines changed

3 files changed

+13
-27
lines changed

src/Rector/AbstractDrupalCoreRector.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@
44

55
namespace DrupalRector\Rector;
66

7-
use Drupal\Core\Component\DeprecationHelper;
7+
use Drupal\Component\Utility\DeprecationHelper;
88
use DrupalRector\Contract\DrupalCoreRectorInterface;
99
use PhpParser\Node;
10+
use PhpParser\Node\Expr\ArrowFunction;
1011
use Rector\Core\Rector\AbstractRector;
11-
use Rector\Php72\NodeFactory\AnonymousFunctionFactory;
1212

1313
abstract class AbstractDrupalCoreRector extends AbstractRector implements DrupalCoreRectorInterface
1414
{
15-
private AnonymousFunctionFactory $anonymousFunctionFactory;
16-
17-
public function __construct(AnonymousFunctionFactory $anonymousFunctionFactory) {
18-
$this->anonymousFunctionFactory = $anonymousFunctionFactory;
19-
}
20-
2115
public function refactor(Node $node)
2216
{
2317
if (version_compare(\Drupal::VERSION, $this->getVersion(), '<')) {
@@ -49,8 +43,8 @@ private function createBcCallOnCallLike(Node\Expr\CallLike $node, Node\Expr\Call
4943
return $this->nodeFactory->createStaticCall(DeprecationHelper::class, 'backwardsCompatibleCall', [
5044
$this->nodeFactory->createClassConstFetch(\Drupal::class, 'VERSION'),
5145
$this->getVersion(),
52-
$this->anonymousFunctionFactory->create([], [new Node\Stmt\Return_($clonedNode)], null),
53-
$this->anonymousFunctionFactory->create([], [new Node\Stmt\Return_($result)], null),
46+
new ArrowFunction(['expr' => $clonedNode]),
47+
new ArrowFunction(['expr' => $result]),
5448
]);
5549
}
5650

File renamed without changes.
Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,23 @@
11
<?php
22

3-
function simple_example() {
3+
function simple_example()
4+
{
45
$password = user_password();
56
$other_password = user_password(8);
67
$password_length = 12;
78
$last_password = user_password($password_length);
89
}
10+
911
?>
1012
-----
1113
<?php
1214

13-
function simple_example() {
14-
$password = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', function () {
15-
return user_password();
16-
}, function () {
17-
return \Drupal::service('password_generator')->generate();
18-
});
19-
$other_password = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', function () {
20-
return user_password(8);
21-
}, function () {
22-
return \Drupal::service('password_generator')->generate(8);
23-
});
15+
function simple_example()
16+
{
17+
$password = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => user_password(), fn() => \Drupal::service('password_generator')->generate());
18+
$other_password = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => user_password(8), fn() => \Drupal::service('password_generator')->generate(8));
2419
$password_length = 12;
25-
$last_password = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', function () use ($password_length) {
26-
return user_password($password_length);
27-
}, function () use ($password_length) {
28-
return \Drupal::service('password_generator')->generate($password_length);
29-
});
20+
$last_password = \Drupal\Component\Utility\DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '9.1.0', fn() => user_password($password_length), fn() => \Drupal::service('password_generator')->generate($password_length));
3021
}
22+
3123
?>

0 commit comments

Comments
 (0)