Skip to content

Commit a239644

Browse files
committed
[pipe] add custom printer to newline pipe always next line
1 parent 6da898b commit a239644

3 files changed

Lines changed: 24 additions & 4 deletions

File tree

rules-tests/Php85/Rector/StmtsAwareInterface/NestedToPipeOperatorRector/Fixture/basic.php.inc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ $value = "hello world";
66
$result1 = function3($value);
77
$result2 = function2($result1);
88
$result = function1($result2);
9+
910
?>
1011
-----
1112
<?php
1213

1314
namespace Rector\Tests\Php85\Rector\StmtsAwareInterface\NestedToPipeOperatorRector\Fixture;
1415

1516
$value = "hello world";
16-
$result = $value |> function3(...) |> function2(...) |> function1(...);
17-
?>
17+
$result = $value
18+
|> function3(...)
19+
|> function2(...)
20+
|> function1(...);
21+
22+
?>

rules-tests/Php85/Rector/StmtsAwareInterface/NestedToPipeOperatorRector/Fixture/nested_func.php.inc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
namespace Rector\Tests\Php85\Rector\StmtsAwareInterface\NestedToPipeOperatorRector\Fixture;
44

55
$result = trim(strtoupper("Hello World"));
6+
67
?>
78
-----
89
<?php
910

1011
namespace Rector\Tests\Php85\Rector\StmtsAwareInterface\NestedToPipeOperatorRector\Fixture;
1112

12-
$result = strtoupper("Hello World") |> trim(...);
13-
?>
13+
$result = strtoupper("Hello World")
14+
|> trim(...);
15+
16+
?>

src/PhpParser/Printer/BetterStandardPrinter.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,18 @@ protected function pExpr_Array(Array_ $array): string
332332
return parent::pExpr_Array($array);
333333
}
334334

335+
protected function pExpr_BinaryOp_Pipe(BinaryOp\Pipe $node, int $precedence, int $lhsPrecedence): string
336+
{
337+
return $this->pInfixOp(
338+
BinaryOp\Pipe::class,
339+
$node->left,
340+
$this->nl . ' |> ',
341+
$node->right,
342+
$precedence,
343+
$lhsPrecedence
344+
);
345+
}
346+
335347
/**
336348
* Fixes escaping of regular patterns
337349
*/

0 commit comments

Comments
 (0)