Skip to content

Commit 09ab43b

Browse files
[PHP 8.5] Add NestedToPipeOperatorRector (#7577)
* pipe * rebase * feedback * remove from config, make optional as opinionated new syntax --------- Co-authored-by: MailMug <info@mailmug.net>
1 parent d8e15a8 commit 09ab43b

File tree

9 files changed

+419
-21
lines changed

9 files changed

+419
-21
lines changed

config/set/php85.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,19 @@
3131
use Rector\Renaming\ValueObject\RenameClassAndConstFetch;
3232

3333
return static function (RectorConfig $rectorConfig): void {
34-
$rectorConfig->rules(
35-
[
36-
ArrayFirstLastRector::class,
37-
RemoveFinfoBufferContextArgRector::class,
38-
NullDebugInfoReturnRector::class,
39-
DeprecatedAnnotationToDeprecatedAttributeRector::class,
40-
ColonAfterSwitchCaseRector::class,
41-
ArrayKeyExistsNullToEmptyStringRector::class,
42-
ChrArgModuloRector::class,
43-
SleepToSerializeRector::class,
44-
OrdSingleByteRector::class,
45-
WakeupToUnserializeRector::class,
46-
ShellExecFunctionCallOverBackticksRector::class,
47-
]
48-
);
34+
$rectorConfig->rules([
35+
ArrayFirstLastRector::class,
36+
RemoveFinfoBufferContextArgRector::class,
37+
NullDebugInfoReturnRector::class,
38+
DeprecatedAnnotationToDeprecatedAttributeRector::class,
39+
ColonAfterSwitchCaseRector::class,
40+
ArrayKeyExistsNullToEmptyStringRector::class,
41+
ChrArgModuloRector::class,
42+
SleepToSerializeRector::class,
43+
OrdSingleByteRector::class,
44+
WakeupToUnserializeRector::class,
45+
ShellExecFunctionCallOverBackticksRector::class,
46+
]);
4947

5048
$rectorConfig->ruleWithConfiguration(
5149
RemoveFuncCallArgRector::class,

phpstan.neon

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@ parameters:
222222

223223
- '#Register "Rector\\Php80\\Rector\\NotIdentical\\MbStrContainsRector" service to "php80\.php" config set#'
224224

225+
- '#Register "Rector\\Php85\\Rector\\StmtsAwareInterface\\NestedToPipeOperatorRector" service to "php85\.php" config set#'
226+
225227
# closure detailed
226228
- '#Method Rector\\Config\\RectorConfig\:\:singleton\(\) has parameter \$concrete with no signature specified for Closure#'
227229

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php85\Rector\StmtsAwareInterface\NestedToPipeOperatorRector\Fixture;
4+
5+
$value = "hello world";
6+
$result1 = function3($value);
7+
$result2 = function2($result1);
8+
$result = function1($result2);
9+
?>
10+
-----
11+
<?php
12+
13+
namespace Rector\Tests\Php85\Rector\StmtsAwareInterface\NestedToPipeOperatorRector\Fixture;
14+
15+
$value = "hello world";
16+
$result = $value |> function3(...) |> function2(...) |> function1(...);
17+
?>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php85\Rector\StmtsAwareInterface\NestedToPipeOperatorRector\Fixture;
4+
5+
$result = trim(strtoupper("Hello World"));
6+
?>
7+
-----
8+
<?php
9+
10+
namespace Rector\Tests\Php85\Rector\StmtsAwareInterface\NestedToPipeOperatorRector\Fixture;
11+
12+
$result = strtoupper("Hello World") |> trim(...);
13+
?>
Lines changed: 28 additions & 0 deletions
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\Php85\Rector\StmtsAwareInterface\NestedToPipeOperatorRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class NestedToPipeOperatorRectorTest 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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Php85\Rector\StmtsAwareInterface\NestedToPipeOperatorRector;
7+
8+
return static function (RectorConfig $rectorConfig): void {
9+
$rectorConfig->rule(NestedToPipeOperatorRector::class);
10+
};

0 commit comments

Comments
 (0)