Skip to content

Commit 94a3659

Browse files
arshidkv12samsonasik
authored andcommitted
Downgrade php85 pipe
1 parent fd80f74 commit 94a3659

File tree

11 files changed

+390
-45
lines changed

11 files changed

+390
-45
lines changed

rules-tests/DowngradePhp85/Rector/StmtsAwareInterface/DowngradePipeOperatorRectorTest/DowngradePipeOperatorRectorTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66

77
use Iterator;
88
use PHPUnit\Framework\Attributes\DataProvider;
9+
use PHPUnit\Framework\Attributes\RequiresPhp;
910
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
1011

1112
final class DowngradePipeOperatorRectorTest extends AbstractRectorTestCase
1213
{
1314
#[DataProvider('provideData')]
15+
#[RequiresPhp('>= 8.5')]
1416
public function test(string $filePath): void
1517
{
1618
$this->doTestFile($filePath);
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\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+
-----
16+
<?php
17+
18+
declare(strict_types=1);
19+
20+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
21+
22+
$data = " Hello, World! ";
23+
$result1 = trim($data);
24+
$result2 = strtoupper($result1);
25+
$result3 = (fn($str) => str_replace('WORLD', 'PHP', $str))($result2);
26+
$processed = addslashes($result3);
27+
28+
?>

rules-tests/DowngradePhp85/Rector/StmtsAwareInterface/DowngradePipeOperatorRectorTest/Fixture/fixture.php.inc renamed to rules-tests/DowngradePhp85/Rector/StmtsAwareInterface/DowngradePipeOperatorRectorTest/Fixture/multiple_pipes.php.inc

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +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-
$result1 = function3($value);
23-
$result2 = function2($result1);
24-
$result = function1($result2);
25-
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+
$result1 = function3($value);
23+
$result2 = function2($result1);
24+
$result = function1($result2);
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+
$result1 = trim($value);
20+
$result = strtoupper($result1);
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+
$result1 = (fn($x) => strtoupper($x))("hello");
18+
$result = (fn($y) => $y . '!')($result1);
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+
?>
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+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
6+
7+
// This should be skipped as the right side is not callable
8+
$result = "hello" |> "not_callable";
9+
10+
?>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\DowngradePhp85\Rector\StmtsAwareInterface\DowngradePipeOperatorRector\Fixture;
6+
7+
$result = trim("hello");
8+
9+
?>

0 commit comments

Comments
 (0)