Skip to content

Commit 17eb5f4

Browse files
committed
[coding-style] Decouple ArrowFunctionToFirstClassCallableRector to allow step-by-step upgrade
1 parent e1d53b0 commit 17eb5f4

File tree

40 files changed

+595
-140
lines changed

40 files changed

+595
-140
lines changed

config/set/php81.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
declare(strict_types=1);
44

5+
use Rector\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector;
56
use Rector\CodingStyle\Rector\FuncCall\ClosureFromCallableToFirstClassCallableRector;
67
use Rector\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector;
78
use Rector\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector;
@@ -32,7 +33,10 @@
3233
NullToStrictIntPregSlitFuncCallLimitArgRector::class,
3334
// array of local method call
3435
ArrayToFirstClassCallableRector::class,
36+
3537
// closure/arrow function
38+
ArrowFunctionToFirstClassCallableRector::class,
39+
3640
FunctionLikeToFirstClassCallableRector::class,
3741
ClosureFromCallableToFirstClassCallableRector::class,
3842
FunctionFirstClassCallableRector::class,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class ArrowFunctionToFirstClassCallableRectorTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Fixture;
4+
5+
final class ArrayMap
6+
{
7+
public function call($items)
8+
{
9+
array_map(fn($x) => strlen($x), $items);
10+
}
11+
12+
public function run(): void
13+
{
14+
$array = [1, 2, 3];
15+
16+
array_map(
17+
fn($item) => var_dump(
18+
$item,
19+
),
20+
$array
21+
);
22+
}
23+
}
24+
25+
?>
26+
-----
27+
<?php
28+
29+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Fixture;
30+
31+
final class ArrayMap
32+
{
33+
public function call($items)
34+
{
35+
array_map(strlen(...), $items);
36+
}
37+
38+
public function run(): void
39+
{
40+
$array = [1, 2, 3];
41+
42+
array_map(
43+
var_dump(
44+
...
45+
),
46+
$array
47+
);
48+
}
49+
}
50+
51+
?>

rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/exists_both_in_method_doc_and_native_method.php.inc renamed to rules-tests/CodingStyle/Rector/ArrowFunction/ArrowFunctionToFirstClassCallableRector/Fixture/exists_both_in_method_doc_and_native_method.php.inc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;
3+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Fixture;
44

55
/**
66
* @method static array test(mixed $value)
@@ -22,7 +22,7 @@ class ExistsBothInMethodDocAndNativeMethod
2222
-----
2323
<?php
2424

25-
namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;
25+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Fixture;
2626

2727
/**
2828
* @method static array test(mixed $value)
@@ -40,4 +40,4 @@ class ExistsBothInMethodDocAndNativeMethod
4040
}
4141
}
4242

43-
?>
43+
?>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Fixture;
4+
5+
use Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Source\FooBar;
6+
7+
fn ($foo) => FooBar::foo($foo);
8+
9+
?>
10+
-----
11+
<?php
12+
13+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Fixture;
14+
15+
use Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Source\FooBar;
16+
17+
FooBar::foo(...);
18+
19+
?>

rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/multiple_params.php.inc renamed to rules-tests/CodingStyle/Rector/ArrowFunction/ArrowFunctionToFirstClassCallableRector/Fixture/multiple_params.php.inc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;
3+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Fixture;
44

55
final class MultipleParams
66
{
@@ -14,7 +14,7 @@ final class MultipleParams
1414
-----
1515
<?php
1616

17-
namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;
17+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Fixture;
1818

1919
final class MultipleParams
2020
{

rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_assigned_early.php.inc renamed to rules-tests/CodingStyle/Rector/ArrowFunction/ArrowFunctionToFirstClassCallableRector/Fixture/skip_assigned_early.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;
3+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Fixture;
44

55
final readonly class SkipAssignedEarly {
66
public function __construct(private string $name, private object $object) {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Fixture;
4+
5+
fn ($foo) => $foo->foo();

rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_callable_param_assign_with_signature_multi_params.php.inc renamed to rules-tests/CodingStyle/Rector/ArrowFunction/ArrowFunctionToFirstClassCallableRector/Fixture/skip_callable_param_assign_with_signature_multi_params.php.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;
3+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Fixture;
44

55
class SkipCallableParamAssignWithSignatureMultiParams
66
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Fixture;
4+
5+
use Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionToFirstClassCallableRector\Source\SomeCacheInterface;
6+
7+
class SkipCallableParamUnion {
8+
public function __construct(
9+
private readonly SomeCacheInterface $cache,
10+
) {
11+
}
12+
13+
public function get(): int {
14+
return $this->cache->get('bar', fn() => time());
15+
}
16+
}

0 commit comments

Comments
 (0)