diff --git a/docs/Newlines.md b/docs/Newlines.md
index 5c969c82..40476c80 100644
--- a/docs/Newlines.md
+++ b/docs/Newlines.md
@@ -46,6 +46,7 @@ They are also allowed before:
- `T_LOGICAL_NOT`
- `T_NULLSAFE_OBJECT_OPERATOR`
- `T_OBJECT_OPERATOR`
+- `T_PIPE`
- Arithmetic operators
- Bitwise operators - `&`, `^`, `|`, `~`, `<<`, `>>`
- Ternary operators
@@ -88,6 +89,7 @@ boolean operators and comparison operators.
enabled)
- `T_NULLSAFE_OBJECT_OPERATOR`
- `T_OBJECT_OPERATOR`
+- `T_PIPE`
- Arithmetic operators
- Bitwise operators - `&`, `^`, `|`, `~`, `<<`, `>>`
- Boolean operators - `!`, `&&`, `||`, `and`, `or`, `xor`
@@ -138,6 +140,7 @@ With **`--operators-last`**, newlines are allowed after, and not before,
- `T_LOGICAL_NOT`
- `T_NULLSAFE_OBJECT_OPERATOR`
- `T_OBJECT_OPERATOR`
+- `T_PIPE`
- Ternary operators
[unit test]: ../tests/unit/TokenIndexTest.php
diff --git a/docs/Rules.md b/docs/Rules.md
index fa336554..9791903f 100644
--- a/docs/Rules.md
+++ b/docs/Rules.md
@@ -144,7 +144,7 @@ Blank lines are also suppressed inside alternative syntax blocks.
### `OperatorSpacing`
-(mandatory, `processTokens()`, priority 102, tokens: `!` | `$` | `%` | `&` | `*` | `+` | `-` | `.` | `/` | `:` | `<` | `=` | `>` | `?` | `@` | `^` | `|` | `~` | `T_LOGICAL_OR` | `T_LOGICAL_XOR` | `T_LOGICAL_AND` | `T_INSTANCEOF` | `T_PLUS_EQUAL` | `T_MINUS_EQUAL` | `T_MUL_EQUAL` | `T_DIV_EQUAL` | `T_CONCAT_EQUAL` | `T_MOD_EQUAL` | `T_AND_EQUAL` | `T_OR_EQUAL` | `T_XOR_EQUAL` | `T_SL_EQUAL` | `T_SR_EQUAL` | `T_COALESCE_EQUAL` | `T_BOOLEAN_OR` | `T_BOOLEAN_AND` | `T_IS_EQUAL` | `T_IS_NOT_EQUAL` | `T_IS_IDENTICAL` | `T_IS_NOT_IDENTICAL` | `T_IS_SMALLER_OR_EQUAL` | `T_IS_GREATER_OR_EQUAL` | `T_SPACESHIP` | `T_SL` | `T_SR` | `T_INC` | `T_DEC` | `T_DOUBLE_ARROW` | `T_COALESCE` | `T_POW` | `T_POW_EQUAL` | `T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG` | `T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG`)
+(mandatory, `processTokens()`, priority 102, tokens: `!` | `$` | `%` | `&` | `*` | `+` | `-` | `.` | `/` | `:` | `<` | `=` | `>` | `?` | `@` | `^` | `|` | `~` | `T_LOGICAL_OR` | `T_LOGICAL_XOR` | `T_LOGICAL_AND` | `T_INSTANCEOF` | `T_PLUS_EQUAL` | `T_MINUS_EQUAL` | `T_MUL_EQUAL` | `T_DIV_EQUAL` | `T_CONCAT_EQUAL` | `T_MOD_EQUAL` | `T_AND_EQUAL` | `T_OR_EQUAL` | `T_XOR_EQUAL` | `T_SL_EQUAL` | `T_SR_EQUAL` | `T_COALESCE_EQUAL` | `T_BOOLEAN_OR` | `T_BOOLEAN_AND` | `T_IS_EQUAL` | `T_IS_NOT_EQUAL` | `T_IS_IDENTICAL` | `T_IS_NOT_IDENTICAL` | `T_IS_SMALLER_OR_EQUAL` | `T_IS_GREATER_OR_EQUAL` | `T_SPACESHIP` | `T_SL` | `T_SR` | `T_INC` | `T_DEC` | `T_DOUBLE_ARROW` | `T_COALESCE` | `T_POW` | `T_POW_EQUAL` | `T_PIPE` | `T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG` | `T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG`)
Operators in `declare` expressions are ignored.
diff --git a/src/AbstractTokenIndex.php b/src/AbstractTokenIndex.php
index 3f9d8fc3..ae12fe61 100644
--- a/src/AbstractTokenIndex.php
+++ b/src/AbstractTokenIndex.php
@@ -25,6 +25,7 @@ abstract class AbstractTokenIndex implements HasTokenIndex, Immutable
\T_LOGICAL_NOT => true,
\T_OBJECT_OPERATOR => true,
\T_NULLSAFE_OBJECT_OPERATOR => true,
+ \T_PIPE => true,
]
+ self::OPERATOR_ARITHMETIC
+ self::OPERATOR_BITWISE
@@ -571,7 +572,7 @@ abstract class AbstractTokenIndex implements HasTokenIndex, Immutable
/**
* Arithmetic operators, assignment operators, bitwise operators, boolean
* operators, comparison operators, ternary operators, T_AT, T_CONCAT,
- * T_DOLLAR, T_DOUBLE_ARROW, T_INC, T_DEC, T_INSTANCEOF
+ * T_DOLLAR, T_DOUBLE_ARROW, T_INC, T_DEC, T_INSTANCEOF, T_PIPE
*
* @var array
*/
@@ -583,6 +584,7 @@ abstract class AbstractTokenIndex implements HasTokenIndex, Immutable
\T_INC => true,
\T_DEC => true,
\T_INSTANCEOF => true,
+ \T_PIPE => true,
]
+ self::OPERATOR_ARITHMETIC
+ self::OPERATOR_ASSIGNMENT
@@ -596,7 +598,7 @@ abstract class AbstractTokenIndex implements HasTokenIndex, Immutable
* Arithmetic operators, assignment operators, bitwise operators (except
* T_OR, T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG), boolean operators,
* comparison operators, T_AT, T_CONCAT, T_DOLLAR, T_DOUBLE_ARROW, T_INC,
- * T_DEC, T_INSTANCEOF
+ * T_DEC, T_INSTANCEOF, T_PIPE
*
* @var array
*/
@@ -608,6 +610,7 @@ abstract class AbstractTokenIndex implements HasTokenIndex, Immutable
\T_INC => true,
\T_DEC => true,
\T_INSTANCEOF => true,
+ \T_PIPE => true,
\T_OR => false,
\T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG => false,
]
diff --git a/src/Contract/HasOperatorPrecedence.php b/src/Contract/HasOperatorPrecedence.php
index 5f93a509..50d16435 100644
--- a/src/Contract/HasOperatorPrecedence.php
+++ b/src/Contract/HasOperatorPrecedence.php
@@ -42,45 +42,46 @@ interface HasOperatorPrecedence
\T_SL => [[0, 8, true, false]],
\T_SR => [[0, 8, true, false]],
\T_CONCAT => [[0, 9, true, false]],
- \T_SMALLER => [[0, 10, false, false]],
- \T_IS_SMALLER_OR_EQUAL => [[0, 10, false, false]],
- \T_GREATER => [[0, 10, false, false]],
- \T_IS_GREATER_OR_EQUAL => [[0, 10, false, false]],
- \T_IS_EQUAL => [[0, 11, false, false]],
- \T_IS_NOT_EQUAL => [[0, 11, false, false]],
- \T_IS_IDENTICAL => [[0, 11, false, false]],
- \T_IS_NOT_IDENTICAL => [[0, 11, false, false]],
- \T_SPACESHIP => [[0, 11, false, false]],
- \T_AND => [[0, 12, true, false]],
- \T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG => [[0, 12, true, false]],
- \T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG => [[0, 12, true, false]],
- \T_XOR => [[0, 13, true, false]],
- \T_OR => [[0, 14, true, false]],
- \T_BOOLEAN_AND => [[0, 15, true, false]],
- \T_BOOLEAN_OR => [[0, 16, true, false]],
- \T_COALESCE => [[0, 17, false, true]],
- \T_QUESTION => [[self::TERNARY, 18, false, false]],
- \T_COLON => [[self::TERNARY, 18, false, false]],
- \T_EQUAL => [[0, 19, false, true]],
- \T_PLUS_EQUAL => [[0, 19, false, true]],
- \T_MINUS_EQUAL => [[0, 19, false, true]],
- \T_MUL_EQUAL => [[0, 19, false, true]],
- \T_POW_EQUAL => [[0, 19, false, true]],
- \T_DIV_EQUAL => [[0, 19, false, true]],
- \T_CONCAT_EQUAL => [[0, 19, false, true]],
- \T_MOD_EQUAL => [[0, 19, false, true]],
- \T_AND_EQUAL => [[0, 19, false, true]],
- \T_OR_EQUAL => [[0, 19, false, true]],
- \T_XOR_EQUAL => [[0, 19, false, true]],
- \T_SL_EQUAL => [[0, 19, false, true]],
- \T_SR_EQUAL => [[0, 19, false, true]],
- \T_COALESCE_EQUAL => [[0, 19, false, true]],
- \T_YIELD_FROM => [[0, 20, false, false]],
- \T_YIELD => [[0, 21, false, false]],
- \T_PRINT => [[0, 22, false, false]],
- \T_LOGICAL_AND => [[0, 23, true, false]],
- \T_LOGICAL_XOR => [[0, 24, true, false]],
- \T_LOGICAL_OR => [[0, 25, true, false]],
+ \T_PIPE => [[0, 10, true, false]],
+ \T_SMALLER => [[0, 11, false, false]],
+ \T_IS_SMALLER_OR_EQUAL => [[0, 11, false, false]],
+ \T_GREATER => [[0, 11, false, false]],
+ \T_IS_GREATER_OR_EQUAL => [[0, 11, false, false]],
+ \T_IS_EQUAL => [[0, 12, false, false]],
+ \T_IS_NOT_EQUAL => [[0, 12, false, false]],
+ \T_IS_IDENTICAL => [[0, 12, false, false]],
+ \T_IS_NOT_IDENTICAL => [[0, 12, false, false]],
+ \T_SPACESHIP => [[0, 12, false, false]],
+ \T_AND => [[0, 13, true, false]],
+ \T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG => [[0, 13, true, false]],
+ \T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG => [[0, 13, true, false]],
+ \T_XOR => [[0, 14, true, false]],
+ \T_OR => [[0, 15, true, false]],
+ \T_BOOLEAN_AND => [[0, 16, true, false]],
+ \T_BOOLEAN_OR => [[0, 17, true, false]],
+ \T_COALESCE => [[0, 18, false, true]],
+ \T_QUESTION => [[self::TERNARY, 19, false, false]],
+ \T_COLON => [[self::TERNARY, 19, false, false]],
+ \T_EQUAL => [[0, 20, false, true]],
+ \T_PLUS_EQUAL => [[0, 20, false, true]],
+ \T_MINUS_EQUAL => [[0, 20, false, true]],
+ \T_MUL_EQUAL => [[0, 20, false, true]],
+ \T_POW_EQUAL => [[0, 20, false, true]],
+ \T_DIV_EQUAL => [[0, 20, false, true]],
+ \T_CONCAT_EQUAL => [[0, 20, false, true]],
+ \T_MOD_EQUAL => [[0, 20, false, true]],
+ \T_AND_EQUAL => [[0, 20, false, true]],
+ \T_OR_EQUAL => [[0, 20, false, true]],
+ \T_XOR_EQUAL => [[0, 20, false, true]],
+ \T_SL_EQUAL => [[0, 20, false, true]],
+ \T_SR_EQUAL => [[0, 20, false, true]],
+ \T_COALESCE_EQUAL => [[0, 20, false, true]],
+ \T_YIELD_FROM => [[0, 21, false, false]],
+ \T_YIELD => [[0, 22, false, false]],
+ \T_PRINT => [[0, 23, false, false]],
+ \T_LOGICAL_AND => [[0, 24, true, false]],
+ \T_LOGICAL_XOR => [[0, 25, true, false]],
+ \T_LOGICAL_OR => [[0, 26, true, false]],
\T_DOUBLE_ARROW => [[0, 99, false, false]],
\T_BREAK => [[0, 99, false, false]],
\T_CASE => [[0, 99, false, false]],
diff --git a/tests/fixtures/Formatter/out/01-default/3rdparty/php-doc/appendices/migration85/new-features/000.php b/tests/fixtures/Formatter/out/01-default/3rdparty/php-doc/appendices/migration85/new-features/000.php
index 73bd6be3..00664406 100644
--- a/tests/fixtures/Formatter/out/01-default/3rdparty/php-doc/appendices/migration85/new-features/000.php
+++ b/tests/fixtures/Formatter/out/01-default/3rdparty/php-doc/appendices/migration85/new-features/000.php
@@ -1,3 +1,3 @@
strlen(...);
+$result = 'Hello World' |> strlen(...);
print $result . PHP_EOL; // Prints "11"
diff --git a/tests/fixtures/Formatter/out/01-default/3rdparty/php-doc/language/operators/functional/000.php b/tests/fixtures/Formatter/out/01-default/3rdparty/php-doc/language/operators/functional/000.php
index 79f37fc4..17a8e4f0 100644
--- a/tests/fixtures/Formatter/out/01-default/3rdparty/php-doc/language/operators/functional/000.php
+++ b/tests/fixtures/Formatter/out/01-default/3rdparty/php-doc/language/operators/functional/000.php
@@ -1,5 +1,5 @@
strlen(...);
+$result = 'Hello World' |> strlen(...);
echo $result, PHP_EOL;
$result = strlen('Hello World');
diff --git a/tests/fixtures/Formatter/out/01-default/3rdparty/php-doc/language/operators/functional/001.php b/tests/fixtures/Formatter/out/01-default/3rdparty/php-doc/language/operators/functional/001.php
index ceeb9a15..e5d0debf 100644
--- a/tests/fixtures/Formatter/out/01-default/3rdparty/php-doc/language/operators/functional/001.php
+++ b/tests/fixtures/Formatter/out/01-default/3rdparty/php-doc/language/operators/functional/001.php
@@ -1,5 +1,9 @@
htmlentities(...)|> str_split(...)|>(fn($x) => array_map(strtoupper(...), $x))|>(fn($x) => array_filter($x, fn($v) => $v != 'O'));
+$result = 'PHP Rocks'
+ |> htmlentities(...)
+ |> str_split(...)
+ |> (fn($x) => array_map(strtoupper(...), $x))
+ |> (fn($x) => array_filter($x, fn($v) => $v != 'O'));
print_r($result);
$temp = 'PHP Rocks';
diff --git a/tests/fixtures/Formatter/out/01-default/3rdparty/php-fig/per/06200-6.2-binary-operators.php b/tests/fixtures/Formatter/out/01-default/3rdparty/php-fig/per/06200-6.2-binary-operators.php
index 4a310979..64bda1c8 100644
--- a/tests/fixtures/Formatter/out/01-default/3rdparty/php-fig/per/06200-6.2-binary-operators.php
+++ b/tests/fixtures/Formatter/out/01-default/3rdparty/php-fig/per/06200-6.2-binary-operators.php
@@ -5,5 +5,5 @@
} elseif ($a > $b) {
$foo = $a + $b * $c;
} else {
- $foo = $a|> log(...)|> round(...);
+ $foo = $a |> log(...) |> round(...);
}
diff --git a/tests/fixtures/Formatter/out/01-default/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php b/tests/fixtures/Formatter/out/01-default/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php
index 39200663..9723d45c 100644
--- a/tests/fixtures/Formatter/out/01-default/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php
+++ b/tests/fixtures/Formatter/out/01-default/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php
@@ -10,4 +10,6 @@
$variable3 = $elvisExpr
?: 'qix';
-$variable4 = ''|> strtoupper(...)|> htmlspecialchars(...);
+$variable4 = ''
+ |> strtoupper(...)
+ |> htmlspecialchars(...);
diff --git a/tests/fixtures/Formatter/out/01-default/3rdparty/php-parser/parser/expr/pipe/000.php b/tests/fixtures/Formatter/out/01-default/3rdparty/php-parser/parser/expr/pipe/000.php
index 9ec26c9f..513fecfe 100644
--- a/tests/fixtures/Formatter/out/01-default/3rdparty/php-parser/parser/expr/pipe/000.php
+++ b/tests/fixtures/Formatter/out/01-default/3rdparty/php-parser/parser/expr/pipe/000.php
@@ -1,7 +1,7 @@
$b|> $c;
-$a . $b|> $c . $d;
-$a|> $b == $c;
-$c == $a|> $b;
-$a|>(fn($x) => $x)|>(fn($y) => $y);
-$a|> fn($x) => $x|> fn($y) => $y;
+$a |> $b |> $c;
+$a . $b |> $c . $d;
+$a |> $b == $c;
+$c == $a |> $b;
+$a |> (fn($x) => $x) |> (fn($y) => $y);
+$a |> fn($x) => $x |> fn($y) => $y;
diff --git a/tests/fixtures/Formatter/out/01-default/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php b/tests/fixtures/Formatter/out/01-default/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php
index af739c26..ebe9abf8 100644
--- a/tests/fixtures/Formatter/out/01-default/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php
+++ b/tests/fixtures/Formatter/out/01-default/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php
@@ -1,10 +1,10 @@
$b|> $c;
-$a . $b|> $c . $d;
-$a|> $b == $c;
-$c == $a|> $b;
-($a == $b)|>($c == $d);
-$a . ($b|> $c) . $d;
-$a|>(fn($x) => $x)|>(fn($y) => $y)|> $b;
-(fn($x) => $x)|> $y;
-fn($x) => $x|> $y;
+$a |> $b |> $c;
+$a . $b |> $c . $d;
+$a |> $b == $c;
+$c == $a |> $b;
+($a == $b) |> ($c == $d);
+$a . ($b |> $c) . $d;
+$a |> (fn($x) => $x) |> (fn($y) => $y) |> $b;
+(fn($x) => $x) |> $y;
+fn($x) => $x |> $y;
diff --git a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-doc/appendices/migration85/new-features/000.php b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-doc/appendices/migration85/new-features/000.php
index 73bd6be3..00664406 100644
--- a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-doc/appendices/migration85/new-features/000.php
+++ b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-doc/appendices/migration85/new-features/000.php
@@ -1,3 +1,3 @@
strlen(...);
+$result = 'Hello World' |> strlen(...);
print $result . PHP_EOL; // Prints "11"
diff --git a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-doc/language/operators/functional/000.php b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-doc/language/operators/functional/000.php
index 79f37fc4..17a8e4f0 100644
--- a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-doc/language/operators/functional/000.php
+++ b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-doc/language/operators/functional/000.php
@@ -1,5 +1,5 @@
strlen(...);
+$result = 'Hello World' |> strlen(...);
echo $result, PHP_EOL;
$result = strlen('Hello World');
diff --git a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-doc/language/operators/functional/001.php b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-doc/language/operators/functional/001.php
index 93f1f0da..1e04c961 100644
--- a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-doc/language/operators/functional/001.php
+++ b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-doc/language/operators/functional/001.php
@@ -1,5 +1,9 @@
htmlentities(...)|> str_split(...)|>(fn($x) => array_map(strtoupper(...), $x))|>(fn($x) => array_filter($x, fn($v) => $v != 'O'));
+$result = 'PHP Rocks'
+ |> htmlentities(...)
+ |> str_split(...)
+ |> (fn($x) => array_map(strtoupper(...), $x))
+ |> (fn($x) => array_filter($x, fn($v) => $v != 'O'));
print_r($result);
$temp = 'PHP Rocks';
diff --git a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-fig/per/06200-6.2-binary-operators.php b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-fig/per/06200-6.2-binary-operators.php
index 4a310979..64bda1c8 100644
--- a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-fig/per/06200-6.2-binary-operators.php
+++ b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-fig/per/06200-6.2-binary-operators.php
@@ -5,5 +5,5 @@
} elseif ($a > $b) {
$foo = $a + $b * $c;
} else {
- $foo = $a|> log(...)|> round(...);
+ $foo = $a |> log(...) |> round(...);
}
diff --git a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php
index 3c5ca466..91c9afa2 100644
--- a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php
+++ b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php
@@ -10,4 +10,6 @@
$variable3 = $elvisExpr
?: 'qix';
-$variable4 = ''|> strtoupper(...)|> htmlspecialchars(...);
+$variable4 = ''
+ |> strtoupper(...)
+ |> htmlspecialchars(...);
diff --git a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-parser/parser/expr/pipe/000.php b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-parser/parser/expr/pipe/000.php
index 9ec26c9f..513fecfe 100644
--- a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-parser/parser/expr/pipe/000.php
+++ b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-parser/parser/expr/pipe/000.php
@@ -1,7 +1,7 @@
$b|> $c;
-$a . $b|> $c . $d;
-$a|> $b == $c;
-$c == $a|> $b;
-$a|>(fn($x) => $x)|>(fn($y) => $y);
-$a|> fn($x) => $x|> fn($y) => $y;
+$a |> $b |> $c;
+$a . $b |> $c . $d;
+$a |> $b == $c;
+$c == $a |> $b;
+$a |> (fn($x) => $x) |> (fn($y) => $y);
+$a |> fn($x) => $x |> fn($y) => $y;
diff --git a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php
index af739c26..ebe9abf8 100644
--- a/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php
+++ b/tests/fixtures/Formatter/out/02-aligned/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php
@@ -1,10 +1,10 @@
$b|> $c;
-$a . $b|> $c . $d;
-$a|> $b == $c;
-$c == $a|> $b;
-($a == $b)|>($c == $d);
-$a . ($b|> $c) . $d;
-$a|>(fn($x) => $x)|>(fn($y) => $y)|> $b;
-(fn($x) => $x)|> $y;
-fn($x) => $x|> $y;
+$a |> $b |> $c;
+$a . $b |> $c . $d;
+$a |> $b == $c;
+$c == $a |> $b;
+($a == $b) |> ($c == $d);
+$a . ($b |> $c) . $d;
+$a |> (fn($x) => $x) |> (fn($y) => $y) |> $b;
+(fn($x) => $x) |> $y;
+fn($x) => $x |> $y;
diff --git a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-doc/appendices/migration85/new-features/000.php b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-doc/appendices/migration85/new-features/000.php
index 73bd6be3..00664406 100644
--- a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-doc/appendices/migration85/new-features/000.php
+++ b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-doc/appendices/migration85/new-features/000.php
@@ -1,3 +1,3 @@
strlen(...);
+$result = 'Hello World' |> strlen(...);
print $result . PHP_EOL; // Prints "11"
diff --git a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-doc/language/operators/functional/000.php b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-doc/language/operators/functional/000.php
index 79f37fc4..17a8e4f0 100644
--- a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-doc/language/operators/functional/000.php
+++ b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-doc/language/operators/functional/000.php
@@ -1,5 +1,5 @@
strlen(...);
+$result = 'Hello World' |> strlen(...);
echo $result, PHP_EOL;
$result = strlen('Hello World');
diff --git a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-doc/language/operators/functional/001.php b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-doc/language/operators/functional/001.php
index ceeb9a15..834b1c50 100644
--- a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-doc/language/operators/functional/001.php
+++ b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-doc/language/operators/functional/001.php
@@ -1,5 +1,9 @@
htmlentities(...)|> str_split(...)|>(fn($x) => array_map(strtoupper(...), $x))|>(fn($x) => array_filter($x, fn($v) => $v != 'O'));
+$result = 'PHP Rocks'
+ |> htmlentities(...)
+ |> str_split(...)
+ |> (fn($x) => array_map(strtoupper(...), $x))
+ |> (fn($x) => array_filter($x, fn($v) => $v != 'O'));
print_r($result);
$temp = 'PHP Rocks';
diff --git a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-fig/per/06200-6.2-binary-operators.php b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-fig/per/06200-6.2-binary-operators.php
index af4d06e9..7fa5a965 100644
--- a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-fig/per/06200-6.2-binary-operators.php
+++ b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-fig/per/06200-6.2-binary-operators.php
@@ -5,5 +5,5 @@
} elseif ($a > $b) {
$foo = $a + $b * $c;
} else {
- $foo = $a|> log(...)|> round(...);
+ $foo = $a |> log(...) |> round(...);
}
diff --git a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php
index f7f9649f..545df43c 100644
--- a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php
+++ b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php
@@ -10,4 +10,6 @@
$variable3 = $elvisExpr
?: 'qix';
-$variable4 = ''|> strtoupper(...)|> htmlspecialchars(...);
+$variable4 = ''
+ |> strtoupper(...)
+ |> htmlspecialchars(...);
diff --git a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-parser/parser/expr/pipe/000.php b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-parser/parser/expr/pipe/000.php
index 9ec26c9f..513fecfe 100644
--- a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-parser/parser/expr/pipe/000.php
+++ b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-parser/parser/expr/pipe/000.php
@@ -1,7 +1,7 @@
$b|> $c;
-$a . $b|> $c . $d;
-$a|> $b == $c;
-$c == $a|> $b;
-$a|>(fn($x) => $x)|>(fn($y) => $y);
-$a|> fn($x) => $x|> fn($y) => $y;
+$a |> $b |> $c;
+$a . $b |> $c . $d;
+$a |> $b == $c;
+$c == $a |> $b;
+$a |> (fn($x) => $x) |> (fn($y) => $y);
+$a |> fn($x) => $x |> fn($y) => $y;
diff --git a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php
index af739c26..ebe9abf8 100644
--- a/tests/fixtures/Formatter/out/03-tab/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php
+++ b/tests/fixtures/Formatter/out/03-tab/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php
@@ -1,10 +1,10 @@
$b|> $c;
-$a . $b|> $c . $d;
-$a|> $b == $c;
-$c == $a|> $b;
-($a == $b)|>($c == $d);
-$a . ($b|> $c) . $d;
-$a|>(fn($x) => $x)|>(fn($y) => $y)|> $b;
-(fn($x) => $x)|> $y;
-fn($x) => $x|> $y;
+$a |> $b |> $c;
+$a . $b |> $c . $d;
+$a |> $b == $c;
+$c == $a |> $b;
+($a == $b) |> ($c == $d);
+$a . ($b |> $c) . $d;
+$a |> (fn($x) => $x) |> (fn($y) => $y) |> $b;
+(fn($x) => $x) |> $y;
+fn($x) => $x |> $y;
diff --git a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-doc/appendices/migration85/new-features/000.php b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-doc/appendices/migration85/new-features/000.php
index 73bd6be3..00664406 100644
--- a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-doc/appendices/migration85/new-features/000.php
+++ b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-doc/appendices/migration85/new-features/000.php
@@ -1,3 +1,3 @@
strlen(...);
+$result = 'Hello World' |> strlen(...);
print $result . PHP_EOL; // Prints "11"
diff --git a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-doc/language/operators/functional/000.php b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-doc/language/operators/functional/000.php
index 79f37fc4..17a8e4f0 100644
--- a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-doc/language/operators/functional/000.php
+++ b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-doc/language/operators/functional/000.php
@@ -1,5 +1,5 @@
strlen(...);
+$result = 'Hello World' |> strlen(...);
echo $result, PHP_EOL;
$result = strlen('Hello World');
diff --git a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-doc/language/operators/functional/001.php b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-doc/language/operators/functional/001.php
index ceeb9a15..e5d0debf 100644
--- a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-doc/language/operators/functional/001.php
+++ b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-doc/language/operators/functional/001.php
@@ -1,5 +1,9 @@
htmlentities(...)|> str_split(...)|>(fn($x) => array_map(strtoupper(...), $x))|>(fn($x) => array_filter($x, fn($v) => $v != 'O'));
+$result = 'PHP Rocks'
+ |> htmlentities(...)
+ |> str_split(...)
+ |> (fn($x) => array_map(strtoupper(...), $x))
+ |> (fn($x) => array_filter($x, fn($v) => $v != 'O'));
print_r($result);
$temp = 'PHP Rocks';
diff --git a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-fig/per/06200-6.2-binary-operators.php b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-fig/per/06200-6.2-binary-operators.php
index 4a310979..64bda1c8 100644
--- a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-fig/per/06200-6.2-binary-operators.php
+++ b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-fig/per/06200-6.2-binary-operators.php
@@ -5,5 +5,5 @@
} elseif ($a > $b) {
$foo = $a + $b * $c;
} else {
- $foo = $a|> log(...)|> round(...);
+ $foo = $a |> log(...) |> round(...);
}
diff --git a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php
index 39200663..9723d45c 100644
--- a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php
+++ b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-fig/per/06400-6.4-operator-s-placement.php
@@ -10,4 +10,6 @@
$variable3 = $elvisExpr
?: 'qix';
-$variable4 = ''|> strtoupper(...)|> htmlspecialchars(...);
+$variable4 = ''
+ |> strtoupper(...)
+ |> htmlspecialchars(...);
diff --git a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-parser/parser/expr/pipe/000.php b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-parser/parser/expr/pipe/000.php
index 9ec26c9f..513fecfe 100644
--- a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-parser/parser/expr/pipe/000.php
+++ b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-parser/parser/expr/pipe/000.php
@@ -1,7 +1,7 @@
$b|> $c;
-$a . $b|> $c . $d;
-$a|> $b == $c;
-$c == $a|> $b;
-$a|>(fn($x) => $x)|>(fn($y) => $y);
-$a|> fn($x) => $x|> fn($y) => $y;
+$a |> $b |> $c;
+$a . $b |> $c . $d;
+$a |> $b == $c;
+$c == $a |> $b;
+$a |> (fn($x) => $x) |> (fn($y) => $y);
+$a |> fn($x) => $x |> fn($y) => $y;
diff --git a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php
index af739c26..ebe9abf8 100644
--- a/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php
+++ b/tests/fixtures/Formatter/out/04-psr12/3rdparty/php-parser/prettyPrinter/expr/pipe/000.php
@@ -1,10 +1,10 @@
$b|> $c;
-$a . $b|> $c . $d;
-$a|> $b == $c;
-$c == $a|> $b;
-($a == $b)|>($c == $d);
-$a . ($b|> $c) . $d;
-$a|>(fn($x) => $x)|>(fn($y) => $y)|> $b;
-(fn($x) => $x)|> $y;
-fn($x) => $x|> $y;
+$a |> $b |> $c;
+$a . $b |> $c . $d;
+$a |> $b == $c;
+$c == $a |> $b;
+($a == $b) |> ($c == $d);
+$a . ($b |> $c) . $d;
+$a |> (fn($x) => $x) |> (fn($y) => $y) |> $b;
+(fn($x) => $x) |> $y;
+fn($x) => $x |> $y;
diff --git a/tests/unit/Contract/HasOperatorPrecedenceTest.php b/tests/unit/Contract/HasOperatorPrecedenceTest.php
index 97629a8c..e2e99312 100644
--- a/tests/unit/Contract/HasOperatorPrecedenceTest.php
+++ b/tests/unit/Contract/HasOperatorPrecedenceTest.php
@@ -40,38 +40,40 @@ final class HasOperatorPrecedenceTest extends TestCase implements HasOperatorPre
[8, [\T_SL, \T_SR], self::LEFT_ASSOCIATIVE],
// .
[9, [\T_CONCAT], self::LEFT_ASSOCIATIVE],
+ // |>
+ [10, [\T_PIPE], self::LEFT_ASSOCIATIVE],
// <, <=, >, >=
- [10, [\T_SMALLER, \T_IS_SMALLER_OR_EQUAL, \T_GREATER, \T_IS_GREATER_OR_EQUAL]],
+ [11, [\T_SMALLER, \T_IS_SMALLER_OR_EQUAL, \T_GREATER, \T_IS_GREATER_OR_EQUAL]],
// ==, !=, ===, !==, <>, <=>
- [11, [\T_IS_EQUAL, \T_IS_NOT_EQUAL, \T_IS_IDENTICAL, \T_IS_NOT_IDENTICAL, \T_SPACESHIP]],
+ [12, [\T_IS_EQUAL, \T_IS_NOT_EQUAL, \T_IS_IDENTICAL, \T_IS_NOT_IDENTICAL, \T_SPACESHIP]],
// &
- [12, [\T_AND, \T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, \T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG], self::LEFT_ASSOCIATIVE],
+ [13, [\T_AND, \T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG, \T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG], self::LEFT_ASSOCIATIVE],
// ^
- [13, [\T_XOR], self::LEFT_ASSOCIATIVE],
+ [14, [\T_XOR], self::LEFT_ASSOCIATIVE],
// |
- [14, [\T_OR], self::LEFT_ASSOCIATIVE],
+ [15, [\T_OR], self::LEFT_ASSOCIATIVE],
// &&
- [15, [\T_BOOLEAN_AND], self::LEFT_ASSOCIATIVE],
+ [16, [\T_BOOLEAN_AND], self::LEFT_ASSOCIATIVE],
// ||
- [16, [\T_BOOLEAN_OR], self::LEFT_ASSOCIATIVE],
+ [17, [\T_BOOLEAN_OR], self::LEFT_ASSOCIATIVE],
// ??
- [17, [\T_COALESCE], self::RIGHT_ASSOCIATIVE],
+ [18, [\T_COALESCE], self::RIGHT_ASSOCIATIVE],
// ?, :
- [18, [\T_QUESTION, \T_COLON], self::TERNARY],
+ [19, [\T_QUESTION, \T_COLON], self::TERNARY],
// =, +=, -=, *=, **=, /=, .=, %=, &=, |=, ^=, <<=, >>=, ??=
- [19, [\T_EQUAL, \T_PLUS_EQUAL, \T_MINUS_EQUAL, \T_MUL_EQUAL, \T_POW_EQUAL, \T_DIV_EQUAL, \T_CONCAT_EQUAL, \T_MOD_EQUAL, \T_AND_EQUAL, \T_OR_EQUAL, \T_XOR_EQUAL, \T_SL_EQUAL, \T_SR_EQUAL, \T_COALESCE_EQUAL], self::RIGHT_ASSOCIATIVE],
+ [20, [\T_EQUAL, \T_PLUS_EQUAL, \T_MINUS_EQUAL, \T_MUL_EQUAL, \T_POW_EQUAL, \T_DIV_EQUAL, \T_CONCAT_EQUAL, \T_MOD_EQUAL, \T_AND_EQUAL, \T_OR_EQUAL, \T_XOR_EQUAL, \T_SL_EQUAL, \T_SR_EQUAL, \T_COALESCE_EQUAL], self::RIGHT_ASSOCIATIVE],
// yield from
- [20, [\T_YIELD_FROM]],
+ [21, [\T_YIELD_FROM]],
// yield
- [21, [\T_YIELD]],
+ [22, [\T_YIELD]],
// print
- [22, [\T_PRINT]],
+ [23, [\T_PRINT]],
// and
- [23, [\T_LOGICAL_AND], self::LEFT_ASSOCIATIVE],
+ [24, [\T_LOGICAL_AND], self::LEFT_ASSOCIATIVE],
// xor
- [24, [\T_LOGICAL_XOR], self::LEFT_ASSOCIATIVE],
+ [25, [\T_LOGICAL_XOR], self::LEFT_ASSOCIATIVE],
// or
- [25, [\T_LOGICAL_OR], self::LEFT_ASSOCIATIVE],
+ [26, [\T_LOGICAL_OR], self::LEFT_ASSOCIATIVE],
];
public function testOperatorPrecedence(): void
@@ -132,6 +134,7 @@ public function testOperatorPrecedence(): void
\T_DEC => true,
\T_INSTANCEOF => true,
\T_NEW => true,
+ \T_PIPE => true,
]
+ self::OPERATOR_ARITHMETIC
+ self::OPERATOR_ASSIGNMENT
diff --git a/tests/unit/Rule/PreserveNewlinesTest.php b/tests/unit/Rule/PreserveNewlinesTest.php
index 59818b76..04b745e1 100644
--- a/tests/unit/Rule/PreserveNewlinesTest.php
+++ b/tests/unit/Rule/PreserveNewlinesTest.php
@@ -82,6 +82,27 @@ private static function getFoo()
$formatter,
];
+ if (\PHP_VERSION_ID >= 80500) {
+ yield 'newlines before pipe operators' => [
+ <<<'PHP'
+ first(...)
+ |> (fn($item) => second($item))
+ |> third(...);
+
+PHP,
+ <<<'PHP'
+first(...)
+|>(fn($item)=>second($item))
+|>third(...);
+PHP,
+ $formatter,
+ ];
+ }
+
if (\PHP_VERSION_ID < 80000) {
return;
}
diff --git a/tests/unit/Rule/Preset/Internal/WordPressTokenIndexTest.php b/tests/unit/Rule/Preset/Internal/WordPressTokenIndexTest.php
index 144684aa..22274a5e 100644
--- a/tests/unit/Rule/Preset/Internal/WordPressTokenIndexTest.php
+++ b/tests/unit/Rule/Preset/Internal/WordPressTokenIndexTest.php
@@ -46,6 +46,7 @@ final class WordPressTokenIndexTest extends TokenIndexTest
\T_NULLSAFE_OBJECT_OPERATOR,
\T_OBJECT_OPERATOR,
\T_OR,
+ \T_PIPE,
\T_PLUS,
\T_POW,
\T_QUESTION,
diff --git a/tests/unit/TokenIndexTest.php b/tests/unit/TokenIndexTest.php
index fa5a12c2..44fe9029 100644
--- a/tests/unit/TokenIndexTest.php
+++ b/tests/unit/TokenIndexTest.php
@@ -32,6 +32,7 @@ class TokenIndexTest extends TestCase
\T_LOGICAL_NOT,
\T_NULLSAFE_OBJECT_OPERATOR,
\T_OBJECT_OPERATOR,
+ \T_PIPE,
\T_QUESTION,
];