Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
],
"dependencies": {
"linguist-languages": "^8.0.0",
"php-parser": "^3.2.5"
"php-parser": "^3.4.0"
},
"devDependencies": {
"@babel/preset-env": "^7.27.2",
Expand Down
4 changes: 2 additions & 2 deletions src/printer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ function printClass(path, options, print) {
declaration.push("abstract ");
}

if (node.isReadonly) {
if (node.isReadonly && !isAnonymousClass) {
declaration.push("readonly ");
}

Expand Down Expand Up @@ -2094,7 +2094,7 @@ function printNode(path, options, print) {
() => printAttrs(path, options, print, { inline: true }),
"what"
),
"class",
node.what.isReadonly ? "readonly class" : "class",
node.arguments.length > 0
? [" ", printArgumentsList(path, options, print)]
: "",
Expand Down
1 change: 1 addition & 0 deletions src/util.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const PRECEDENCE = new Map(
"<<=",
">>=",
],
["|>"],
["??"],
["||"],
["&&"],
Expand Down
16 changes: 16 additions & 0 deletions tests/bin/bin.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,3 +331,19 @@ function () {
$this->request->data['comments']['user_id'] = $this->request->data['comments']['user_id'] ?? 'value';
// Instead of repeating variables with long names, the equal coalesce operator is used
$this->request->data['comments']['user_id'] ??= 'value';

$result = "Hello, World!" |> strtoupper(...);
$result = "Hello, World!" |> strtoupper(...) |> trim(...);
$result = "Hello, World!" |> strtoupper(...) |> trim(...) |> htmlspecialchars(...);

return $value |> transform(...);
echo $value |> format(...);

if ($x |> validate(...)) {}

$result = $value |> fn1(...) ?? $fallback;
$result = $value ?? $fallback |> fn1(...);

foo($value |> transform(...), $other);

$veryLongVariableName |> someVeryLongFunctionName(...) |> anotherVeryLongFunctionName(...);
20 changes: 20 additions & 0 deletions tests/class/anonymous.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,23 @@ function () {
return 1;
}
) extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass {};

new readonly class() {};
new readonly class {};
new readonly class($one, $two, $three) {};

$class = new readonly class {};
$class = new readonly class() {};
$class = new readonly class { public int $x = 0; };
$class = new readonly class implements MyInterface {};
$class = new readonly class implements MyInterface, MyOtherInterface {};
$class = new readonly class extends MyParent {};
$class = new readonly class extends MyParent implements MyInterface {};
$class = new readonly class extends MyParent implements MyInterface, MyOtherInterface {};

$class = new readonly class implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyOtherClass {};
$class = new readonly class extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass {};
$class = new readonly class extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass implements MyI, MyII, MyIII {};

$class = new readonly class($one, $two) implements MyInterface {};
$class = new readonly class($one, $two) extends MyParent implements MyInterface {};
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4701,10 +4701,10 @@ path-type@^4.0.0:
resolved "https://registry.yarnpkg.com/path-type/-/path-type-4.0.0.tgz#84ed01c0a7ba380afe09d90a8c180dcd9d03043b"
integrity sha512-gDKb8aZMDeD/tZWs9P6+q0J9Mwkdl6xMV8TjnGP3qJVJ06bdMgkbBlLU8IdfOsIsFz2BW1rNVT3XuNEl8zPAvw==

php-parser@^3.2.5:
version "3.2.5"
resolved "https://registry.yarnpkg.com/php-parser/-/php-parser-3.2.5.tgz#24ff4b4f3e1788967f7737e43c273a5a8e7cd0ac"
integrity sha512-M1ZYlALFFnESbSdmRtTQrBFUHSriHgPhgqtTF/LCbZM4h7swR5PHtUceB2Kzby5CfqcsYwBn7OXTJ0+8Sajwkw==
php-parser@^3.4.0:
version "3.4.0"
resolved "https://registry.yarnpkg.com/php-parser/-/php-parser-3.4.0.tgz#dcd7743bf01caaaa7281e8b253f4cdbbea6e1265"
integrity sha512-JoDPazv8OESrVtcoIuO8HC587zVNJYSYUIl9zYn+JEpwlHSOrxmyMHB+sDS0O1ID5z1aFxPnr+vAUGoSKphlHA==

picocolors@^1.0.0:
version "1.0.0"
Expand Down