Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8376d26

Browse files
[php 8.5] Split of nested functions calls to pipe operator in a new standalone rule (#7603)
* split fixtures * [php 8.5] Split of nested functions calls to pipe operator in a new standalone rule * implemented * implemented --------- Co-authored-by: Abdul Malik Ikhsan <[email protected]>
1 parent c010b02 commit 8376d26

File tree

13 files changed

+391
-74
lines changed

13 files changed

+391
-74
lines changed

phpstan.neon

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@ parameters:
217217

218218
# optional as changes behavior, should be used explicitly outside PHP upgrade
219219
- '#Register "Rector\\Php73\\Rector\\FuncCall\\JsonThrowOnErrorRector" service to "php73\.php" config set#'
220-
221220
- '#Register "Rector\\Php81\\Rector\\ClassMethod\\NewInInitializerRector" service to "php81\.php" config set#'
222-
223221
- '#Register "Rector\\Php80\\Rector\\NotIdentical\\MbStrContainsRector" service to "php80\.php" config set#'
224-
225222
- '#Register "Rector\\Php85\\Rector\\StmtsAwareInterface\\SequentialAssignmentsToPipeOperatorRector" service to "php85\.php" config set#'
223+
- '#Register "Rector\\Php85\\Rector\\Expression\\NestedFuncCallsToPipeOperatorRector" service to "php85\.php" config set#'
226224

227225
# closure detailed
228226
- '#Method Rector\\Config\\RectorConfig\:\:singleton\(\) has parameter \$concrete with no signature specified for Closure#'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector\Fixture;
4+
5+
final class ArrayFilter
6+
{
7+
public function filter(array $data)
8+
{
9+
return array_filter($data, 'intval');
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector\Fixture;
18+
19+
final class ArrayFilter
20+
{
21+
public function filter(array $data)
22+
{
23+
return array_filter($data, intval(...));
24+
}
25+
}
26+
27+
?>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector\Fixture;
4+
5+
final class ArrayFunctionNamedArgument
6+
{
7+
public function map(array $data)
8+
{
9+
return array_map(callback: 'strtolower', array: $data);
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector\Fixture;
18+
19+
final class ArrayFunctionNamedArgument
20+
{
21+
public function map(array $data)
22+
{
23+
return array_map(callback: strtolower(...), array: $data);
24+
}
25+
}
26+
27+
?>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector\Fixture;
4+
5+
final class ArrayWalk
6+
{
7+
public function walkWithArgument(array $data, mixed $additionalArgument)
8+
{
9+
array_walk($data, 'serialize', $additionalArgument);
10+
11+
return $data;
12+
}
13+
}
14+
15+
?>
16+
-----
17+
<?php
18+
19+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector\Fixture;
20+
21+
final class ArrayWalk
22+
{
23+
public function walkWithArgument(array $data, mixed $additionalArgument)
24+
{
25+
array_walk($data, serialize(...), $additionalArgument);
26+
27+
return $data;
28+
}
29+
}
30+
31+
?>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector\Fixture;
4+
5+
final class NestedArrayCall
6+
{
7+
public function nestedMap(array $data)
8+
{
9+
return array_map('strtolower', array: array_map('trim', $data));
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector\Fixture;
18+
19+
final class NestedArrayCall
20+
{
21+
public function nestedMap(array $data)
22+
{
23+
return array_map(strtolower(...), array: array_map(trim(...), $data));
24+
}
25+
}
26+
27+
?>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\FuncCall\FunctionFirstClassCallableRector\Fixture;
4+
5+
final class SkipAlreadyCallable
6+
{
7+
public function skipFilter(array $data)
8+
{
9+
return array_filter($data, boolval(...));
10+
}
11+
}

rules-tests/CodingStyle/Rector/FuncCall/FunctionFirstClassCallableRector/Fixture/with_function_calls.php.inc

Lines changed: 0 additions & 71 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php85\Rector\Expression\NestedFuncCallsToPipeOperatorRector\Fixture;
4+
5+
final class NestedFunctions
6+
{
7+
public function run()
8+
{
9+
$result = trim(strtolower(htmlspecialchars(' Hello World! ')));
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\Php85\Rector\Expression\NestedFuncCallsToPipeOperatorRector\Fixture;
18+
19+
final class NestedFunctions
20+
{
21+
public function run()
22+
{
23+
$result = ' Hello World! '
24+
|> htmlspecialchars(...)
25+
|> strtolower(...)
26+
|> trim(...);
27+
}
28+
}
29+
30+
?>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php85\Rector\Expression\NestedFuncCallsToPipeOperatorRector\Fixture;
4+
5+
final class ReturnNested
6+
{
7+
public function run()
8+
{
9+
return trim(strtolower(htmlspecialchars(' Hello World! ')));
10+
}
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\Php85\Rector\Expression\NestedFuncCallsToPipeOperatorRector\Fixture;
18+
19+
final class ReturnNested
20+
{
21+
public function run()
22+
{
23+
return ' Hello World! '
24+
|> htmlspecialchars(...)
25+
|> strtolower(...)
26+
|> trim(...);
27+
}
28+
}
29+
30+
?>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php85\Rector\Expression\NestedFuncCallsToPipeOperatorRector\Fixture;
4+
5+
final class SkipSole
6+
{
7+
public function run()
8+
{
9+
$result = trim(' Hello World! ');
10+
}
11+
}

0 commit comments

Comments
 (0)