Skip to content

Commit c2349bd

Browse files
samsonasikarshidkv12actions-user
authored
[DowngradePhp85] Add DowngradePipeOperatorRector (#343)
* downgrade pipe * Downgrade php85 pipe * Downgrade php85 pipe * Downgrade php85 pipe * CI - PHP85 * Downgrade php85 pipe * Downgrade php85 pipe * clean clone usage * use NamedVariableFactory * [ci-review] Rector Rectify * clean check * clean up result variable --------- Co-authored-by: Arshid <[email protected]> Co-authored-by: GitHub Action <[email protected]>
1 parent 6d02b96 commit c2349bd

File tree

14 files changed

+491
-1
lines changed

14 files changed

+491
-1
lines changed

.github/workflows/tests.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
matrix:
1717
php-version: ['8.2', '8.5']
1818
os: [ubuntu-latest]
19-
19+
2020
runs-on: ${{ matrix.os }}
2121
timeout-minutes: 3
2222

config/set/downgrade-php85.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Rector\Config\RectorConfig;
66
use Rector\DowngradePhp85\Rector\Class_\DowngradeFinalPropertyPromotionRector;
77
use Rector\DowngradePhp85\Rector\FuncCall\DowngradeArrayFirstLastRector;
8+
use Rector\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector;
89
use Rector\Renaming\Rector\ClassConstFetch\RenameClassConstFetchRector;
910
use Rector\Renaming\Rector\MethodCall\RenameMethodRector;
1011
use Rector\Renaming\ValueObject\MethodCallRename;
@@ -16,6 +17,7 @@
1617
$rectorConfig->rules([
1718
DowngradeArrayFirstLastRector::class,
1819
DowngradeFinalPropertyPromotionRector::class,
20+
DowngradePipeOperatorRector::class,
1921
]);
2022

2123
// https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_driver_specific_pdo_constants_and_methods
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use PHPUnit\Framework\Attributes\RequiresPhp;
10+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
11+
12+
final class DowngradePipeOperatorRectorTest extends AbstractRectorTestCase
13+
{
14+
#[DataProvider('provideData')]
15+
#[RequiresPhp('>= 8.5')]
16+
public function test(string $filePath): void
17+
{
18+
$this->doTestFile($filePath);
19+
}
20+
21+
public static function provideData(): Iterator
22+
{
23+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
24+
}
25+
26+
public function provideConfigFilePath(): string
27+
{
28+
return __DIR__ . '/config/configured_rule.php';
29+
}
30+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
6+
7+
$data = " Hello, World! ";
8+
$processed = $data
9+
|> trim(...)
10+
|> strtoupper(...)
11+
|> (fn($str) => str_replace('WORLD', 'PHP', $str))
12+
|> addslashes(...);
13+
?>
14+
-----
15+
<?php
16+
17+
declare(strict_types=1);
18+
19+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
20+
21+
$data = " Hello, World! ";
22+
$result = trim($data);
23+
$result = strtoupper($result);
24+
$result = (fn($str) => str_replace('WORLD', 'PHP', $str))($result);
25+
$processed = addslashes($result);
26+
?>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
6+
7+
$value = "hello world";
8+
$result = $value
9+
|> function3(...)
10+
|> function2(...)
11+
|> function1(...);
12+
13+
?>
14+
-----
15+
<?php
16+
17+
declare(strict_types=1);
18+
19+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
20+
21+
$value = "hello world";
22+
$result = function3($value);
23+
$result = function2($result);
24+
$result = function1($result);
25+
26+
?>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
6+
7+
$value = " test ";
8+
$result = $value |> trim(...) |> strtoupper(...);
9+
10+
?>
11+
-----
12+
<?php
13+
14+
declare(strict_types=1);
15+
16+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
17+
18+
$value = " test ";
19+
$result = trim($value);
20+
$result = strtoupper($result);
21+
22+
?>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
6+
7+
$result = "hello" |> (fn($x) => strtoupper($x)) |> (fn($y) => $y . '!');
8+
9+
?>
10+
-----
11+
<?php
12+
13+
declare(strict_types=1);
14+
15+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
16+
17+
$result = (fn($x) => strtoupper($x))("hello");
18+
$result = (fn($y) => $y . '!')($result);
19+
20+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
6+
7+
class StringProcessor {
8+
public function process($str) {
9+
return trim($str);
10+
}
11+
}
12+
13+
$processor = new StringProcessor();
14+
$result = " hello " |> $processor->process(...);
15+
16+
?>
17+
-----
18+
<?php
19+
20+
declare(strict_types=1);
21+
22+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
23+
24+
class StringProcessor {
25+
public function process($str) {
26+
return trim($str);
27+
}
28+
}
29+
30+
$processor = new StringProcessor();
31+
$result = $processor->process(" hello ");
32+
33+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
6+
7+
$func = 'trim';
8+
$result = " hello " |> $func(...);
9+
10+
?>
11+
-----
12+
<?php
13+
14+
declare(strict_types=1);
15+
16+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
17+
18+
$func = 'trim';
19+
$result = $func(" hello ");
20+
21+
?>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
6+
7+
$result = strtoupper("Hello World") |> trim(...);
8+
9+
?>
10+
-----
11+
<?php
12+
13+
declare(strict_types=1);
14+
15+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
16+
17+
$result = trim(strtoupper("Hello World"));
18+
19+
?>

0 commit comments

Comments
 (0)