Skip to content

Commit 23c63d7

Browse files
authored
[coding-style] Decouple ArrowFunctionToFirstClassCallableRector to allow step-by-step upgrade (#7737)
* [coding-style] Decouple ArrowFunctionToFirstClassCallableRector to allow step-by-step upgrade * decouple ClosureDelegatingCallToFirstClassCallableRector, deprecate FunctionLikeToFirstClassCallableRector as split into 2 rules now
1 parent e1d53b0 commit 23c63d7

File tree

69 files changed

+999
-604
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+999
-604
lines changed

config/set/php81.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
declare(strict_types=1);
44

5+
use Rector\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector;
6+
use Rector\CodingStyle\Rector\Closure\ClosureDelegatingCallToFirstClassCallableRector;
57
use Rector\CodingStyle\Rector\FuncCall\ClosureFromCallableToFirstClassCallableRector;
68
use Rector\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector;
7-
use Rector\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector;
89
use Rector\Config\RectorConfig;
910
use Rector\Php81\Rector\Array_\ArrayToFirstClassCallableRector;
1011
use Rector\Php81\Rector\Class_\MyCLabsClassToEnumRector;
@@ -30,10 +31,13 @@
3031
SpatieEnumMethodCallToEnumConstRector::class,
3132
NullToStrictStringFuncCallArgRector::class,
3233
NullToStrictIntPregSlitFuncCallLimitArgRector::class,
33-
// array of local method call
34+
3435
ArrayToFirstClassCallableRector::class,
36+
3537
// closure/arrow function
36-
FunctionLikeToFirstClassCallableRector::class,
38+
ArrowFunctionDelegatingCallToFirstClassCallableRector::class,
39+
ClosureDelegatingCallToFirstClassCallableRector::class,
40+
3741
ClosureFromCallableToFirstClassCallableRector::class,
3842
FunctionFirstClassCallableRector::class,
3943
RemoveReflectionSetAccessibleCallsRector::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\ArrowFunctionDelegatingCallToFirstClassCallableRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class ArrowFunctionDelegatingCallToFirstClassCallableRectorTest 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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector\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\ArrowFunctionDelegatingCallToFirstClassCallableRector\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/ArrowFunctionDelegatingCallToFirstClassCallableRector/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\ArrowFunctionDelegatingCallToFirstClassCallableRector\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\ArrowFunctionDelegatingCallToFirstClassCallableRector\Fixture;
2626

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

43-
?>
43+
?>

rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/multiple_params.php.inc renamed to rules-tests/CodingStyle/Rector/ArrowFunction/ArrowFunctionDelegatingCallToFirstClassCallableRector/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\ArrowFunctionDelegatingCallToFirstClassCallableRector\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\ArrowFunctionDelegatingCallToFirstClassCallableRector\Fixture;
1818

1919
final class MultipleParams
2020
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector\Fixture;
4+
5+
use Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector\Source\FooBar;
6+
7+
final class SimpleCall
8+
{
9+
public function run()
10+
{
11+
fn ($foo) => FooBar::foo($foo);
12+
}
13+
}
14+
15+
?>
16+
-----
17+
<?php
18+
19+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector\Fixture;
20+
21+
use Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector\Source\FooBar;
22+
23+
final class SimpleCall
24+
{
25+
public function run()
26+
{
27+
FooBar::foo(...);
28+
}
29+
}
30+
31+
?>

rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_assigned_early.php.inc renamed to rules-tests/CodingStyle/Rector/ArrowFunction/ArrowFunctionDelegatingCallToFirstClassCallableRector/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\ArrowFunctionDelegatingCallToFirstClassCallableRector\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,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector\Fixture;
4+
5+
final class SkipDependencyOnArg
6+
{
7+
public function run()
8+
{
9+
fn ($foo) => $foo->foo();
10+
}
11+
}

rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_callable_param_assign_with_signature_multi_params.php.inc renamed to rules-tests/CodingStyle/Rector/ArrowFunction/ArrowFunctionDelegatingCallToFirstClassCallableRector/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\ArrowFunctionDelegatingCallToFirstClassCallableRector\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\ArrowFunctionDelegatingCallToFirstClassCallableRector\Fixture;
4+
5+
use Rector\Tests\CodingStyle\Rector\ArrowFunction\ArrowFunctionDelegatingCallToFirstClassCallableRector\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)