From 1a91c8d31cac87aa542a5439c4126f6d16370be0 Mon Sep 17 00:00:00 2001 From: Christian Zosel Date: Tue, 8 Jul 2025 11:53:50 +0200 Subject: [PATCH 01/17] feat!: bump default formatting version to 8.3 BREAKING CHANGE: If you didn't set the `phpVersion` option explicitly, the formatting will assume PHP 8.3 now (instead of 7.0). --- src/options.mjs | 2 +- .../assign/__snapshots__/jsfmt.spec.mjs.snap | 8 +- .../__snapshots__/jsfmt.spec.mjs.snap | 20 +-- tests/bin/__snapshots__/jsfmt.spec.mjs.snap | 14 +- .../__snapshots__/jsfmt.spec.mjs.snap | 114 +++++++------- tests/call/__snapshots__/jsfmt.spec.mjs.snap | 114 +++++++------- tests/case/__snapshots__/jsfmt.spec.mjs.snap | 8 +- tests/class/__snapshots__/jsfmt.spec.mjs.snap | 56 +++---- .../__snapshots__/jsfmt.spec.mjs.snap | 18 +-- tests/clone/__snapshots__/jsfmt.spec.mjs.snap | 4 +- .../closure/__snapshots__/jsfmt.spec.mjs.snap | 26 +-- .../__snapshots__/jsfmt.spec.mjs.snap | 80 +++++----- tests/echo/__snapshots__/jsfmt.spec.mjs.snap | 72 ++++----- .../__snapshots__/jsfmt.spec.mjs.snap | 5 +- tests/encapsed/jsfmt.spec.mjs | 2 +- .../errors/__snapshots__/jsfmt.spec.mjs.snap | 4 +- tests/eval/__snapshots__/jsfmt.spec.mjs.snap | 20 +-- tests/exit/__snapshots__/jsfmt.spec.mjs.snap | 20 +-- .../__snapshots__/jsfmt.spec.mjs.snap | 18 +-- .../inline/__snapshots__/jsfmt.spec.mjs.snap | 22 +-- tests/isset/__snapshots__/jsfmt.spec.mjs.snap | 8 +- .../__snapshots__/jsfmt.spec.mjs.snap | 4 +- tests/list/__snapshots__/jsfmt.spec.mjs.snap | 148 +++++++++--------- .../__snapshots__/jsfmt.spec.mjs.snap | 42 ++--- tests/new/__snapshots__/jsfmt.spec.mjs.snap | 84 +++++----- .../nowdoc/__snapshots__/jsfmt.spec.mjs.snap | 4 +- tests/nowdoc/jsfmt.spec.mjs | 2 +- .../__snapshots__/jsfmt.spec.mjs.snap | 4 +- .../__snapshots__/jsfmt.spec.mjs.snap | 22 +-- .../parens/__snapshots__/jsfmt.spec.mjs.snap | 8 +- .../__snapshots__/jsfmt.spec.mjs.snap | 36 ++--- tests/print/__snapshots__/jsfmt.spec.mjs.snap | 12 +- .../__snapshots__/jsfmt.spec.mjs.snap | 10 +- .../__snapshots__/jsfmt.spec.mjs.snap | 4 +- tests/retif/__snapshots__/jsfmt.spec.mjs.snap | 14 +- .../return/__snapshots__/jsfmt.spec.mjs.snap | 16 +- .../silent/__snapshots__/jsfmt.spec.mjs.snap | 4 +- tests/single-quote-api/jsfmt.spec.mjs | 2 +- .../string/__snapshots__/jsfmt.spec.mjs.snap | 4 +- tests/sys/__snapshots__/jsfmt.spec.mjs.snap | 10 +- .../__snapshots__/jsfmt.spec.mjs.snap | 14 +- tests/trailing_commas/jsfmt.spec.mjs | 3 +- tests/unset/__snapshots__/jsfmt.spec.mjs.snap | 8 +- tests/use/__snapshots__/jsfmt.spec.mjs.snap | 6 +- .../__snapshots__/jsfmt.spec.mjs.snap | 4 +- 45 files changed, 562 insertions(+), 538 deletions(-) diff --git a/src/options.mjs b/src/options.mjs index 3a67fff3d..e28876ca5 100644 --- a/src/options.mjs +++ b/src/options.mjs @@ -5,7 +5,7 @@ export default { since: "0.13.0", category: CATEGORY_PHP, type: "choice", - default: "7.0", + default: "8.3", description: "Minimum target PHP version.", choices: [ { value: "5.0" }, diff --git a/tests/assign/__snapshots__/jsfmt.spec.mjs.snap b/tests/assign/__snapshots__/jsfmt.spec.mjs.snap index 27dfa6187..b9d4aef69 100644 --- a/tests/assign/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/assign/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`assign.php 1`] = ` ====================================options===================================== @@ -234,13 +234,13 @@ $obj->property = $obj->oneProperty = $obj->twoPeroperty = 0; $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = 0; $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = $veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongValue; $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = (new MyClass())->call( - $arg + $arg, ); $obj->loooooooooooong->lookup = $this->getRequest()->getParam( - "instance-resource-id" + "instance-resource-id", ); $obj->loooooooooooong->lookup = (int) $this->getRequest()->getParam( - "instance-resource-id" + "instance-resource-id", ); $component = diff --git a/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap b/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap index 7d30d00a9..c2b776223 100644 --- a/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/attributes/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`attributes.php 1`] = ` ====================================options===================================== @@ -158,25 +158,25 @@ class D "aaaaaaaaaaaaa", "vvvvvvvvvvvv", "cccccccccc", - "eeeeeeeeeee" + "eeeeeeeeeee", ), - X + X, ] function Y( #[ ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ( 12345678, - 1234578 - ) + 1234578, + ), ] - string $_ + string $_, ): string { return new #[NON, Anon] class {}; } #[ IA("interface"), - \\Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong\\Namespace\\WithStuff\\IB + \\Looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong\\Namespace\\WithStuff\\IB, ] interface IC { @@ -209,7 +209,7 @@ class ValueModel { #[ Assert\\NotBlank(allowNull: false, groups: ["foo"]), - Assert\\Length(max: 255, groups: ["foo"]) + Assert\\Length(max: 255, groups: ["foo"]), ] public ?string $value = null; } @@ -233,7 +233,7 @@ class ParamCommentFunctionAnnotation #[Foo] function bar( int $a, // parameter comment - int $b + int $b, ) { return $a + $b; } @@ -242,7 +242,7 @@ class ParamCommentFunctionAnnotation function bar2( int $a, int $middle, // parameter comment - int $b + int $b, ) { return $a + $middle + $b; } diff --git a/tests/bin/__snapshots__/jsfmt.spec.mjs.snap b/tests/bin/__snapshots__/jsfmt.spec.mjs.snap index cd784e8db..787a4f6d2 100644 --- a/tests/bin/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/bin/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`bin.php 1`] = ` ====================================options===================================== @@ -455,7 +455,7 @@ function f() { if ( get_option( - "woocommerce_product_cart_actions_notification_more_cart" + "woocommerce_product_cart_actions_notification_more_cart", ) === "yes" && count($cartItems) > 0 ) { @@ -490,7 +490,7 @@ call( "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVery" ? 1 : 2, - "arg" + "arg", ); $var = @@ -660,13 +660,13 @@ $var = call($var > $someOtherReallyReallyLongVariable ? true : false); $var = call( $someOtherReallyReallyLongVariable > $someOtherReallyReallyLongVariable ? true - : false + : false, ); $var = call( $someOtherReallyReallyReallyReallyReallyReallyLongVariable > $someOtherReallyReallyReallyReallyReallyReallyLongVariable ? true - : false + : false, ); return $var > $var ? true : false; @@ -686,7 +686,7 @@ func( $glimseGlyphsHazardNoopsTieTie === averredBathersBoxroomBuggyNurl && $anodyneCondosMalateOverateRetinol ? $annularCooeedSplicesWalksWayWay - : $kochabCooieGameOnOboleUnweave + : $kochabCooieGameOnOboleUnweave, ); $var = $a ?? $b; @@ -714,7 +714,7 @@ $var = call( $someOtherReallyReallyLongVariable, $someOtherReallyReallyLongVariable, - $someOtherReallyReallyLongVariable + $someOtherReallyReallyLongVariable, )))); $var = $someOtherReallyReallyLongVariable ?? diff --git a/tests/brace-style/__snapshots__/jsfmt.spec.mjs.snap b/tests/brace-style/__snapshots__/jsfmt.spec.mjs.snap index 4db4b933b..389ba6b8e 100644 --- a/tests/brace-style/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/brace-style/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`classes.php 1`] = ` ====================================options===================================== @@ -486,7 +486,7 @@ function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVer function reeeeeeeeeeaaaaaaaallllllllyyyyyy_llloooooooonnnnnnggggg( $soooooooooooo_looooooooonnnng, - $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr + $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr, ) { return $soooooooooooo_looooooooonnnng; } @@ -498,7 +498,7 @@ function type_hinting_test( float $float_test, iterable $iterable_test, int $int_test, - string $string_test = "" + string $string_test = "", ) { return $int_test; } @@ -511,7 +511,7 @@ $anonymousLongVariableName = function ( $name, $more, $params, - $looooooooooooooooooooooooooooooooong + $looooooooooooooooooooooooooooooooong, ) use ($all, $kinds, $of, $stuff) { printf("Hello %s", $name); }; @@ -579,7 +579,7 @@ function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVer function reeeeeeeeeeaaaaaaaallllllllyyyyyy_llloooooooonnnnnnggggg( $soooooooooooo_looooooooonnnng, - $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr + $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr, ) { return $soooooooooooo_looooooooonnnng; } @@ -591,7 +591,7 @@ function type_hinting_test( float $float_test, iterable $iterable_test, int $int_test, - string $string_test = "" + string $string_test = "", ) { return $int_test; } @@ -604,7 +604,7 @@ $anonymousLongVariableName = function ( $name, $more, $params, - $looooooooooooooooooooooooooooooooong + $looooooooooooooooooooooooooooooooong, ) use ($all, $kinds, $of, $stuff) { printf("Hello %s", $name); }; @@ -672,7 +672,7 @@ function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVer function reeeeeeeeeeaaaaaaaallllllllyyyyyy_llloooooooonnnnnnggggg( $soooooooooooo_looooooooonnnng, - $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr + $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr, ) { return $soooooooooooo_looooooooonnnng; } @@ -684,7 +684,7 @@ function type_hinting_test( float $float_test, iterable $iterable_test, int $int_test, - string $string_test = "" + string $string_test = "", ) { return $int_test; } @@ -697,7 +697,7 @@ $anonymousLongVariableName = function ( $name, $more, $params, - $looooooooooooooooooooooooooooooooong + $looooooooooooooooooooooooooooooooong, ) use ($all, $kinds, $of, $stuff) { printf("Hello %s", $name); }; @@ -762,7 +762,7 @@ function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVer function reeeeeeeeeeaaaaaaaallllllllyyyyyy_llloooooooonnnnnnggggg( $soooooooooooo_looooooooonnnng, - $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr + $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr, ) { return $soooooooooooo_looooooooonnnng; } @@ -774,7 +774,7 @@ function type_hinting_test( float $float_test, iterable $iterable_test, int $int_test, - string $string_test = "" + string $string_test = "", ) { return $int_test; } @@ -787,7 +787,7 @@ $anonymousLongVariableName = function ( $name, $more, $params, - $looooooooooooooooooooooooooooooooong + $looooooooooooooooooooooooooooooooong, ) use ($all, $kinds, $of, $stuff) { printf("Hello %s", $name); }; @@ -942,7 +942,7 @@ class Foo function reeeeeeeeeeaaaaaaaallllllllyyyyyy_llloooooooonnnnnnggggg( $soooooooooooo_looooooooonnnng, - $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr + $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr, ) { return $soooooooooooo_looooooooonnnng; } @@ -954,7 +954,7 @@ class Foo float $float_test, iterable $iterable_test, int $int_test, - string $string_test = "" + string $string_test = "", ) { return $int_test; } @@ -964,7 +964,7 @@ class Foo $max_length, // @codingStandardsIgnoreLine $ellipses = " … ", // the spaces are non-breaking spaces - &$flag = null + &$flag = null, ) { return "hello"; } @@ -976,7 +976,7 @@ class Foo $max_length, // @codingStandardsIgnoreLine $ellipses = " … ", // the spaces are non-breaking spaces - &$flag = null + &$flag = null, ) { $string = trim($string); } @@ -988,43 +988,43 @@ class Foo public static function hello_4( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ) {} public static function hello_5( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ): ?string {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName() {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( - $var = 1 + $var = 1, ) {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ) {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ): ?string {} public static function newlines( $var = 1, - $other_var = 2 + $other_var = 2, ) {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $var = 1, - $other_var = 2 + $other_var = 2, ) {} } @@ -1179,7 +1179,7 @@ class Foo function reeeeeeeeeeaaaaaaaallllllllyyyyyy_llloooooooonnnnnnggggg( $soooooooooooo_looooooooonnnng, - $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr + $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr, ) { return $soooooooooooo_looooooooonnnng; } @@ -1191,7 +1191,7 @@ class Foo float $float_test, iterable $iterable_test, int $int_test, - string $string_test = "" + string $string_test = "", ) { return $int_test; } @@ -1201,7 +1201,7 @@ class Foo $max_length, // @codingStandardsIgnoreLine $ellipses = " … ", // the spaces are non-breaking spaces - &$flag = null + &$flag = null, ) { return "hello"; } @@ -1213,7 +1213,7 @@ class Foo $max_length, // @codingStandardsIgnoreLine $ellipses = " … ", // the spaces are non-breaking spaces - &$flag = null + &$flag = null, ) { $string = trim($string); } @@ -1225,43 +1225,43 @@ class Foo public static function hello_4( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ) {} public static function hello_5( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ): ?string {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName() {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( - $var = 1 + $var = 1, ) {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ) {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ): ?string {} public static function newlines( $var = 1, - $other_var = 2 + $other_var = 2, ) {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $var = 1, - $other_var = 2 + $other_var = 2, ) {} } @@ -1416,7 +1416,7 @@ class Foo function reeeeeeeeeeaaaaaaaallllllllyyyyyy_llloooooooonnnnnnggggg( $soooooooooooo_looooooooonnnng, - $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr + $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr, ) { return $soooooooooooo_looooooooonnnng; } @@ -1428,7 +1428,7 @@ class Foo float $float_test, iterable $iterable_test, int $int_test, - string $string_test = "" + string $string_test = "", ) { return $int_test; } @@ -1438,7 +1438,7 @@ class Foo $max_length, // @codingStandardsIgnoreLine $ellipses = " … ", // the spaces are non-breaking spaces - &$flag = null + &$flag = null, ) { return "hello"; } @@ -1450,7 +1450,7 @@ class Foo $max_length, // @codingStandardsIgnoreLine $ellipses = " … ", // the spaces are non-breaking spaces - &$flag = null + &$flag = null, ) { $string = trim($string); } @@ -1462,43 +1462,43 @@ class Foo public static function hello_4( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ) {} public static function hello_5( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ): ?string {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName() {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( - $var = 1 + $var = 1, ) {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ) {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ): ?string {} public static function newlines( $var = 1, - $other_var = 2 + $other_var = 2, ) {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $var = 1, - $other_var = 2 + $other_var = 2, ) {} } @@ -1645,7 +1645,7 @@ class Foo { function reeeeeeeeeeaaaaaaaallllllllyyyyyy_llloooooooonnnnnnggggg( $soooooooooooo_looooooooonnnng, - $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr + $eeeeeeeeevvveeeeeeeennnn_loooooonnngggeeeerrrr, ) { return $soooooooooooo_looooooooonnnng; } @@ -1657,7 +1657,7 @@ class Foo { float $float_test, iterable $iterable_test, int $int_test, - string $string_test = "" + string $string_test = "", ) { return $int_test; } @@ -1667,7 +1667,7 @@ class Foo { $max_length, // @codingStandardsIgnoreLine $ellipses = " … ", // the spaces are non-breaking spaces - &$flag = null + &$flag = null, ) { return "hello"; } @@ -1679,7 +1679,7 @@ class Foo { $max_length, // @codingStandardsIgnoreLine $ellipses = " … ", // the spaces are non-breaking spaces - &$flag = null + &$flag = null, ) { $string = trim($string); } @@ -1691,43 +1691,43 @@ class Foo { public static function hello_4( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ) {} public static function hello_5( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ): ?string {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName() {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( - $var = 1 + $var = 1, ) {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ) {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $var = 1, $other_var = 2, - $other_other_other_var = 3 + $other_other_other_var = 3, ): ?string {} public static function newlines( $var = 1, - $other_var = 2 + $other_var = 2, ) {} public static function veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongName( $var = 1, - $other_var = 2 + $other_var = 2, ) {} } diff --git a/tests/call/__snapshots__/jsfmt.spec.mjs.snap b/tests/call/__snapshots__/jsfmt.spec.mjs.snap index 94fbc34ed..be49c6300 100644 --- a/tests/call/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/call/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`call.php 1`] = ` ====================================options===================================== @@ -386,7 +386,7 @@ $db->Execute( $somewhatLongParameterX, $somewhatLongParameterXYZ, ], - $sql + $sql, ); $app->get("/hello/{name}", function ($name) use ($app) { @@ -395,19 +395,19 @@ $app->get("/hello/{name}", function ($name) use ($app) { $this->something->method( $argument, - $this->more->stuff($this->even->more->things->complicatedMethod()) + $this->more->stuff($this->even->more->things->complicatedMethod()), ); $this->something->method( $this->more->stuff($this->even->more->things->complicatedMethod()), - $argument + $argument, ); $this->something->method( $argument, $otherArgument, ["foo" => "bar", "baz" => "buzz"], - $this->even->more->things->complicatedMethod() + $this->even->more->things->complicatedMethod(), ); $this->files->put($path, $this->expiration($minutes) . serialize($value), true); @@ -432,7 +432,7 @@ $this->filter([ $this->assertEquals( ["First", "Second", "Taylor", "Mohamed", "Jeffrey", "Abigail", "Lydia"], - $results + $results, ); $this->assertEquals(["First"], $results); @@ -451,7 +451,7 @@ $some->other->thing( "foo" => "bar", "buzz" => $this->is->nested([12, 34, 45, 67, 89]), ], - [11323123, 1231, 13231233243, 324234234] + [11323123, 1231, 13231233243, 324234234], ); $foo->bar( @@ -459,12 +459,12 @@ $foo->bar( function ($arg2) use ($var1) { // body }, - $arg3 + $arg3, ); $packages = array_merge( idx($composer, "require", []), - idx($composer, "require-dev", []) + idx($composer, "require-dev", []), ); if ( @@ -474,7 +474,7 @@ if ( function ($acc, $tmp) { return $acc ^ $tmp; }, - 0 + 0, ) ) { return []; @@ -484,21 +484,21 @@ implode( ", ", array_map(function ($f) { return $f; - }, array_merge($arr1, $arr2, $arr3)) + }, array_merge($arr1, $arr2, $arr3)), ); call( function () { return thing(); }, - 1 ? 2 : 3 + 1 ? 2 : 3, ); call( function () { return thing(); }, - something() ? someOtherThing() : somethingElse(true, 0) + something() ? someOtherThing() : somethingElse(true, 0), ); call( @@ -507,7 +507,7 @@ call( }, something($longArgumentName, $anotherLongArgumentName) ? someOtherThing() - : somethingElse(true, 0) + : somethingElse(true, 0), ); call( @@ -518,10 +518,10 @@ call( $longArgumentName, $anotherLongArgumentName, $anotherLongArgumentName, - $anotherLongArgumentName + $anotherLongArgumentName, ) ? someOtherThing() - : somethingElse(true, 0) + : somethingElse(true, 0), ); array_map( @@ -530,7 +530,7 @@ array_map( }, is_array($attributes["alignment"]) ? $attributes["alignment"] - : explode(" ", $attributes["alignment"]) + : explode(" ", $attributes["alignment"]), ); call(' @@ -542,7 +542,7 @@ call( ' string string -string' +string', ); call( @@ -550,7 +550,7 @@ call( string string string', - $a + $a, ); call( @@ -558,7 +558,7 @@ call( ' string string -string' +string', ); call(" @@ -570,7 +570,7 @@ call( " string string -string" +string", ); call( @@ -578,7 +578,7 @@ call( string string string", - $a + $a, ); call( @@ -586,7 +586,7 @@ call( " string string -string" +string", ); $a->call(' @@ -598,7 +598,7 @@ $a->bar->call( ' string string -string' +string', ); $a->call(' @@ -615,14 +615,14 @@ $a->call( string string string', - $c + $c, )->call( $a, ' string string string', - $c + $c, ); call("string $var string"); @@ -636,7 +636,7 @@ call( "string string string -$var" +$var", ); call(\`string $var string\`); @@ -650,54 +650,58 @@ call( \`string string string -$var\` +$var\`, ); call( <<foo)(); diff --git a/tests/case/__snapshots__/jsfmt.spec.mjs.snap b/tests/case/__snapshots__/jsfmt.spec.mjs.snap index f254aafbd..8b25cbdaf 100644 --- a/tests/case/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/case/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`case.php 1`] = ` ====================================options===================================== @@ -332,7 +332,7 @@ final class MyClass extends Bar implements iTemplate break; } - while (list($key, $value) = foo($arr)) { + while ([$key, $value] = foo($arr)) { if (!($key % 2)) { continue; } @@ -363,7 +363,7 @@ final class MyClass extends Bar implements iTemplate $noArgs_longVars = function () use ( $longVar1, $longerVar2, - $muchLongerVar3 + $muchLongerVar3, ) { // Body }; @@ -484,7 +484,7 @@ final class MyClass extends Bar implements iTemplate object $param6, ClassA $param7, self $param8, - Name\\Space\\ClassA $param8 + Name\\Space\\ClassA $param8, ): void { // Nothing } diff --git a/tests/class/__snapshots__/jsfmt.spec.mjs.snap b/tests/class/__snapshots__/jsfmt.spec.mjs.snap index cf60d29d6..6fff7326e 100644 --- a/tests/class/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/class/__snapshots__/jsfmt.spec.mjs.snap @@ -303,7 +303,7 @@ $app->setLogger( { echo $msg; } - } + }, ); $app->setLogger( new class { @@ -311,7 +311,7 @@ $app->setLogger( { echo $msg; } - } + }, ); var_dump( @@ -324,7 +324,7 @@ var_dump( } use SomeTrait; - } + }, ); class Outer @@ -427,7 +427,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) {}; $class = new class ( @@ -438,7 +438,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) implements MyOtherClass {}; $class = new class ( @@ -449,7 +449,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) implements MyOtherClass, MyOtherClass1, MyOtherClass2 {}; $class = new class ( @@ -460,7 +460,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyOtherClass {}; @@ -472,7 +472,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) implements MyOtherClass, MyOtherClass, @@ -487,7 +487,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) extends MyOtherClass {}; $class = new class ( @@ -498,7 +498,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass {}; @@ -510,7 +510,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) extends MyOtherClass implements MyI {}; $class = new class ( @@ -521,7 +521,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) extends MyOtherClass implements MyI, MyII, MyIII {}; $class = new class ( @@ -532,7 +532,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) extends MyOtherClass implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass {}; @@ -544,7 +544,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) extends MyOtherClass implements MyInterface, MyOtherInterface, @@ -558,7 +558,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass implements MyI {}; @@ -571,7 +571,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass implements @@ -587,7 +587,7 @@ $class = new class ( $other_arg, function () { return 1; - } + }, ) extends VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass implements VeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMyClass {}; @@ -1004,7 +1004,7 @@ abstract class ReallyReallyReallyLongClassName $test_int = null, $test_string = "hi", readonly int $test_readonly, - public readonly string $test_promoted_readonly + public readonly string $test_promoted_readonly, ) { parent::__construct($test_int ?: 1); $this->other = $test_string; @@ -1016,13 +1016,13 @@ abstract class ReallyReallyReallyLongClassName public static function test_static_constructor( $test, $test_int, - $test_string + $test_string, ) { $model = new self($test, $test_int, $test_string); $model = new self( $really_really_really_really_really_really_really_really_long_array, $test_int, - $test_string + $test_string, ); return $model; } @@ -1048,7 +1048,7 @@ abstract class ReallyReallyReallyLongClassName public function reallyReallyReallyReallyReallyReallyReallyLongMethodName( $input, - $otherInput = 1 + $otherInput = 1, ) { return true; } @@ -1115,7 +1115,7 @@ abstract class ReallyReallyReallyLongClassName public function longLongAnotherFunction( string $foo, string $bar, - int $baz + int $baz, ): string { return "foo"; } @@ -1123,7 +1123,7 @@ abstract class ReallyReallyReallyLongClassName public function longLongAnotherFunctionOther( string $foo, string $bar, - int $baz + int $baz, ) { return "foo"; } @@ -1141,7 +1141,7 @@ abstract class ReallyReallyReallyLongClassName $this->something->method( $argument, - $this->more->stuff($this->even->more->things->complicatedMethod()) + $this->more->stuff($this->even->more->things->complicatedMethod()), ); class A {} @@ -1224,9 +1224,9 @@ class field extends \\models\\base array_merge( $configs, $field_type->process_field_config_from_user( - $input["definition"] - ) - ) + $input["definition"], + ), + ), ); unset($input["definition"]); } @@ -1379,7 +1379,7 @@ class Promoted public function __construct( public int $a, private float $b, - protected string $d + protected string $d, ) {} } diff --git a/tests/classconstant/__snapshots__/jsfmt.spec.mjs.snap b/tests/classconstant/__snapshots__/jsfmt.spec.mjs.snap index fa8ee35e7..9a66f8297 100644 --- a/tests/classconstant/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/classconstant/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`classconstant.php 1`] = ` ====================================options===================================== @@ -125,15 +125,15 @@ class ConstDemo 1200 + 1300; const CONST_9 = <<veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLeadDeveloper; $OneSecAgo = (clone $Now)->veryVeryVeryVeryVeryVeryVeryVeryLongMethod( - new \\DateInterval("PT1S") + new \\DateInterval("PT1S"), ); ================================================================================ diff --git a/tests/closure/__snapshots__/jsfmt.spec.mjs.snap b/tests/closure/__snapshots__/jsfmt.spec.mjs.snap index 2917294b0..f9e4e1129 100644 --- a/tests/closure/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/closure/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`closure.php 1`] = ` ====================================options===================================== @@ -158,7 +158,7 @@ $closureWithArgsAndVars = function ($arg1, $arg2) use ($var1, $var2) { $longArgs_noVars = function ( $longArgument, $longerArgument, - $muchLongerArgument + $muchLongerArgument, ) { // body }; @@ -166,7 +166,7 @@ $longArgs_noVars = function ( $noArgs_longVars = function () use ( $longLongLongLongVar1, $longerLongerVar2, - $muchLongerVar3 + $muchLongerVar3, ) { // body }; @@ -174,11 +174,11 @@ $noArgs_longVars = function () use ( $longArgs_longVars = function ( $longArgument, $longerArgument, - $muchLongerArgument + $muchLongerArgument, ) use ( $longLongLongLongLongLongLongVar1, $longerLongerLongerLongerVar2, - $muchLongerVar3 + $muchLongerVar3, ) { // body }; @@ -186,7 +186,7 @@ $longArgs_longVars = function ( $longArgs_shortVars = function ( $longArgument, $longerArgument, - $muchLongerArgument + $muchLongerArgument, ) use ($var1) { // body }; @@ -194,7 +194,7 @@ $longArgs_shortVars = function ( $shortArgs_longVars = function ($arg) use ( $longVar1, $longerVar2, - $muchLongerVar3 + $muchLongerVar3, ) { // body }; @@ -204,7 +204,7 @@ $foo->bar( function ($arg2) use ($var1) { // body }, - $longLongLongLongLongLongLongLongLongLongArg3 + $longLongLongLongLongLongLongLongLongLongArg3, ); $emptyFunc = function () {}; @@ -216,7 +216,7 @@ $emptyFuncWithComment = function () { $longArgs_noVars = function ( $longArgument, $longerArgument, - $muchLongerArgument + $muchLongerArgument, ) { // body }; @@ -228,7 +228,7 @@ $noArgs_longVars = function () use ($longVar1, $longerVar2, $muchLongerVar3) { $longArgs_longVars = function ( $longArgument, $longerArgument, - $muchLongerArgument + $muchLongerArgument, ) use ($longVar1, $longerVar2, $muchLongerVar3) { // body }; @@ -236,7 +236,7 @@ $longArgs_longVars = function ( $longArgs_shortVars = function ( $longArgument, $longerArgument, - $muchLongerArgument + $muchLongerArgument, ) use ($var1) { // body }; @@ -244,7 +244,7 @@ $longArgs_shortVars = function ( $shortArgs_longVars = function ($arg) use ( $longVar1, $longerVar2, - $muchLongerVar3 + $muchLongerVar3, ) { // body }; @@ -264,7 +264,7 @@ $rTDWU = function (array $array) use ($var1, $var2): int { $rTDWLU = function (array $array) use ( $longLongLongLongLongLongLongVar1, $longerLongerLongerLongerVar2, - $muchLongerVar3 + $muchLongerVar3, ): int { return array_sum($array); }; diff --git a/tests/comments/__snapshots__/jsfmt.spec.mjs.snap b/tests/comments/__snapshots__/jsfmt.spec.mjs.snap index a01c42f14..bc5b490f0 100644 --- a/tests/comments/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/comments/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`array.php 1`] = ` ====================================options===================================== @@ -204,7 +204,7 @@ $array = [ ]; call( - [] // Comment + [], // Comment ); call([ @@ -588,7 +588,7 @@ $var->render( foo( /* Comment */ $a /* Comment */, /* Comment */ [] /* Comment */, - /* Comment */ $a + 2 /* Comment */ + /* Comment */ $a + 2 /* Comment */, ); foo(/* A */); $foo->bar(/* B */); @@ -596,24 +596,24 @@ $foo->bar(/* B */); render( // Comment "string", - $container + $container, ); $var->render( // Comment "string", - $var + $var, ); render( "string", - $container + $container, // Comment ); $var->render( "string", - $var + $var, // Comment ); @@ -621,7 +621,7 @@ $var->render( // Comment "string", // Comment - $var + $var, // Comment ); @@ -2745,22 +2745,22 @@ echo // Comment call( $veryVeryVeryVeryVeryVeryVeryLongArg, $veryVeryVeryVeryVeryVeryVeryLongArg, - $veryVeryVeryVeryVeryVeryVeryLongArg + $veryVeryVeryVeryVeryVeryVeryLongArg, ); echo // Comment <<city, // city $vendor->state, // state - $vendor->zip // state + $vendor->zip, // state ); } } @@ -5883,7 +5883,7 @@ $a = new class ( // Comment $a, $b, - $c + $c, ) {}; $a = new class ( @@ -5892,7 +5892,7 @@ $a = new class ( // Comment $b, // Comment - $c + $c, ) {}; $a = new class { @@ -6221,28 +6221,28 @@ class MyClass { function foo( /* Comment */ $a, - /* Comment */ array /* Comment2 */ $b /* Comment */ = /* Comment */ [] /* Comment */ + /* Comment */ array /* Comment2 */ $b /* Comment */ = /* Comment */ [] /* Comment */, ) {} function bar(/* Comment */ &$a /* Comment */) {} function baz( /* Comment */ $a, - /* Comment */ array /* Comment3 */ &$b /* Comment */ = /* Comment */ [] /* Comment */ + /* Comment */ array /* Comment3 */ &$b /* Comment */ = /* Comment */ [] /* Comment */, ) {} class MyClass { public function foo( /* Comment */ $a, - /* Comment */ array /* Comment2 */ $b /* Comment */ = /* Comment */ [] /* Comment */ + /* Comment */ array /* Comment2 */ $b /* Comment */ = /* Comment */ [] /* Comment */, ) {} public function bar(/* Comment */ &$a /* Comment */) {} public function baz( /* Comment */ $a, - /* Comment */ array /* Comment3 */ &$b /* Comment */ = /* Comment */ [] /* Comment */ + /* Comment */ array /* Comment3 */ &$b /* Comment */ = /* Comment */ [] /* Comment */, ) {} } @@ -6333,7 +6333,7 @@ print // Comment print call( // Comment - $a + $a, ); print // Comment @@ -6471,14 +6471,14 @@ class Foo public $bar = // Comment 1 // Comment 2 <<<'EOT' -bar -EOT; + bar + EOT; public $baz = // Comment 1 // Comment 2 << "foo", "barfoo" => "foobar", "foobar" => "barfoo", - ] + ], ); ?>
element( @@ -1183,7 +1183,7 @@ printWidth: 80 "bar" => "foo", "barfoo" => "foobar", "foobar" => "barfoo", - ] + ], ); ?>
@@ -1803,7 +1803,7 @@ printWidth: 80 value="id); ?>" chosen, true); ?> data-text="order_button_text + $gateway->order_button_text, ); ?>" @@ -1874,7 +1874,7 @@ func( @@ -1882,7 +1882,7 @@ func( @@ -1890,7 +1890,7 @@ func( @@ -1898,7 +1898,7 @@ func( @@ -1906,7 +1906,7 @@ func( @@ -1914,7 +1914,7 @@ func( @@ -1922,7 +1922,7 @@ func( diff --git a/tests/isset/__snapshots__/jsfmt.spec.mjs.snap b/tests/isset/__snapshots__/jsfmt.spec.mjs.snap index f94ba9377..88f261c05 100644 --- a/tests/isset/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/isset/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`isset.php 1`] = ` ====================================options===================================== @@ -60,14 +60,14 @@ class T a->b); isset( $veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongVariable ->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty - ->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty + ->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty, ); if (isset($var)) { diff --git a/tests/kitchen_sink/__snapshots__/jsfmt.spec.mjs.snap b/tests/kitchen_sink/__snapshots__/jsfmt.spec.mjs.snap index ea8553b76..b468e90a5 100644 --- a/tests/kitchen_sink/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/kitchen_sink/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`kitchen_sink.php 1`] = ` ====================================options===================================== @@ -77,7 +77,7 @@ if ($test == 1) { function really_long_function( $test2 = 1, $long_parameter_name, - $even_longer_longer_longer_longer_longer_parameter_name + $even_longer_longer_longer_longer_longer_parameter_name, ) { return $test2; } diff --git a/tests/list/__snapshots__/jsfmt.spec.mjs.snap b/tests/list/__snapshots__/jsfmt.spec.mjs.snap index 027a6c996..c21e367f4 100644 --- a/tests/list/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/list/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`list.php 1`] = ` ====================================options===================================== @@ -159,110 +159,110 @@ list( $info = ["coffee", "brown", "caffeine"]; // Listing all the variables -list($drink, $color, $power) = $info; +[$drink, $color, $power] = $info; echo "$drink is $color and $power makes it special.\\n"; // Listing some of them -list($drink, , $power) = $info; +[$drink, , $power] = $info; echo "$drink has $power.\\n"; // Or let's skip to only the third one -list(, , $power) = $info; +[, , $power] = $info; echo "I need $power!\\n"; // list() doesn't work with strings -list($bar) = "abcde"; +[$bar] = "abcde"; var_dump($bar); // NULL -while (list($id, $name, $salary) = $result->fetch(PDO::FETCH_NUM)) { +while ([$id, $name, $salary] = $result->fetch(PDO::FETCH_NUM)) { } -list($a, list($b, $c)) = [1, [2, 3]]; +[$a, [$b, $c]] = [1, [2, 3]]; $info = ["coffee", "brown", "caffeine"]; -list($a[0], $a[1], $a[2]) = $info; +[$a[0], $a[1], $a[2]] = $info; -list("id" => $id1, "name" => $name1) = $data[0]; -list( +["id" => $id1, "name" => $name1] = $data[0]; +[ "veryVeryVeryVeryVeryLongKey" => $veryVeryVeryVeryVeryLongValue, "veryVeryVeryVeryVeryLongKey" => $veryVeryVeryVeryVeryLongValue, -) = $data[0]; -list( +] = $data[0]; +[ "veryVeryVeryVeryVeryVeryVeryVeryVeryLongKey" => $veryVeryVeryVeryVeryVeryVeryVeryVeryLongValue, "veryVeryVeryVeryVeryVeryVeryVeryVeryLongKey" => $veryVeryVeryVeryVeryVeryVeryVeryVeryLongValue, -) = $data[0]; +] = $data[0]; -foreach ($data as list("id" => $id, "name" => $name)) { +foreach ($data as ["id" => $id, "name" => $name]) { // logic here with $id and $name } foreach ( $data - as list( + as [ "veryVeryVeryVeryVeryLongKey" => $veryVeryVeryVeryVeryLongValue, "veryVeryVeryVeryVeryLongKey" => $veryVeryVeryVeryVeryLongValue, - ) + ] ) { // logic here with $id and $name } foreach ( $data - as list( + as [ "veryVeryVeryVeryVeryVeryVeryVeryVeryLongKey" => $veryVeryVeryVeryVeryVeryVeryVeryVeryLongValue, "veryVeryVeryVeryVeryVeryVeryVeryVeryLongKey" => $veryVeryVeryVeryVeryVeryVeryVeryVeryLongValue, - ) + ] ) { // logic here with $id and $name } -list(, $b) = ["a", "b"]; -list(, , $c) = ["a", "b", "c"]; +[, $b] = ["a", "b"]; +[, , $c] = ["a", "b", "c"]; -while (list($id, $name, $salary) = $result->fetch(PDO::FETCH_NUM)) { +while ([$id, $name, $salary] = $result->fetch(PDO::FETCH_NUM)) { echo " \\n" . " $name\\n" . " $salary\\n" . " \\n"; } -list($a, list($b, $c)) = [1, [2, 3]]; +[$a, [$b, $c]] = [1, [2, 3]]; -list($a[0], $a[1], $a[2]) = $info; +[$a[0], $a[1], $a[2]] = $info; foreach ($data as ["id" => $id, "name" => $name]) { echo "id: $id, name: $name\\n"; } -list(0 => $first, 1 => $second, 2 => $three, 3 => $fourth) = $arr; -list( +[0 => $first, 1 => $second, 2 => $three, 3 => $fourth] = $arr; +[ 0 => $first, 1 => $second, 2 => $three, 3 => $fourth, -) = $arr; +] = $arr; -list($first, $second, $three, $fourth) = $arr; -list(, $first, $second, $three, $fourth) = $arr; -list(, , $first, $second, $three, $fourth, ,) = $arr; -list(, , $first, , $second, , $three, , $fourth, ,) = $arr; -list(, , , $first, $second, $three, $fourth, , ,) = $arr; -list(, , , $first, , , $second, , , $three, , , $fourth, , ,) = $arr; +[$first, $second, $three, $fourth] = $arr; +[, $first, $second, $three, $fourth] = $arr; +[, , $first, $second, $three, $fourth, ,] = $arr; +[, , $first, , $second, , $three, , $fourth, ,] = $arr; +[, , , $first, $second, $three, $fourth, , ,] = $arr; +[, , , $first, , , $second, , , $three, , , $fourth, , ,] = $arr; -list( +[ 0 => $firstVeryVeryVeryVeryLong, 1 => $secondVeryVeryVeryVeryLong, 2 => $threeVeryVeryVeryVeryLong, 3 => $fourthVeryVeryVeryVeryLong, -) = $arr; -list( +] = $arr; +[ , 0 => $firstVeryVeryVeryVeryLong, 1 => $secondVeryVeryVeryVeryLong, 2 => $threeVeryVeryVeryVeryLong, 3 => $fourthVeryVeryVeryVeryLong, -) = $arr; -list( +] = $arr; +[ , , 0 => $firstVeryVeryVeryVeryLong, @@ -270,8 +270,8 @@ list( 2 => $threeVeryVeryVeryVeryLong, 3 => $fourthVeryVeryVeryVeryLong, , -) = $arr; -list( +] = $arr; +[ , , 0 => $firstVeryVeryVeryVeryLong, @@ -282,8 +282,8 @@ list( , 3 => $fourthVeryVeryVeryVeryLong, , -) = $arr; -list( +] = $arr; +[ , , , @@ -293,8 +293,8 @@ list( 3 => $fourthVeryVeryVeryVeryLong, , , -) = $arr; -list( +] = $arr; +[ , , , @@ -310,9 +310,9 @@ list( 3 => $fourthVeryVeryVeryVeryLong, , , -) = $arr; +] = $arr; -list( +[ 0 => $firstVeryVeryVeryVeryLong, 1 => $secondVeryVeryVeryVeryLong, @@ -320,12 +320,12 @@ list( 2 => $threeVeryVeryVeryVeryLong, 3 => $fourthVeryVeryVeryVeryLong, -) = $arr; +] = $arr; -list("id" => $id1, "name" => $name1) = $data[0]; +["id" => $id1, "name" => $name1] = $data[0]; ["id" => $id1, "name" => $name1] = $data[0]; -foreach ($data as list("id" => $id, "name" => $name)) { +foreach ($data as ["id" => $id, "name" => $name]) { // logic here with $id and $name } @@ -339,60 +339,60 @@ function swap(&$a, &$b): void } $array = [1, 2]; -list($a, &$b) = $array; [$a, &$b] = $array; -list(&$a, $b, , list(&$c, $d)) = $array; +[$a, &$b] = $array; +[&$a, $b, , [&$c, $d]] = $array; [&$a, $b, , [&$c, $d]] = $array; -foreach ($array as list(&$a, $b)) { +foreach ($array as [&$a, $b]) { } foreach ($array as [&$a, $b]) { } -list(0 => $var) = $arr; -list(0 => $var) = $arr; -list(, 0 => $var) = $arr; -list(0 => $var) = $arr; -list( +[0 => $var] = $arr; +[0 => $var] = $arr; +[, 0 => $var] = $arr; +[0 => $var] = $arr; +[ 0 => $var, -) = $arr; -list( +] = $arr; +[ , 0 => $var, -) = $arr; -list( +] = $arr; +[ , 0 => $var, -) = $arr; -list( +] = $arr; +[ , 0 => $var, , -) = $arr; -list( +] = $arr; +[ 0 => $var, 1 => $other_var, -) = $arr; -list( +] = $arr; +[ , 0 => $var, 1 => $other_var, -) = $arr; -list( +] = $arr; +[ , 0 => $var, 1 => $other_var, -) = $arr; -list( +] = $arr; +[ , 0 => $var, 1 => $other_var, , -) = $arr; -list(0 => $var) = $arr; -list( +] = $arr; +[0 => $var] = $arr; +[ 0 => $var, -) = $arr; +] = $arr; ================================================================================ `; diff --git a/tests/member_chain/__snapshots__/jsfmt.spec.mjs.snap b/tests/member_chain/__snapshots__/jsfmt.spec.mjs.snap index 283177c24..548a8e419 100644 --- a/tests/member_chain/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/member_chain/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`break-last-call.php 1`] = ` ====================================options===================================== @@ -34,7 +34,7 @@ function call($store) actionWith([ "response" => $response, "type" => $successType, - ]) + ]), ); }, function ($error) { @@ -42,9 +42,9 @@ function call($store) actionWith([ "type" => $failureType, "error" => $error->message || "Something bad happened", - ]) + ]), ); - } + }, ); } @@ -470,7 +470,7 @@ return tap( $this->forceFill([ "approver_id" => $user instanceof User ? $user->id : $user, "approved_at" => $this->freshTimestamp(), - ]) + ]), )->save(); return collect(parent::jsonSerialize()) @@ -518,7 +518,7 @@ $a = $t ->once(); $this->loooooooooooong->lookup = (int) $this->getRequest()->getParam( - "some-param" + "some-param", ); $this->loooooooooooong->lookup = (int) $variable @@ -541,24 +541,24 @@ $aVariable = $theThing bar()(); bar( - "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong" + "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong", )(); bar()( - "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong" + "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong", ); bar( - "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong" + "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong", )()()()()(); $foo->bar()(); $foo->bar( - "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong" + "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong", )(); $foo->bar()( - "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong" + "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong", ); $foo->bar( - "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong" + "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong", )()()()()(); $brian->hotel->orders()->ordered()->with("smith")->get(); @@ -641,7 +641,7 @@ $wrapper ->find("SomewhatLongNodeName") ->prop( "longPropFunctionName", - "second argument that pushes this group past 80 characters" + "second argument that pushes this group past 80 characters", ) ->then(function () { doSomething(); @@ -971,7 +971,7 @@ DB::table("identity")->insert([ ]); DB::table( - "identity" + "identity", )->insertReallyReallyReallyReallyReallyReallyReallyReallyReallyLongName([ "ref" => $ref, "handle" => $handle, @@ -991,7 +991,7 @@ Logger::use_logger("albus")->info( [ "uuid" => $uuid, "requested_date" => $date, - ] + ], ); DBwithlongname::table("identity") @@ -1031,7 +1031,7 @@ $page = TableRegistry::insertReallyReallyReallyReallyReallyReallyReallyReallyRea $page = TableRegistry::insertReallyReallyReallyLongName("Pages")[0]; $page = TableRegistry::insertReallyReallyReallyReallyReallyReallyReallyReallyReallyLongName( - "Pages" + "Pages", )[0]; $component = find(".org-lclp-edit-copy-url-banner__link")[0] @@ -1053,7 +1053,7 @@ static::viewFactory() $view ?: static::$defaultSimpleView, array_merge($data, [ "paginator" => $this, - ]) + ]), ) ->render(); static::viewFactory() @@ -1061,7 +1061,7 @@ static::viewFactory() $view ?: static::$defaultSimpleView, array_merge($data, [ "paginator" => $this, - ]) + ]), ) ->render(); self::viewFactory() @@ -1069,7 +1069,7 @@ self::viewFactory() $view ?: static::$defaultSimpleView, array_merge($data, [ "paginator" => $this, - ]) + ]), ) ->render(); parent::viewFactory() @@ -1077,7 +1077,7 @@ parent::viewFactory() $view ?: static::$defaultSimpleView, array_merge($data, [ "paginator" => $this, - ]) + ]), ) ->render(); @@ -1086,7 +1086,7 @@ Foo::viewFactory() $view ?: static::$defaultSimpleView, array_merge($data, [ "paginator" => $this, - ]) + ]), ) ->render(); diff --git a/tests/new/__snapshots__/jsfmt.spec.mjs.snap b/tests/new/__snapshots__/jsfmt.spec.mjs.snap index d29025a20..4a69f1ad5 100644 --- a/tests/new/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/new/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`new.php 1`] = ` ====================================options===================================== @@ -225,7 +225,7 @@ $class = (new Foo([ "VeryVeryVeryVeryVeryVeryVeryVeryVeryLongValue", ]))->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongMethod(); $class = (new PendingDispatch(new $this->class(...func_get_args())))->chain( - $this->chain + $this->chain, ); $dumper = in_array(PHP_SAPI, ["cli", "phpdbg"]) ? new CliDumper() @@ -236,10 +236,10 @@ $class = new static( "] with ID [" . $model->getKey() . "] to JSON: " . - $message + $message, ); $response = new \\Illuminate\\Http\\JsonResponse( - new JsonResponseTestJsonSerializeObject() + new JsonResponseTestJsonSerializeObject(), ); $result = (new Pipeline(new \\Illuminate\\Container\\Container())) ->send("foo") @@ -250,62 +250,64 @@ $result = (new Pipeline(new \\Illuminate\\Container\\Container())) $var = new Foo( <<<'EOD' -Example of string -spanning multiple lines -using nowdoc syntax. -EOD + Example of string + spanning multiple lines + using nowdoc syntax. + EOD , - $arg + $arg, ); $var = new Foo( $arg, <<<'EOD' -Example of string -spanning multiple lines -using nowdoc syntax. -EOD + Example of string + spanning multiple lines + using nowdoc syntax. + EOD + , ); $var = new Foo( $arg, <<<'EOD' -Example of string -spanning multiple lines -using nowdoc syntax. -EOD + Example of string + spanning multiple lines + using nowdoc syntax. + EOD , - $arg + $arg, ); $var = new Foo( << "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString", "key3" => "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString", - ] + ], ) { return $arg; } @@ -211,7 +211,7 @@ function bar2( $arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" . "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" . - "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" + "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString", ) { return $arg; } @@ -219,7 +219,7 @@ function bar2( function bar3( $arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString" ? "1" - : "2" + : "2", ) { return $arg; } @@ -227,7 +227,7 @@ function bar3( function bar4( string $arg = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString" ? "1" - : "2" + : "2", ) { return $arg; } @@ -237,7 +237,7 @@ function bar5( "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" === "veryVeryVeryVeryVeryVeryVeryVeryVeryLongString" ? "1" - : "2" + : "2", ) { return $arg; } @@ -245,7 +245,7 @@ function bar5( function foo( $arg = 'string string -string' +string', ) {} function foo( @@ -254,7 +254,7 @@ string string', $arg = 'string string -string' +string', ) {} function foo( @@ -262,7 +262,7 @@ function foo( $b = 'string string string', - $c + $c, ) {} ================================================================================ diff --git a/tests/parens/__snapshots__/jsfmt.spec.mjs.snap b/tests/parens/__snapshots__/jsfmt.spec.mjs.snap index ed2b205ba..50fbfd49d 100644 --- a/tests/parens/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/parens/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`array.php 1`] = ` ====================================options===================================== @@ -3567,7 +3567,7 @@ switch ($var = 1) { switch ($var = 1) { } -while (list($id, $name, $salary) = $result->fetch(PDO::FETCH_NUM)) { +while ([$id, $name, $salary] = $result->fetch(PDO::FETCH_NUM)) { } while ([$id, $name, $salary] = $result->fetch(PDO::FETCH_NUM)) { } @@ -5027,7 +5027,7 @@ new Translator( new MessageFormatter(), "en", [], - ["foo" => "bar"] + ["foo" => "bar"], ); ?> "bar", @@ -6225,7 +6225,7 @@ try { handle_exception(); } -@list($width, $height) = getimagesize($file); +@[$width, $height] = getimagesize($file); // Todo https://github.com/glayzzle/php-parser/issues/356 // @(list($width, $height) = getimagesize($file)); diff --git a/tests/preserve_line/__snapshots__/jsfmt.spec.mjs.snap b/tests/preserve_line/__snapshots__/jsfmt.spec.mjs.snap index 45c50c6ef..5a67bb15a 100644 --- a/tests/preserve_line/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/preserve_line/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`argument-list.php 1`] = ` ====================================options===================================== @@ -209,14 +209,14 @@ longArgNamesWithComments( $longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong2, /* Hello World */ - $longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong3 + $longlonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglonglong3, ); shortArgNames( $short, $short2, - $short3 + $short3, ); comments( @@ -235,7 +235,7 @@ comments( /* Long Long Long Long Long Comment */ // Long Long Long Long Long Comment - $short3 + $short3, // More comments ); @@ -244,7 +244,7 @@ differentArgTypes( return true; }, - isTrue ? doSomething() : 12 + isTrue ? doSomething() : 12, ); moreArgTypes( @@ -261,31 +261,31 @@ moreArgTypes( // Hello world again ["name" => "Hello World", "age" => 34], - $oneThing + $anotherThing + $oneThing + $anotherThing, // Comment - ) + ), ); evenMoreArgTypes( doSomething( ["name" => "Hello World", "age" => 34], - true + true, ), 14, 1 + 2 - 90 / 80, - !98 * 60 - 90 + !98 * 60 - 90, ); $foo->apply( null, // Array here - [1, 2] + [1, 2], ); $bar->on( @@ -293,7 +293,7 @@ $bar->on( function () { doStuff(); - } + }, ); foo( @@ -302,7 +302,7 @@ foo( /* function here */ function () { return true; - } + }, ); $doSomething->apply( @@ -310,13 +310,13 @@ $doSomething->apply( // Comment - ["Hello world 1", "Hello world 2", "Hello world 3"] + ["Hello world 1", "Hello world 2", "Hello world 3"], ); doAnotherThing( "node", - [$solution_type, $time_frame] + [$solution_type, $time_frame], ); $stuff->doThing( @@ -327,7 +327,7 @@ $stuff->doThing( "accept" => function ($node) { doSomething($node); }, - ] + ], ); doThing( @@ -339,7 +339,7 @@ doThing( "decline" => function ($creditCard) { takeMoney($creditCard); }, - ] + ], ); func( @@ -347,7 +347,7 @@ func( thing(); }, - ["yes" => true, "no" => 5] + ["yes" => true, "no" => 5], ); doSomething( @@ -358,7 +358,7 @@ doSomething( /* Comment */ // This is important - [$helloWorld, $someImportantStuff] + [$helloWorld, $someImportantStuff], ); ================================================================================ diff --git a/tests/print/__snapshots__/jsfmt.spec.mjs.snap b/tests/print/__snapshots__/jsfmt.spec.mjs.snap index d93a2e400..922788033 100644 --- a/tests/print/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/print/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`print.php 1`] = ` ====================================options===================================== @@ -229,10 +229,10 @@ print esc_html( __( "Hi there. Your recent order on %s has been completed. " . "Your order details are shown below for your reference:", - "woocommerce" + "woocommerce", ), - get_option("blogname") - ) + get_option("blogname"), + ), ); print << "very_very_very_long_other_value", ]; public $var8 = <<<'EOD' -hello world -EOD; + hello world + EOD; public $var9 = 11111111111111111111111111111111111111111111111111111111111111111111; public $var10 = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString"; public $var11 = true; diff --git a/tests/propertylookup/__snapshots__/jsfmt.spec.mjs.snap b/tests/propertylookup/__snapshots__/jsfmt.spec.mjs.snap index e0378115a..bbd1aa97f 100644 --- a/tests/propertylookup/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/propertylookup/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`offsets.php 1`] = ` ====================================options===================================== @@ -115,7 +115,7 @@ $this->loooooooooooong->loooooooooooong->loooooooooooong->lookup = $this->loooooooooooong->loooooooooooong->loooooooooooong->lookup = $other->looooooooooong->stuff; $this->loooooooooooong->lookup = (int) $this->getRequest()->getParam( - "instance-resource-id" + "instance-resource-id", ); $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty; diff --git a/tests/retif/__snapshots__/jsfmt.spec.mjs.snap b/tests/retif/__snapshots__/jsfmt.spec.mjs.snap index 94fc73a9f..49603a8d0 100644 --- a/tests/retif/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/retif/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`retif.php 1`] = ` ====================================options===================================== @@ -259,7 +259,7 @@ $test = bar( $someOtherReallyReallyLongVariable, $someOtherReallyReallyLongVariable, - $someOtherReallyReallyLongVariable + $someOtherReallyReallyLongVariable, ); $test = $testReallyReallyReallyReallyReallyReallyLong >= 1 ?: @@ -445,7 +445,7 @@ call( function () { return 1; }, - $var ? 1 : 2 + $var ? 1 : 2, ); call( @@ -454,7 +454,7 @@ call( }, $someOtherReallyReallyLongVariable ? $someOtherReallyReallyLongVariable - : $someOtherReallyReallyLongVariable + : $someOtherReallyReallyLongVariable, ); call( @@ -464,7 +464,7 @@ call( $someOtherReallyReallyLongVariable ?: $someOtherReallyReallyLongVariable ?: $someOtherReallyReallyLongVariable ?: - "test" + "test", ); $var = [ @@ -553,13 +553,13 @@ call($var ?: $var ?: $var ?: "string"); call( $someOtherReallyReallyLongVariable ? $someOtherReallyReallyLongVariable - : $someOtherReallyReallyLongVariable + : $someOtherReallyReallyLongVariable, ); call( $someOtherReallyReallyLongVariable ?: $someOtherReallyReallyLongVariable ?: $someOtherReallyReallyLongVariable ?: - "string" + "string", ); exit($var ? "string" : "other-string"); diff --git a/tests/return/__snapshots__/jsfmt.spec.mjs.snap b/tests/return/__snapshots__/jsfmt.spec.mjs.snap index c1c416e4a..45146d195 100644 --- a/tests/return/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/return/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`return.php 1`] = ` ====================================options===================================== @@ -425,7 +425,7 @@ return new Foo( 1024, $veryVeryVeryVeryVeryVeryLongLine, true, - false + false, ); return new Foo( $arg, @@ -433,7 +433,7 @@ return new Foo( 1024, $veryVeryVeryVeryVeryVeryLongLine, true, - false + false, ) . "string"; return "string" . new Foo( @@ -442,7 +442,7 @@ return "string" . 1024, $veryVeryVeryVeryVeryVeryLongLine, true, - false + false, ); return []; @@ -469,12 +469,12 @@ return $packages || [ ]; return $this->events->until( - new Events\\NotificationSending($notifiable, $notification, $channel) + new Events\\NotificationSending($notifiable, $notification, $channel), ) !== false; return false !== $this->events->until( - new Events\\NotificationSending($notifiable, $notification, $channel) + new Events\\NotificationSending($notifiable, $notification, $channel), ); return $this->getOptions()["endpoint"] ?? @@ -488,7 +488,7 @@ return $this->channels[$name] ?? with($this->resolve($name), function ($logger) use ($name) { return $this->channels[$name] = $this->tap( $name, - new Logger($logger, $this->app["events"]) + new Logger($logger, $this->app["events"]), ); }); @@ -530,7 +530,7 @@ return $this->guards[$name] ?? ($this->guards[$name] = $this->resolve($veryVeryVeryLongVariable)); return $this->guards[$veryVeryVeryLongVariable] ?? ($this->guards[$veryVeryVeryLongVariable] = $this->resolve( - $veryVeryVeryLongVariable + $veryVeryVeryLongVariable, )); return call_user_func($this->passwordValidator, $credentials) && diff --git a/tests/silent/__snapshots__/jsfmt.spec.mjs.snap b/tests/silent/__snapshots__/jsfmt.spec.mjs.snap index 77637a202..523f38a29 100644 --- a/tests/silent/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/silent/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`silent.php 1`] = ` ====================================options===================================== @@ -41,7 +41,7 @@ $variable = @foo() $variable = @foo( "VeryVeryVeryVeryVeryVeryLongArgument", "VeryVeryVeryVeryVeryVeryLongArgument", - "VeryVeryVeryVeryVeryVeryLongArgument" + "VeryVeryVeryVeryVeryVeryLongArgument", ); @trigger_error($error, E_USER_DEPRECATED); $value = @$cache[$key]; diff --git a/tests/single-quote-api/jsfmt.spec.mjs b/tests/single-quote-api/jsfmt.spec.mjs index c95b4ab03..bb9db6fb7 100644 --- a/tests/single-quote-api/jsfmt.spec.mjs +++ b/tests/single-quote-api/jsfmt.spec.mjs @@ -13,7 +13,7 @@ test(`singleQuote option on format api`, async () => { const expected = ` `; diff --git a/tests/string/__snapshots__/jsfmt.spec.mjs.snap b/tests/string/__snapshots__/jsfmt.spec.mjs.snap index edef47687..a166868aa 100644 --- a/tests/string/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/string/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`multiline.php 1`] = ` ====================================options===================================== @@ -308,7 +308,7 @@ $string = "This is the value of the var named by the return value of getName(): $string = "This is the value of the var named by the return value of getName(): {\${getName( $arg1, $arg2, - $arg3 + $arg3, )}}"; $string = "This is the value of the var named by the return value of \\$object->getName(): {\${$object->getName()}}"; $string = "I'd like an {\${beers::softdrink}}\\n"; diff --git a/tests/sys/__snapshots__/jsfmt.spec.mjs.snap b/tests/sys/__snapshots__/jsfmt.spec.mjs.snap index 25eefe8ec..6cbfb3562 100644 --- a/tests/sys/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/sys/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`sys.php 1`] = ` ====================================options===================================== @@ -40,12 +40,12 @@ echo "test echo"; echo $test, $other; $info = ["coffee", "brown", "caffeine"]; -list($drink, $color, $power) = $info; -list( +[$drink, $color, $power] = $info; +[ $reallyReallyReallyReallyLongName, $otherReallyReallyReallyLongName, $lastOne, -) = $info; +] = $info; print "test print"; print "parens test"; @@ -68,7 +68,7 @@ isset( $test, $test, $test, - $test + $test, ); isset($test["foo"]); diff --git a/tests/trailing_commas/__snapshots__/jsfmt.spec.mjs.snap b/tests/trailing_commas/__snapshots__/jsfmt.spec.mjs.snap index 6650f4f14..c570a1a63 100644 --- a/tests/trailing_commas/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/trailing_commas/__snapshots__/jsfmt.spec.mjs.snap @@ -1,8 +1,9 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`array.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "7.0" printWidth: 80 | printWidth =====================================input====================================== @@ -1753,6 +1754,7 @@ $expected = [ exports[`array.php 5`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "7.0" printWidth: 80 trailingComma: "all" trailingCommaPHP: false @@ -2179,6 +2181,7 @@ EOT exports[`call.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "7.0" printWidth: 80 | printWidth =====================================input====================================== @@ -3359,6 +3362,7 @@ $sel = $this->connections exports[`call.php 5`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "7.0" printWidth: 80 trailingComma: "all" trailingCommaPHP: false @@ -3654,6 +3658,7 @@ $sel = $this->connections exports[`isset.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "7.0" printWidth: 80 | printWidth =====================================input====================================== @@ -3756,6 +3761,7 @@ var_dump( exports[`isset.php 5`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "7.0" printWidth: 80 trailingComma: "all" trailingCommaPHP: false @@ -3782,6 +3788,7 @@ var_dump( exports[`list.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "7.0" printWidth: 80 | printWidth =====================================input====================================== @@ -4180,6 +4187,7 @@ list(,,,0 => $firstVeryVeryVeryVeryLong,,, 1 => $secondVeryVeryVeryVeryLong,,, 2 exports[`list.php 5`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "7.0" printWidth: 80 trailingComma: "all" trailingCommaPHP: false @@ -4280,6 +4288,7 @@ list( exports[`unset.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "7.0" printWidth: 80 | printWidth =====================================input====================================== @@ -4378,6 +4387,7 @@ unset( exports[`unset.php 5`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "7.0" printWidth: 80 trailingComma: "all" trailingCommaPHP: false @@ -4403,6 +4413,7 @@ unset( exports[`use.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "7.0" printWidth: 80 | printWidth =====================================input====================================== @@ -4609,6 +4620,7 @@ use other_foo\\bar\\{ exports[`use.php 5`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "7.0" printWidth: 80 trailingComma: "all" trailingCommaPHP: false diff --git a/tests/trailing_commas/jsfmt.spec.mjs b/tests/trailing_commas/jsfmt.spec.mjs index 695bbbc83..a9c95d350 100644 --- a/tests/trailing_commas/jsfmt.spec.mjs +++ b/tests/trailing_commas/jsfmt.spec.mjs @@ -1,8 +1,9 @@ -run_spec(import.meta, ["php"]); +run_spec(import.meta, ["php"], { phpVersion: "7.0" }); run_spec(import.meta, ["php"], { trailingCommaPHP: true, phpVersion: "5.0" }); run_spec(import.meta, ["php"], { trailingCommaPHP: true, phpVersion: "7.2" }); run_spec(import.meta, ["php"], { trailingCommaPHP: true, phpVersion: "7.3" }); run_spec(import.meta, ["php"], { trailingCommaPHP: false, + phpVersion: "7.0", trailingComma: "all", }); diff --git a/tests/unset/__snapshots__/jsfmt.spec.mjs.snap b/tests/unset/__snapshots__/jsfmt.spec.mjs.snap index 949971bb3..3384bb48a 100644 --- a/tests/unset/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/unset/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`unset.php 1`] = ` ====================================options===================================== @@ -22,14 +22,14 @@ unset($veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryL a->b); unset( $veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongVariable ->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty - ->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty + ->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty, ); ================================================================================ diff --git a/tests/use/__snapshots__/jsfmt.spec.mjs.snap b/tests/use/__snapshots__/jsfmt.spec.mjs.snap index f3b09702d..dca64bca2 100644 --- a/tests/use/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/use/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`use.php 1`] = ` ====================================options===================================== @@ -64,7 +64,7 @@ use Vendor\\Package\\SomeNamespace\\{ SubnamespaceOne\\ClassA, SubnamespaceOne\\ClassB, SubnamespaceTwo\\ClassY, - ClassZ + ClassZ, }; use Mizo\\Web\\{ Php\\WebSite, @@ -74,7 +74,7 @@ use Mizo\\Web\\{ function JS\\printTotal, function JS\\printList, const JS\\BUAIKUM, - const JS\\MAUTAM + const JS\\MAUTAM, }; use Illuminate\\Foundation\\Bootstrap\\BootProviders; use function some\\Full\\fn_a; diff --git a/tests/variadic/__snapshots__/jsfmt.spec.mjs.snap b/tests/variadic/__snapshots__/jsfmt.spec.mjs.snap index 4f7205633..64025ce9f 100644 --- a/tests/variadic/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/variadic/__snapshots__/jsfmt.spec.mjs.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP +// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing exports[`variadic.php 1`] = ` ====================================options===================================== @@ -41,7 +41,7 @@ function f($req, $opt = null, ...$params) '$req: %d; $opt: %d; number of params: %d' . "\\n", $req, $opt, - count($params) + count($params), ); } From 4e03484949fa69a149c98170bc0fbcbf961c0bd8 Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Thu, 10 Jul 2025 22:56:00 +1000 Subject: [PATCH 02/17] added composer version detection --- src/options.mjs | 57 ++++- .../composer-version.spec.mjs | 208 ++++++++++++++++++ 2 files changed, 264 insertions(+), 1 deletion(-) create mode 100644 tests/composer-version/composer-version.spec.mjs diff --git a/src/options.mjs b/src/options.mjs index e28876ca5..58006fd47 100644 --- a/src/options.mjs +++ b/src/options.mjs @@ -1,11 +1,66 @@ +import fs from "fs"; +import path from "path"; + const CATEGORY_PHP = "PHP"; +/** + * Detect minimum PHP version from the composer.json file + * @param def {string} Default PHP version to use if not found + * @return {string} The PHP version to use in the composer.json file. + */ +function getComposerPhpVer(def) { + // Try to find composer.json + const currentDir = process.cwd(); + let composerPath = null; + + const directComposerPath = path.join(currentDir, "composer.json"); + if (fs.existsSync(directComposerPath)) { + composerPath = directComposerPath; + } + + if (!composerPath) { + let searchDir = path.dirname(currentDir); + while (searchDir !== path.parse(searchDir).root) { + const potentialComposerPath = path.join(searchDir, "composer.json"); + if (fs.existsSync(potentialComposerPath)) { + composerPath = potentialComposerPath; + break; + } + searchDir = path.dirname(searchDir); + } + } + + if (composerPath) { + try { + const fileContent = fs.readFileSync(composerPath, "utf8"); + const composerJson = JSON.parse(fileContent); + + if (composerJson.require && composerJson.require.php) { + // Extract version from composer semver format + const versionMatch = composerJson.require.php.match( + /^(?:[^0-9]*)?([0-9]+)\.([0-9]+)/ + ); + + if (versionMatch) { + return `${versionMatch[1]}.${versionMatch[2]}`; + } + } + } catch (error) { + return def; + } + } + + return def; +} + +export { getComposerPhpVer }; + export default { phpVersion: { since: "0.13.0", category: CATEGORY_PHP, type: "choice", - default: "8.3", + default: getComposerPhpVer("8.3"), description: "Minimum target PHP version.", choices: [ { value: "5.0" }, diff --git a/tests/composer-version/composer-version.spec.mjs b/tests/composer-version/composer-version.spec.mjs new file mode 100644 index 000000000..e2cfa97d9 --- /dev/null +++ b/tests/composer-version/composer-version.spec.mjs @@ -0,0 +1,208 @@ +import { getComposerPhpVer } from "../../src/options.mjs"; +import fs from "fs"; +import path from "path"; +import os from "os"; + +describe("getComposerPhpVer", () => { + // Create a unique temporary directory for our tests + const tempDir = path.join(os.tmpdir(), `composer-version-test-${Date.now()}`); + const tempComposerPath = path.join(tempDir, "composer.json"); + const originalCwd = process.cwd(); + + beforeEach(() => { + // Create temp directory if it doesn't exist + if (!fs.existsSync(tempDir)) { + fs.mkdirSync(tempDir, { recursive: true }); + } + }); + + afterEach(() => { + process.chdir(originalCwd); + + // Clean up temp files and directories + if (fs.existsSync(tempComposerPath)) { + fs.unlinkSync(tempComposerPath); + } + + // Remove any nested directories we created + if (fs.existsSync(tempDir)) { + const deleteFolderRecursive = function(dirPath) { + if (fs.existsSync(dirPath)) { + fs.readdirSync(dirPath).forEach((file) => { + const curPath = path.join(dirPath, file); + if (fs.lstatSync(curPath).isDirectory()) { + deleteFolderRecursive(curPath); + } else { + fs.unlinkSync(curPath); + } + }); + fs.rmdirSync(dirPath); + } + }; + + deleteFolderRecursive(tempDir); + } + }); + + test("returns default value when no composer.json is found", () => { + // Create a directory with no composer.json + const emptyDir = path.join(tempDir, "empty-dir"); + fs.mkdirSync(emptyDir, { recursive: true }); + + process.chdir(emptyDir); + + const defaultVersion = "7.4"; + expect(getComposerPhpVer(defaultVersion)).toBe(defaultVersion); + }); + + test.each([ + [">=7.1.0", "7.1"], + ["^8.0", "8.0"], + ["~7.4", "7.4"], + [">=5.6.0 <8.0.0", "5.6"], + ["7.3.*", "7.3"] + ])("extracts correct version from %s", (versionConstraint, expectedVersion) => { + const composerContent = JSON.stringify( + { + require: { + php: versionConstraint, + }, + }, + null, + 2 + ); + + fs.writeFileSync(tempComposerPath, composerContent); + + process.chdir(tempDir); + + // Call getComposerPhpVer to test version extraction + const result = getComposerPhpVer("default"); + expect(result).toBe(expectedVersion); + }); + + test.each([ + [">=7.1.0", "7.1"], + ["^8.0", "8.0"], + ["~7.4", "7.4"], + [">=5.6.0 <8.0.0", "5.6"], + ["7.3.*", "7.3"] + ])("extracts correct version from %s by changing cwd", (versionConstraint, expectedVersion) => { + const composerContent = JSON.stringify( + { + require: { + php: versionConstraint, + }, + }, + null, + 2 + ); + + fs.writeFileSync(tempComposerPath, composerContent); + + process.chdir(tempDir); + + const result = getComposerPhpVer("default"); + expect(result).toBe(expectedVersion); + }); + + test("returns default when composer.json has no PHP requirement", () => { + const composerContent = JSON.stringify( + { + require: { + // No PHP requirement + "some/package": "^1.0" + }, + }, + null, + 2 + ); + + fs.writeFileSync(tempComposerPath, composerContent); + + process.chdir(tempDir); + + const defaultVersion = "8.3"; + const result = getComposerPhpVer(defaultVersion); + expect(result).toBe(defaultVersion); + }); + + test("returns default when composer.json has invalid PHP requirement", () => { + const composerContent = JSON.stringify( + { + require: { + php: "invalid-version" + }, + }, + null, + 2 + ); + + fs.writeFileSync(tempComposerPath, composerContent); + + process.chdir(tempDir); + + const defaultVersion = "8.3"; + const result = getComposerPhpVer(defaultVersion); + expect(result).toBe(defaultVersion); + }); + + test("finds composer.json in parent directory when in nested child folder", () => { + // Create a nested directory structure + const nestedDir1 = path.join(tempDir, "level1"); + const nestedDir2 = path.join(nestedDir1, "level2"); + const nestedDir3 = path.join(nestedDir2, "level3"); + + fs.mkdirSync(nestedDir1, { recursive: true }); + fs.mkdirSync(nestedDir2, { recursive: true }); + fs.mkdirSync(nestedDir3, { recursive: true }); + + // Create composer.json in the root temp directory + const composerContent = JSON.stringify( + { + require: { + php: "^8.1" + }, + }, + null, + 2 + ); + + fs.writeFileSync(tempComposerPath, composerContent); + + process.chdir(nestedDir3); + + const result = getComposerPhpVer("default"); + expect(result).toBe("8.1"); + }); + + test("finds composer.json in intermediate parent directory", () => { + // Create a nested directory structure + const nestedDir1 = path.join(tempDir, "folder1"); + const nestedDir2 = path.join(nestedDir1, "folder2"); + const nestedDir3 = path.join(nestedDir2, "folder3"); + + fs.mkdirSync(nestedDir1, { recursive: true }); + fs.mkdirSync(nestedDir2, { recursive: true }); + fs.mkdirSync(nestedDir3, { recursive: true }); + + // Create composer.json in the middle level directory + const intermediateComposerPath = path.join(nestedDir2, "composer.json"); + const composerContent = JSON.stringify( + { + require: { + php: "~7.2" + }, + }, + null, + 2 + ); + + fs.writeFileSync(intermediateComposerPath, composerContent); + + process.chdir(nestedDir3); + + const result = getComposerPhpVer("default"); + expect(result).toBe("7.2"); + }); +}); From 9d9ed019e7fc366c34ab285984c256c979df1edc Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Fri, 11 Jul 2025 10:32:47 +1000 Subject: [PATCH 03/17] run all spec.mjs test files, not just jsfmt, remove __tests__ dir as not used --- jest.config.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jest.config.mjs b/jest.config.mjs index 41902fa1a..0170dafb7 100644 --- a/jest.config.mjs +++ b/jest.config.mjs @@ -14,7 +14,7 @@ export default { transform: {}, setupFiles: ["/tests_config/run_spec.mjs"], // Matches `.js` file to prevent files use `.js` extension by mistake, https://github.com/prettier/plugin-php/pull/2247#discussion_r1331847801 - testRegex: "jsfmt\\.spec\\.m?js$|__tests__/.*\\.m?js$", + testRegex: ".*\\.spec\\.m?js$", snapshotSerializers: ["jest-snapshot-serializer-raw"], globals: { STANDALONE: RUN_STANDALONE_TESTS, From 794f4550d500845c4bf1c80b6f48d4a4b82cd388 Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Fri, 11 Jul 2025 10:34:09 +1000 Subject: [PATCH 04/17] changed return to null and improved test coverage - added wildcard major versions - updated test for null return - added invalid json test case --- src/options.mjs | 23 +++-- .../composer-version.spec.mjs | 86 ++++++++----------- 2 files changed, 51 insertions(+), 58 deletions(-) diff --git a/src/options.mjs b/src/options.mjs index 58006fd47..fcf9d15e2 100644 --- a/src/options.mjs +++ b/src/options.mjs @@ -4,11 +4,10 @@ import path from "path"; const CATEGORY_PHP = "PHP"; /** - * Detect minimum PHP version from the composer.json file - * @param def {string} Default PHP version to use if not found - * @return {string} The PHP version to use in the composer.json file. + * Detect the minimum PHP version from the composer.json file + * @return {string|null} The PHP version to use in the composer.json file, null when not found */ -function getComposerPhpVer(def) { +function getComposerPhpVer() { // Try to find composer.json const currentDir = process.cwd(); let composerPath = null; @@ -36,6 +35,14 @@ function getComposerPhpVer(def) { const composerJson = JSON.parse(fileContent); if (composerJson.require && composerJson.require.php) { + // Check for wildcard pattern like "7.*" + const wildcardMatch = composerJson.require.php.match( + /^(?:[^0-9]*)?([0-9]+)\.\*/ + ); + if (wildcardMatch) { + return `${wildcardMatch[1]}.0`; + } + // Extract version from composer semver format const versionMatch = composerJson.require.php.match( /^(?:[^0-9]*)?([0-9]+)\.([0-9]+)/ @@ -45,12 +52,12 @@ function getComposerPhpVer(def) { return `${versionMatch[1]}.${versionMatch[2]}`; } } - } catch (error) { - return def; + } catch (e) { + // Ignore JSON parsing errors } } - return def; + return null; } export { getComposerPhpVer }; @@ -60,7 +67,7 @@ export default { since: "0.13.0", category: CATEGORY_PHP, type: "choice", - default: getComposerPhpVer("8.3"), + default: getComposerPhpVer() ?? "8.3", description: "Minimum target PHP version.", choices: [ { value: "5.0" }, diff --git a/tests/composer-version/composer-version.spec.mjs b/tests/composer-version/composer-version.spec.mjs index e2cfa97d9..19661755c 100644 --- a/tests/composer-version/composer-version.spec.mjs +++ b/tests/composer-version/composer-version.spec.mjs @@ -44,69 +44,42 @@ describe("getComposerPhpVer", () => { } }); - test("returns default value when no composer.json is found", () => { + test("returns null when no composer.json is found", () => { // Create a directory with no composer.json const emptyDir = path.join(tempDir, "empty-dir"); fs.mkdirSync(emptyDir, { recursive: true }); process.chdir(emptyDir); - const defaultVersion = "7.4"; - expect(getComposerPhpVer(defaultVersion)).toBe(defaultVersion); + expect(getComposerPhpVer()).toBe(null); }); test.each([ - [">=7.1.0", "7.1"], - ["^8.0", "8.0"], - ["~7.4", "7.4"], - [">=5.6.0 <8.0.0", "5.6"], - ["7.3.*", "7.3"] - ])("extracts correct version from %s", (versionConstraint, expectedVersion) => { + {ver:">=7.1.0",expected: "7.1"}, + {ver:"^8.0",expected: "8.0"}, + {ver:"~7.4",expected: "7.4"}, + {ver:">=5.6.0 <8.0.0",expected: "5.6"}, + {ver:"7.3.*",expected: "7.3"}, + {ver:"7.* || 8.*",expected: "7.0"} + ])("extracts correct version from $ver ba changing cwd", ({ver, expected}) => { const composerContent = JSON.stringify( { require: { - php: versionConstraint, + php: ver, }, }, null, 2 ); - fs.writeFileSync(tempComposerPath, composerContent); - process.chdir(tempDir); - - // Call getComposerPhpVer to test version extraction - const result = getComposerPhpVer("default"); - expect(result).toBe(expectedVersion); - }); - - test.each([ - [">=7.1.0", "7.1"], - ["^8.0", "8.0"], - ["~7.4", "7.4"], - [">=5.6.0 <8.0.0", "5.6"], - ["7.3.*", "7.3"] - ])("extracts correct version from %s by changing cwd", (versionConstraint, expectedVersion) => { - const composerContent = JSON.stringify( - { - require: { - php: versionConstraint, - }, - }, - null, - 2 - ); - fs.writeFileSync(tempComposerPath, composerContent); - process.chdir(tempDir); - const result = getComposerPhpVer("default"); - expect(result).toBe(expectedVersion); + expect(getComposerPhpVer()).toBe(expected); }); - test("returns default when composer.json has no PHP requirement", () => { + test("returns null when composer.json has no PHP requirement", () => { const composerContent = JSON.stringify( { require: { @@ -122,12 +95,10 @@ describe("getComposerPhpVer", () => { process.chdir(tempDir); - const defaultVersion = "8.3"; - const result = getComposerPhpVer(defaultVersion); - expect(result).toBe(defaultVersion); + expect(getComposerPhpVer()).toBe(null); }); - test("returns default when composer.json has invalid PHP requirement", () => { + test("returns null when composer.json has invalid PHP requirement", () => { const composerContent = JSON.stringify( { require: { @@ -142,9 +113,7 @@ describe("getComposerPhpVer", () => { process.chdir(tempDir); - const defaultVersion = "8.3"; - const result = getComposerPhpVer(defaultVersion); - expect(result).toBe(defaultVersion); + expect(getComposerPhpVer()).toBe(null); }); test("finds composer.json in parent directory when in nested child folder", () => { @@ -172,8 +141,7 @@ describe("getComposerPhpVer", () => { process.chdir(nestedDir3); - const result = getComposerPhpVer("default"); - expect(result).toBe("8.1"); + expect(getComposerPhpVer()).toBe("8.1"); }); test("finds composer.json in intermediate parent directory", () => { @@ -202,7 +170,25 @@ describe("getComposerPhpVer", () => { process.chdir(nestedDir3); - const result = getComposerPhpVer("default"); - expect(result).toBe("7.2"); + expect(getComposerPhpVer()).toBe("7.2"); + }); + + test("returns null when composer.json is malformed", () => { + // Create a malformed JSON file (invalid syntax) + const malformedContent = `{ + "name": "test/package", + "require": { + "php": "^7.4" + }, // Invalid trailing comma + "extra": { + "key": "value" + } + }`; + + fs.writeFileSync(tempComposerPath, malformedContent); + + process.chdir(tempDir); + + expect(getComposerPhpVer()).toBe(null); }); }); From 500a1c8afe64c973ed7f40e4b258510c944cda95 Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Fri, 11 Jul 2025 10:43:41 +1000 Subject: [PATCH 05/17] refactor: renamed getComposerPhpVersion func to match config naming more closely --- src/options.mjs | 6 +++--- tests/composer-version/composer-version.spec.mjs | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/options.mjs b/src/options.mjs index fcf9d15e2..12d67139c 100644 --- a/src/options.mjs +++ b/src/options.mjs @@ -7,7 +7,7 @@ const CATEGORY_PHP = "PHP"; * Detect the minimum PHP version from the composer.json file * @return {string|null} The PHP version to use in the composer.json file, null when not found */ -function getComposerPhpVer() { +function getComposerPhpVersion() { // Try to find composer.json const currentDir = process.cwd(); let composerPath = null; @@ -60,14 +60,14 @@ function getComposerPhpVer() { return null; } -export { getComposerPhpVer }; +export { getComposerPhpVersion }; export default { phpVersion: { since: "0.13.0", category: CATEGORY_PHP, type: "choice", - default: getComposerPhpVer() ?? "8.3", + default: getComposerPhpVersion() ?? "8.3", description: "Minimum target PHP version.", choices: [ { value: "5.0" }, diff --git a/tests/composer-version/composer-version.spec.mjs b/tests/composer-version/composer-version.spec.mjs index 19661755c..f134e8b05 100644 --- a/tests/composer-version/composer-version.spec.mjs +++ b/tests/composer-version/composer-version.spec.mjs @@ -1,4 +1,4 @@ -import { getComposerPhpVer } from "../../src/options.mjs"; +import { getComposerPhpVersion } from "../../src/options.mjs"; import fs from "fs"; import path from "path"; import os from "os"; @@ -51,7 +51,7 @@ describe("getComposerPhpVer", () => { process.chdir(emptyDir); - expect(getComposerPhpVer()).toBe(null); + expect(getComposerPhpVersion()).toBe(null); }); test.each([ @@ -76,7 +76,7 @@ describe("getComposerPhpVer", () => { fs.writeFileSync(tempComposerPath, composerContent); - expect(getComposerPhpVer()).toBe(expected); + expect(getComposerPhpVersion()).toBe(expected); }); test("returns null when composer.json has no PHP requirement", () => { @@ -95,7 +95,7 @@ describe("getComposerPhpVer", () => { process.chdir(tempDir); - expect(getComposerPhpVer()).toBe(null); + expect(getComposerPhpVersion()).toBe(null); }); test("returns null when composer.json has invalid PHP requirement", () => { @@ -113,7 +113,7 @@ describe("getComposerPhpVer", () => { process.chdir(tempDir); - expect(getComposerPhpVer()).toBe(null); + expect(getComposerPhpVersion()).toBe(null); }); test("finds composer.json in parent directory when in nested child folder", () => { @@ -141,7 +141,7 @@ describe("getComposerPhpVer", () => { process.chdir(nestedDir3); - expect(getComposerPhpVer()).toBe("8.1"); + expect(getComposerPhpVersion()).toBe("8.1"); }); test("finds composer.json in intermediate parent directory", () => { @@ -170,7 +170,7 @@ describe("getComposerPhpVer", () => { process.chdir(nestedDir3); - expect(getComposerPhpVer()).toBe("7.2"); + expect(getComposerPhpVersion()).toBe("7.2"); }); test("returns null when composer.json is malformed", () => { @@ -189,6 +189,6 @@ describe("getComposerPhpVer", () => { process.chdir(tempDir); - expect(getComposerPhpVer()).toBe(null); + expect(getComposerPhpVersion()).toBe(null); }); }); From 2d8a55a787294a6a81fec63e8619a26d1b71b27f Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Mon, 14 Jul 2025 11:26:51 +1000 Subject: [PATCH 06/17] documentation updaste for PHP default version changes --- README.md | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e33bb4b03..51d149a19 100644 --- a/README.md +++ b/README.md @@ -176,17 +176,27 @@ await prettier.format(YOUR_CODE, { Prettier for PHP supports the following options. We recommend that all users set the `phpVersion` option. -| Name | Default | Description | -| ------------------ | ---------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `phpVersion` | `"7.0"` | Allows specifying the PHP version you're using. If you're using PHP 7.1 or later, setting this option will make use of modern language features in the printed output. If you're using PHP lower than 7.0, you'll have to set this option or Prettier will generate incompatible code. | -| `printWidth` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)) | -| `tabWidth` | `4` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)), The default is `4` based on the `PSR-2` coding standard. | -| `useTabs` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tabs)) | -| `singleQuote` | `false` | If set to `"true"`, strings that use double quotes but do not rely on the features they add, will be reformatted. Example: `"foo" -> 'foo'`, `"foo $bar" -> "foo $bar"`. | -| `trailingCommaPHP` | `true` | If set to `true`, trailing commas will be added wherever possible.
If set to `false`, no trailing commas are printed. | -| `braceStyle` | `"per-cs"` | If set to `"per-cs"`, prettier will move open brace for code blocks (classes, functions and methods) onto new line.
If set to `"1tbs"`, prettier will move open brace for code blocks (classes, functions and methods) onto same line. | -| `requirePragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)) | -| `insertPragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#insert-pragma)) | +| Name | Default | Description | +| ------------------ |------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `phpVersion` | `"8.3"` * | Allows specifying the PHP version you're using. (See Notes Below) | +| `printWidth` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)) | +| `tabWidth` | `4` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)), The default is `4` based on the `PSR-2` coding standard. | +| `useTabs` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tabs)) | +| `singleQuote` | `false` | If set to `"true"`, strings that use double quotes but do not rely on the features they add, will be reformatted. Example: `"foo" -> 'foo'`, `"foo $bar" -> "foo $bar"`. | +| `trailingCommaPHP` | `true` | If set to `true`, trailing commas will be added wherever possible.
If set to `false`, no trailing commas are printed. | +| `braceStyle` | `"per-cs"` | If set to `"per-cs"`, prettier will move open brace for code blocks (classes, functions and methods) onto new line.
If set to `"1tbs"`, prettier will move open brace for code blocks (classes, functions and methods) onto same line. | +| `requirePragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)) | +| `insertPragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#insert-pragma)) | + +### `phpVersion` Configuration Notes: + +This setting now defaults to PHP 8.3, however, if the code you are formatting has a `composer.json` with in the current +directory or any parent directory, the plugin will use minimum supported php version from `{"require":{"php":"..."}}` +to set the phpVersion. If no such value is found, it will default to PHP 8.3. + +If the phpVersion is not set correctly for your environment, this plugin will product code that could be incompatible +with your PHP runtime. For example, if you are using PHP 7.4, but the plugin is set to PHP 8.3, it will produce code +that uses features not available in PHP 7.4. ## Ignoring code From dd290b76588dfb597813f4882010513691e97d69 Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Mon, 14 Jul 2025 16:18:23 +1000 Subject: [PATCH 07/17] reformat: ran prettier on README --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 51d149a19..d2cece55a 100644 --- a/README.md +++ b/README.md @@ -177,8 +177,8 @@ await prettier.format(YOUR_CODE, { Prettier for PHP supports the following options. We recommend that all users set the `phpVersion` option. | Name | Default | Description | -| ------------------ |------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| `phpVersion` | `"8.3"` * | Allows specifying the PHP version you're using. (See Notes Below) | +| ------------------ | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `phpVersion` | `"8.3"` \* | Allows specifying the PHP version you're using. (See Notes Below) | | `printWidth` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)) | | `tabWidth` | `4` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)), The default is `4` based on the `PSR-2` coding standard. | | `useTabs` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tabs)) | @@ -191,11 +191,11 @@ Prettier for PHP supports the following options. We recommend that all users set ### `phpVersion` Configuration Notes: This setting now defaults to PHP 8.3, however, if the code you are formatting has a `composer.json` with in the current -directory or any parent directory, the plugin will use minimum supported php version from `{"require":{"php":"..."}}` +directory or any parent directory, the plugin will use minimum supported php version from `{"require":{"php":"..."}}` to set the phpVersion. If no such value is found, it will default to PHP 8.3. -If the phpVersion is not set correctly for your environment, this plugin will product code that could be incompatible -with your PHP runtime. For example, if you are using PHP 7.4, but the plugin is set to PHP 8.3, it will produce code +If the phpVersion is not set correctly for your environment, this plugin will product code that could be incompatible +with your PHP runtime. For example, if you are using PHP 7.4, but the plugin is set to PHP 8.3, it will produce code that uses features not available in PHP 7.4. ## Ignoring code From c73758d490537c69cf5efdeb4545ebed755c82aa Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Tue, 15 Jul 2025 12:14:22 +1000 Subject: [PATCH 08/17] set default phpVersion to auto and added composer setting --- README.md | 47 ++++++++++--------- src/options.mjs | 43 ++++++++++++++++- src/parser.mjs | 2 + .../composer-version.spec.mjs | 31 +++++++++++- 4 files changed, 99 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index d2cece55a..09dd6cff9 100644 --- a/README.md +++ b/README.md @@ -176,27 +176,32 @@ await prettier.format(YOUR_CODE, { Prettier for PHP supports the following options. We recommend that all users set the `phpVersion` option. -| Name | Default | Description | -| ------------------ | ---------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `phpVersion` | `"8.3"` \* | Allows specifying the PHP version you're using. (See Notes Below) | -| `printWidth` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)) | -| `tabWidth` | `4` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)), The default is `4` based on the `PSR-2` coding standard. | -| `useTabs` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tabs)) | -| `singleQuote` | `false` | If set to `"true"`, strings that use double quotes but do not rely on the features they add, will be reformatted. Example: `"foo" -> 'foo'`, `"foo $bar" -> "foo $bar"`. | -| `trailingCommaPHP` | `true` | If set to `true`, trailing commas will be added wherever possible.
If set to `false`, no trailing commas are printed. | -| `braceStyle` | `"per-cs"` | If set to `"per-cs"`, prettier will move open brace for code blocks (classes, functions and methods) onto new line.
If set to `"1tbs"`, prettier will move open brace for code blocks (classes, functions and methods) onto same line. | -| `requirePragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)) | -| `insertPragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#insert-pragma)) | - -### `phpVersion` Configuration Notes: - -This setting now defaults to PHP 8.3, however, if the code you are formatting has a `composer.json` with in the current -directory or any parent directory, the plugin will use minimum supported php version from `{"require":{"php":"..."}}` -to set the phpVersion. If no such value is found, it will default to PHP 8.3. - -If the phpVersion is not set correctly for your environment, this plugin will product code that could be incompatible -with your PHP runtime. For example, if you are using PHP 7.4, but the plugin is set to PHP 8.3, it will produce code -that uses features not available in PHP 7.4. +| Name | Default | Description | +| ------------------ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| `phpVersion` | `"auto"` \* | Allows specifying the PHP version you're using. (See Notes Below) | +| `printWidth` | `80` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#print-width)) | +| `tabWidth` | `4` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tab-width)), The default is `4` based on the `PSR-2` coding standard. | +| `useTabs` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#tabs)) | +| `singleQuote` | `false` | If set to `"true"`, strings that use double quotes but do not rely on the features they add, will be reformatted. Example: `"foo" -> 'foo'`, `"foo $bar" -> "foo $bar"`. | +| `trailingCommaPHP` | `true` | If set to `true`, trailing commas will be added wherever possible.
If set to `false`, no trailing commas are printed. | +| `braceStyle` | `"per-cs"` | If set to `"per-cs"`, prettier will move open brace for code blocks (classes, functions and methods) onto new line.
If set to `"1tbs"`, prettier will move open brace for code blocks (classes, functions and methods) onto same line. | +| `requirePragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#require-pragma)) | +| `insertPragma` | `false` | Same as in Prettier ([see prettier docs](https://prettier.io/docs/en/options.html#insert-pragma)) | + +### \* `phpVersion` Configuration Notes : + +The default setting `auto`, attempts to auto-detect your supported php versions from a `composer.json` with in the +current directory or any parent directory, the plugin will use minimum supported php version from `{"require":{"php":"..."}}` +to set the phpVersion. If not found, or not able to be parsed, it will default to PHP 8.3. + +You set the `phpVersion` to `composer` and this will only use the `composer.json` file to determine the php +version, prettier will crash if the PHP cannot be determined. + +You can also set the `phpVersion` to a specific version, such as `7.4`, `8.0`, `8.1`, `8.2`, or `8.3`. + +**Please Note:** If the phpVersion is not set correctly for your environment, this plugin will product code that could +be incompatible with your PHP runtime. For example, if you are using PHP 7.4, but the plugin is set to PHP 8.3, it will +produce code that uses features not available in PHP 7.4. ## Ignoring code diff --git a/src/options.mjs b/src/options.mjs index 12d67139c..76cfb14c3 100644 --- a/src/options.mjs +++ b/src/options.mjs @@ -3,6 +3,10 @@ import path from "path"; const CATEGORY_PHP = "PHP"; +const LATEST_PHP_VERSION = "8.3"; + +let getComposerError = ""; + /** * Detect the minimum PHP version from the composer.json file * @return {string|null} The PHP version to use in the composer.json file, null when not found @@ -50,11 +54,16 @@ function getComposerPhpVersion() { if (versionMatch) { return `${versionMatch[1]}.${versionMatch[2]}`; + } else { + getComposerError = `Could not decode PHP version (${composerJson.require.php}})`; + return null; } } } catch (e) { - // Ignore JSON parsing errors + getComposerError = `Error reading composer.json: ${e.message}`; } + } else { + getComposerError = "Could not find composer.json"; } return null; @@ -62,12 +71,34 @@ function getComposerPhpVersion() { export { getComposerPhpVersion }; +/** + * Resolve the PHP version based on the provided options. + * + */ +export function resolvePhpVersion(options) { + if (!options) { + return; + } + if (options.phpVersion === "auto") { + options.phpVersion = getComposerPhpVersion() ?? LATEST_PHP_VERSION; + } else if (options.phpVersion === "composer") { + const v = getComposerPhpVersion(); + if (v === null) { + throw new Error( + `Could not determine PHP version from composer; ${getComposerError}` + ); + } else { + options.phpVersion = v; + } + } +} + export default { phpVersion: { since: "0.13.0", category: CATEGORY_PHP, type: "choice", - default: getComposerPhpVersion() ?? "8.3", + default: "auto", description: "Minimum target PHP version.", choices: [ { value: "5.0" }, @@ -87,6 +118,14 @@ export default { { value: "8.2" }, { value: "8.3" }, { value: "8.4" }, + { + value: "composer", + description: "Use the PHP version defined in composer.json", + }, + { + value: "auto", + description: `Try composer.json, latest PHP Version (${LATEST_PHP_VERSION})`, + }, ], }, trailingCommaPHP: { diff --git a/src/parser.mjs b/src/parser.mjs index 80b61bb45..71c7871a9 100644 --- a/src/parser.mjs +++ b/src/parser.mjs @@ -1,5 +1,6 @@ import engine from "php-parser"; import options from "./options.mjs"; +import { resolvePhpVersion } from "./options.mjs"; function parse(text, opts) { const inMarkdown = opts && opts.parentParser === "markdown"; @@ -7,6 +8,7 @@ function parse(text, opts) { if (!text && inMarkdown) { return ""; } + resolvePhpVersion(opts); // Todo https://github.com/glayzzle/php-parser/issues/170 text = text.replace(/\?>\n<\?/g, "?>\n___PSEUDO_INLINE_PLACEHOLDER___ { expect(getComposerPhpVersion()).toBe(expected); }); + test("phpVersion=composer reads composer.json", () => { + + const composerContent = JSON.stringify( + { + require: { + php: ">=5.4", + }, + }, + null, + 2 + ); + + process.chdir(tempDir); + fs.writeFileSync(tempComposerPath, composerContent); + + + const options = { phpVersion: "composer" }; + resolvePhpVersion(options); + expect(options.phpVersion).toBe("5.4"); + }) + test("returns null when composer.json has no PHP requirement", () => { const composerContent = JSON.stringify( { @@ -98,6 +119,14 @@ describe("getComposerPhpVer", () => { expect(getComposerPhpVersion()).toBe(null); }); + + test("returns error when no composer.json and phpVersion set to composer", () => { + + process.chdir(tempDir); + + expect(() =>resolvePhpVersion({phpVersion:"composer"})).toThrow(); + }); + test("returns null when composer.json has invalid PHP requirement", () => { const composerContent = JSON.stringify( { From d06ca637e9c6cbf13f57c1b448e1ee5e734ed319 Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Tue, 15 Jul 2025 12:50:09 +1000 Subject: [PATCH 09/17] refactored versions after rebasing - automatically use latest version - phpVersion is always a number now - moved isMinVersion to simple number comparison --- src/needs-parens.mjs | 9 ++------- src/options.mjs | 44 +++++++++++++++++++------------------------- src/parser.mjs | 8 ++------ src/printer.mjs | 35 ++++++++++++++++++----------------- src/util.mjs | 4 ---- 5 files changed, 41 insertions(+), 59 deletions(-) diff --git a/src/needs-parens.mjs b/src/needs-parens.mjs index 3f1be4adf..c234c8da7 100644 --- a/src/needs-parens.mjs +++ b/src/needs-parens.mjs @@ -1,9 +1,4 @@ -import { - getPrecedence, - shouldFlatten, - isBitwiseOperator, - isMinVersion, -} from "./util.mjs"; +import { getPrecedence, shouldFlatten, isBitwiseOperator } from "./util.mjs"; function needsParens(path, options) { const { parent } = path; @@ -135,7 +130,7 @@ function needsParens(path, options) { case "new": { const requiresParens = node.kind === "clone" || - (node.kind === "new" && !isMinVersion(options.phpVersion, "8.4")); + (node.kind === "new" && options.phpVersion < 8.4); switch (parent.kind) { case "propertylookup": case "nullsafepropertylookup": diff --git a/src/options.mjs b/src/options.mjs index 76cfb14c3..232129028 100644 --- a/src/options.mjs +++ b/src/options.mjs @@ -3,13 +3,20 @@ import path from "path"; const CATEGORY_PHP = "PHP"; -const LATEST_PHP_VERSION = "8.3"; +// prettier-ignore +const SUPPORTED_PHP_VERSIONS = [ + 5.0, 5.1, 5.2, 5.3, 5.4, 5.5, 5.6, + 7.0, 7.1, 7.2, 7.3, 7.4, + 8.0, 8.1, 8.2, 8.3, 8.4, +]; + +export const LATEST_SUPPORTED_PHP_VERSION = Math.max(...SUPPORTED_PHP_VERSIONS); let getComposerError = ""; /** * Detect the minimum PHP version from the composer.json file - * @return {string|null} The PHP version to use in the composer.json file, null when not found + * @return {number|null} The PHP version to use in the composer.json file, null when not found */ function getComposerPhpVersion() { // Try to find composer.json @@ -39,12 +46,12 @@ function getComposerPhpVersion() { const composerJson = JSON.parse(fileContent); if (composerJson.require && composerJson.require.php) { - // Check for wildcard pattern like "7.*" + // Check for a wildcard pattern like "7.*" const wildcardMatch = composerJson.require.php.match( /^(?:[^0-9]*)?([0-9]+)\.\*/ ); if (wildcardMatch) { - return `${wildcardMatch[1]}.0`; + return parseFloat(`${wildcardMatch[1]}.0`); } // Extract version from composer semver format @@ -53,7 +60,7 @@ function getComposerPhpVersion() { ); if (versionMatch) { - return `${versionMatch[1]}.${versionMatch[2]}`; + return parseFloat(`${versionMatch[1]}.${versionMatch[2]}`); } else { getComposerError = `Could not decode PHP version (${composerJson.require.php}})`; return null; @@ -72,7 +79,7 @@ function getComposerPhpVersion() { export { getComposerPhpVersion }; /** - * Resolve the PHP version based on the provided options. + * Resolve the PHP version to a number based on the provided options. * */ export function resolvePhpVersion(options) { @@ -80,7 +87,8 @@ export function resolvePhpVersion(options) { return; } if (options.phpVersion === "auto") { - options.phpVersion = getComposerPhpVersion() ?? LATEST_PHP_VERSION; + options.phpVersion = + getComposerPhpVersion() ?? LATEST_SUPPORTED_PHP_VERSION; } else if (options.phpVersion === "composer") { const v = getComposerPhpVersion(); if (v === null) { @@ -90,6 +98,8 @@ export function resolvePhpVersion(options) { } else { options.phpVersion = v; } + } else { + options.phpVersion = parseFloat(options.phpVersion); } } @@ -101,30 +111,14 @@ export default { default: "auto", description: "Minimum target PHP version.", choices: [ - { value: "5.0" }, - { value: "5.1" }, - { value: "5.2" }, - { value: "5.3" }, - { value: "5.4" }, - { value: "5.5" }, - { value: "5.6" }, - { value: "7.0" }, - { value: "7.1" }, - { value: "7.2" }, - { value: "7.3" }, - { value: "7.4" }, - { value: "8.0" }, - { value: "8.1" }, - { value: "8.2" }, - { value: "8.3" }, - { value: "8.4" }, + ...SUPPORTED_PHP_VERSIONS.map((v) => ({ value: v.toFixed(1) })), { value: "composer", description: "Use the PHP version defined in composer.json", }, { value: "auto", - description: `Try composer.json, latest PHP Version (${LATEST_PHP_VERSION})`, + description: `Try composer.json, else latest PHP Version (${LATEST_SUPPORTED_PHP_VERSION})`, }, ], }, diff --git a/src/parser.mjs b/src/parser.mjs index 71c7871a9..8df49870d 100644 --- a/src/parser.mjs +++ b/src/parser.mjs @@ -1,5 +1,5 @@ import engine from "php-parser"; -import options from "./options.mjs"; +import { LATEST_SUPPORTED_PHP_VERSION } from "./options.mjs"; import { resolvePhpVersion } from "./options.mjs"; function parse(text, opts) { @@ -13,15 +13,11 @@ function parse(text, opts) { // Todo https://github.com/glayzzle/php-parser/issues/170 text = text.replace(/\?>\n<\?/g, "?>\n___PSEUDO_INLINE_PLACEHOLDER___ parseFloat(c.value)) - ); - // initialize a new parser instance const parser = new engine({ parser: { extractDoc: true, - version: `${latestSupportedPhpVersion}`, + version: `${LATEST_SUPPORTED_PHP_VERSION}`, }, ast: { withPositions: true, diff --git a/src/printer.mjs b/src/printer.mjs index d8e21e832..c3cf11cd0 100644 --- a/src/printer.mjs +++ b/src/printer.mjs @@ -37,7 +37,6 @@ import { isReferenceLikeNode, normalizeMagicMethodName, isSimpleCallArgument, - isMinVersion, } from "./util.mjs"; const { @@ -66,12 +65,19 @@ const { isPreviousLineEmpty, } = prettierUtil; +/** + * Determine if we should print a trailing comma based on the config & php version + * + * @param options {object} Prettier Options + * @param requiredVersion {number} + * @returns {boolean} + */ function shouldPrintComma(options, requiredVersion) { if (!options.trailingCommaPHP) { return false; } - return isMinVersion(options.phpVersion, requiredVersion); + return options.phpVersion >= requiredVersion; } function shouldPrintHardlineForOpenBrace(options) { @@ -612,9 +618,9 @@ function printArgumentsList(path, options, print, argumentsKey = "arguments") { const lastArg = getLast(args); const maybeTrailingComma = - (shouldPrintComma(options, "7.3") && + (shouldPrintComma(options, 7.3) && ["call", "new", "unset", "isset"].includes(node.kind)) || - (shouldPrintComma(options, "8.0") && + (shouldPrintComma(options, 8.0) && ["function", "closure", "method", "arrowfunc", "attribute"].includes( node.kind )) @@ -1186,7 +1192,7 @@ function printAttrs(path, options, print, { inline = false } = {}) { allAttrs.push( group([ indent(attrGroup), - ifBreak(shouldPrintComma(options, "8.0") ? "," : ""), + ifBreak(shouldPrintComma(options, 8.0) ? "," : ""), softline, "]", inline ? ifBreak(softline, " ") : "", @@ -1658,11 +1664,7 @@ function printNode(path, options, print) { join([",", line], path.map(print, "items")), ]), node.name - ? [ - ifBreak(shouldPrintComma(options, "7.2") ? "," : ""), - softline, - "}", - ] + ? [ifBreak(shouldPrintComma(options, 7.2) ? "," : ""), softline, "}"] : "", ]); case "useitem": @@ -2356,9 +2358,8 @@ function printNode(path, options, print) { case "list": case "array": { const useShortForm = - (node.kind === "array" && isMinVersion(options.phpVersion, "5.4")) || - (node.kind === "list" && - (node.shortForm || isMinVersion(options.phpVersion, "7.1"))); + (node.kind === "array" && options.phpVersion >= 5.4) || + (node.kind === "list" && (node.shortForm || options.phpVersion >= 7.1)); const open = useShortForm ? "[" : [node.kind, "("]; const close = useShortForm ? "]" : ")"; @@ -2408,7 +2409,7 @@ function printNode(path, options, print) { indent([softline, printArrayItems(path, options, print)]), needsForcedTrailingComma ? "," : "", ifBreak( - !needsForcedTrailingComma && shouldPrintComma(options, "5.0") + !needsForcedTrailingComma && shouldPrintComma(options, 5.0) ? [ lastElem && shouldPrintHardlineBeforeTrailingComma(lastElem) ? hardline @@ -2675,7 +2676,7 @@ function printNode(path, options, print) { if (parent.kind === "encapsedpart") { const parentParent = path.grandparent; let closingTagIndentation = 0; - const flexible = isMinVersion(options.phpVersion, "7.3"); + const flexible = options.phpVersion >= 7.3; let linebreak = literalline; if (parentParent.type === "heredoc") { linebreak = flexible ? hardline : literalline; @@ -2744,7 +2745,7 @@ function printNode(path, options, print) { case "string": case "shell": case "heredoc": { - const flexible = isMinVersion(options.phpVersion, "7.3"); + const flexible = options.phpVersion >= 7.3; const linebreak = flexible ? hardline : literalline; return [ getEncapsedQuotes(node), @@ -2769,7 +2770,7 @@ function printNode(path, options, print) { case "magic": return node.value; case "nowdoc": { - const flexible = isMinVersion(options.phpVersion, "7.3"); + const flexible = options.phpVersion >= 7.3; const linebreak = flexible ? hardline : literalline; return [ "<<<'", diff --git a/src/util.mjs b/src/util.mjs index 03428ca48..d24ff44e7 100644 --- a/src/util.mjs +++ b/src/util.mjs @@ -709,9 +709,6 @@ function memoize(fn) { }; } -function isMinVersion(actualVersion, requiredVersion) { - return parseFloat(actualVersion) >= parseFloat(requiredVersion); -} export { printNumber, @@ -744,5 +741,4 @@ export { normalizeMagicMethodName, isSimpleCallArgument, memoize, - isMinVersion, }; From d798043ca3d6581ccc3fcc718dba12e3e27a5489 Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Tue, 15 Jul 2025 12:54:46 +1000 Subject: [PATCH 10/17] update versions to number --- .../composer-version/composer-version.spec.mjs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/composer-version/composer-version.spec.mjs b/tests/composer-version/composer-version.spec.mjs index 6d85ce257..59871b3c5 100644 --- a/tests/composer-version/composer-version.spec.mjs +++ b/tests/composer-version/composer-version.spec.mjs @@ -55,12 +55,12 @@ describe("getComposerPhpVer", () => { }); test.each([ - {ver:">=7.1.0",expected: "7.1"}, - {ver:"^8.0",expected: "8.0"}, - {ver:"~7.4",expected: "7.4"}, - {ver:">=5.6.0 <8.0.0",expected: "5.6"}, - {ver:"7.3.*",expected: "7.3"}, - {ver:"7.* || 8.*",expected: "7.0"} + {ver:">=7.1.0",expected: 7.1}, + {ver:"^8.0",expected: 8.0}, + {ver:"~7.4",expected: 7.4}, + {ver:">=5.6.0 <8.0.0",expected: 5.6}, + {ver:"7.3.*",expected: 7.3}, + {ver:"7.* || 8.*",expected: 7.0} ])("extracts correct version from $ver ba changing cwd", ({ver, expected}) => { const composerContent = JSON.stringify( { @@ -97,7 +97,7 @@ describe("getComposerPhpVer", () => { const options = { phpVersion: "composer" }; resolvePhpVersion(options); - expect(options.phpVersion).toBe("5.4"); + expect(options.phpVersion).toBe(5.4); }) test("returns null when composer.json has no PHP requirement", () => { @@ -170,7 +170,7 @@ describe("getComposerPhpVer", () => { process.chdir(nestedDir3); - expect(getComposerPhpVersion()).toBe("8.1"); + expect(getComposerPhpVersion()).toBe(8.1); }); test("finds composer.json in intermediate parent directory", () => { @@ -199,7 +199,7 @@ describe("getComposerPhpVer", () => { process.chdir(nestedDir3); - expect(getComposerPhpVersion()).toBe("7.2"); + expect(getComposerPhpVersion()).toBe(7.2); }); test("returns null when composer.json is malformed", () => { From e8b5ea8090a7087104cde8fe3a86db61f2db5570 Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Tue, 15 Jul 2025 13:03:51 +1000 Subject: [PATCH 11/17] snapshot changes after bumping default version to 8.4 --- .../assign/__snapshots__/jsfmt.spec.mjs.snap | 6 +- .../__snapshots__/jsfmt.spec.mjs.snap | 6 +- .../__snapshots__/jsfmt.spec.mjs.snap | 18 ++--- tests/new/__snapshots__/jsfmt.spec.mjs.snap | 2 +- tests/new/jsfmt.spec.mjs | 2 +- .../parens/__snapshots__/jsfmt.spec.mjs.snap | 66 +++++++++---------- tests/parens/jsfmt.spec.mjs | 2 +- .../__snapshots__/jsfmt.spec.mjs.snap | 2 +- 8 files changed, 52 insertions(+), 52 deletions(-) diff --git a/tests/assign/__snapshots__/jsfmt.spec.mjs.snap b/tests/assign/__snapshots__/jsfmt.spec.mjs.snap index b9d4aef69..78d9bd542 100644 --- a/tests/assign/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/assign/__snapshots__/jsfmt.spec.mjs.snap @@ -233,7 +233,7 @@ $veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongVariable = $veryVeryVeryVeryVer $obj->property = $obj->oneProperty = $obj->twoPeroperty = 0; $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = 0; $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = $obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = $veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongValue; -$obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = (new MyClass())->call( +$obj->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty->veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongProperty = new MyClass()->call( $arg, ); $obj->loooooooooooong->lookup = $this->getRequest()->getParam( @@ -251,7 +251,7 @@ $component = Foo::$insertReallyReallyReallyReallyReallyReallyReallyReallyLongName; $component = $a::$insertReallyReallyReallyReallyReallyReallyReallyReallyLongName; -$component = (new Foo()) +$component = new Foo() ->insertReallyReallyReallyReallyReallyReallyReallyReallyLongName; $component = (clone $a) ->insertReallyReallyReallyReallyReallyReallyReallyReallyLongName; @@ -266,7 +266,7 @@ $component = Foo::$insertReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongName; $component = $a::$insertReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongName; -$component = (new Foo()) +$component = new Foo() ->insertReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongName; $component = (clone $a) ->insertReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyReallyLongName; diff --git a/tests/comments/__snapshots__/jsfmt.spec.mjs.snap b/tests/comments/__snapshots__/jsfmt.spec.mjs.snap index bc5b490f0..2d311f8a6 100644 --- a/tests/comments/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/comments/__snapshots__/jsfmt.spec.mjs.snap @@ -6590,16 +6590,16 @@ $inspect = $condition $extractTextPluginOptions = $shouldUseRelativeAssetPaths ? // Making sure that the publicPath goes back to to build folder. - ["publicPath" => (new Foo($cssFilename->split("/")->length))->join("../")] + ["publicPath" => new Foo($cssFilename->split("/")->length)->join("../")] : []; $extractTextPluginOptions = $shouldUseRelativeAssetPaths ? // Making sure that the publicPath goes back to to build folder. - ["publicPath" => (new Foo($cssFilename->split("/")->length))->join("../")] + ["publicPath" => new Foo($cssFilename->split("/")->length)->join("../")] : []; $extractTextPluginOptions = $shouldUseRelativeAssetPaths // Making sure that the publicPath goes back to to build folder. - ? ["publicPath" => (new Foo($cssFilename->split("/")->length))->join("../")] + ? ["publicPath" => new Foo($cssFilename->split("/")->length)->join("../")] : []; $var = diff --git a/tests/member_chain/__snapshots__/jsfmt.spec.mjs.snap b/tests/member_chain/__snapshots__/jsfmt.spec.mjs.snap index 548a8e419..4d8631650 100644 --- a/tests/member_chain/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/member_chain/__snapshots__/jsfmt.spec.mjs.snap @@ -87,10 +87,10 @@ $superSupersuperSupersuperSupersuperSupersuperSuperLong->{$exampleOfOrderOfGette $superSupersuperSupersuperSupersuperSupersuperSuperLong::$exampleOfOrderOfGetterAndSetterReordered; $superSupersuperSupersuperSupersuperSupersuperSuperLong ::$exampleOfOrderOfGetterAndSetterReordered[0]; -$superSupersuperSupersuperSupersuperSupersuperSuperLong = (new SuperSuperSuperSuperSuperSuperLongClassName()) +$superSupersuperSupersuperSupersuperSupersuperSuperLong = new SuperSuperSuperSuperSuperSuperLongClassName() ->some_very_long_member_expression; new $superSupersuperSupersuperSupersuperSupersuperSuperLong->superSupersuperSupersuperSupersuperSupersuperSuperLong->superSupersuperSupersuperSupersuperSupersuperSuperLong(); -(new $superSupersuperSupersuperSupersuperSupersuperSuperLong->superSupersuperSupersuperSupersuperSupersuperSuperLong->superSupersuperSupersuperSupersuperSupersuperSuperLong()) +new $superSupersuperSupersuperSupersuperSupersuperSuperLong->superSupersuperSupersuperSupersuperSupersuperSuperLong->superSupersuperSupersuperSupersuperSupersuperSuperLong() ->superSupersuperSupersuperSupersuperSupersuperSuperLong; $test = $superSupersuperSupersuperSupersuperSupersuperSuperLong->exampleOfOrderOfGetterAndSetterReordered; @@ -241,7 +241,7 @@ $object[ : $helper->responseBody($defaultUser) ]->map(); -(new TestClassWithReallyReallyReallyReallyReallyReallyReallyReallyReallyLongName()) +new TestClassWithReallyReallyReallyReallyReallyReallyReallyReallyReallyLongName() ->map() ->filter(); @@ -565,14 +565,14 @@ $brian->hotel->orders()->ordered()->with("smith")->get(); $brian::$hotel->orders()->ordered()->with("smith")->get(); $brian["hotel"]->orders()->ordered()->with("smith")->get(); Foo::$hotel->orders()->ordered()->with("smith")->get(); -(new Foo())->hotel->orders()->ordered()->with("smith")->get(); +new Foo()->hotel->orders()->ordered()->with("smith")->get(); (clone $a)->hotel->orders()->ordered()->with("smith")->get(); $var = $brian->hotel->orders()->ordered()->with("smith")->get(); $var = $brian::$hotel->orders()->ordered()->with("smith")->get(); $var = $brian["hotel"]->orders()->ordered()->with("smith")->get(); $var = Foo::$hotel->orders()->ordered()->with("smith")->get(); -$var = (new Foo())->hotel->orders()->ordered()->with("smith")->get(); +$var = new Foo()->hotel->orders()->ordered()->with("smith")->get(); $var = (clone $a)->hotel->orders()->ordered()->with("smith")->get(); $var = Foo::keys($items) @@ -583,10 +583,10 @@ $var = Foo::keys($items) return $x * 2; }); -(new static(func_get_args()))->push($this)->each(function ($item) { +new static(func_get_args())->push($this)->each(function ($item) { VarDumper::dump($item); }); -(new static(func_get_args())) +new static(func_get_args()) ->offset(10) ->push($this) ->each(function ($item) { @@ -812,8 +812,8 @@ $window ->first() ->second(); -(new Foo())->call($foo->bar->baz)->first()->second(); -(new Foo()) +new Foo()->call($foo->bar->baz)->first()->second(); +new Foo() ->call($foo->bar->baz->foo()) ->first() ->second(); diff --git a/tests/new/__snapshots__/jsfmt.spec.mjs.snap b/tests/new/__snapshots__/jsfmt.spec.mjs.snap index 4a69f1ad5..177c147da 100644 --- a/tests/new/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/new/__snapshots__/jsfmt.spec.mjs.snap @@ -3,6 +3,7 @@ exports[`new.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -439,7 +440,6 @@ $client = new (config("longstringvariable", "longerstringvariable")([ exports[`new.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/new/jsfmt.spec.mjs b/tests/new/jsfmt.spec.mjs index a2c158328..0692003b1 100644 --- a/tests/new/jsfmt.spec.mjs +++ b/tests/new/jsfmt.spec.mjs @@ -1,2 +1,2 @@ +run_spec(import.meta, ["php"], {phpVersion: "8.3"}); run_spec(import.meta, ["php"]); -run_spec(import.meta, ["php"], { phpVersion: "8.4" }); diff --git a/tests/parens/__snapshots__/jsfmt.spec.mjs.snap b/tests/parens/__snapshots__/jsfmt.spec.mjs.snap index 50fbfd49d..ccb74dd00 100644 --- a/tests/parens/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/parens/__snapshots__/jsfmt.spec.mjs.snap @@ -3,6 +3,7 @@ exports[`array.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -107,7 +108,6 @@ $var = [new stdClass()][0]; exports[`array.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -212,6 +212,7 @@ $var = [new stdClass()][0]; exports[`assign.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -426,7 +427,6 @@ switch ($i = 1) { exports[`assign.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -641,6 +641,7 @@ switch ($i = 1) { exports[`assignref.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -689,7 +690,6 @@ call($a = &$b); exports[`assignref.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -738,6 +738,7 @@ call($a = &$b); exports[`bin.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -1505,7 +1506,6 @@ $result = 2 ** ($number - 1); exports[`bin.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -2273,6 +2273,7 @@ $result = 2 ** ($number - 1); exports[`block.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -2296,7 +2297,6 @@ function foo() exports[`block.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -2320,6 +2320,7 @@ function foo() exports[`break.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -2354,7 +2355,6 @@ break 2; exports[`break.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -2389,6 +2389,7 @@ break 2; exports[`call.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -2507,7 +2508,6 @@ Foo::call($a = new Foo()); exports[`call.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -2626,6 +2626,7 @@ Foo::call($a = new Foo()); exports[`cast.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -2827,7 +2828,6 @@ $timeout = exports[`cast.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -3029,6 +3029,7 @@ $timeout = exports[`clone.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -3107,7 +3108,6 @@ $var = (clone $var->foo)->foo; exports[`clone.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -3186,6 +3186,7 @@ $var = (clone $var->foo)->foo; exports[`closure.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -3239,7 +3240,6 @@ var_dump(...(function () use ($type) {})()); exports[`closure.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -3293,6 +3293,7 @@ var_dump(...(function () use ($type) {})()); exports[`continue.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -3327,7 +3328,6 @@ continue 2; exports[`continue.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -3362,6 +3362,7 @@ continue 2; exports[`control-structures.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -3589,7 +3590,6 @@ do { exports[`control-structures.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -3817,6 +3817,7 @@ do { exports[`declare.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -3839,7 +3840,6 @@ $a->c(); exports[`declare.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -3862,6 +3862,7 @@ $a->c(); exports[`echo.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -3953,7 +3954,6 @@ echo (function () { exports[`echo.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -4045,6 +4045,7 @@ echo (function () { exports[`empty.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -4076,7 +4077,6 @@ if (empty($var)) { exports[`empty.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -4108,6 +4108,7 @@ if (empty($var)) { exports[`eval.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -4151,7 +4152,6 @@ if (eval("return 1;") === 1) { exports[`eval.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -4195,6 +4195,7 @@ if (eval("return 1;") === 1) { exports[`exit.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -4235,7 +4236,6 @@ call(exit(1)); exports[`exit.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -4276,6 +4276,7 @@ call(exit(1)); exports[`include.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -4359,7 +4360,6 @@ include $_GET["id"] . ".php"; exports[`include.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -4443,6 +4443,7 @@ include $_GET["id"] . ".php"; exports[`isset.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -4478,7 +4479,6 @@ if (isset($var)) { exports[`isset.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -4514,6 +4514,7 @@ if (isset($var)) { exports[`lookups.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -4706,7 +4707,6 @@ $var = (function () { exports[`lookups.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -4899,6 +4899,7 @@ $var = (function () { exports[`namespace.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -4921,7 +4922,6 @@ $a->c(); exports[`namespace.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -4944,6 +4944,7 @@ $a->c(); exports[`new.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -5086,7 +5087,6 @@ $var = (new class {})->foo; exports[`new.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -5229,6 +5229,7 @@ $var = new class {}->foo; exports[`parens.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -5247,7 +5248,6 @@ include $test ? "foo" : "bar"; exports[`parens.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -5266,6 +5266,7 @@ include $test ? "foo" : "bar"; exports[`pre-post.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -5394,7 +5395,6 @@ $var = call(--$var->_uuidCounter); exports[`pre-post.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -5523,6 +5523,7 @@ $var = call(--$var->_uuidCounter); exports[`print.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -5622,7 +5623,6 @@ print ($var || $var) && $var; exports[`print.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -5722,6 +5722,7 @@ print ($var || $var) && $var; exports[`program.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -5740,7 +5741,6 @@ $a->c(); exports[`program.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -5759,6 +5759,7 @@ $a->c(); exports[`retif.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -5904,7 +5905,6 @@ $var = new $foo() ? true : false; exports[`retif.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -6050,6 +6050,7 @@ $var = new $foo() ? true : false; exports[`return.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -6090,7 +6091,6 @@ return $this->customer->paymentService ?? null; exports[`return.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -6131,6 +6131,7 @@ return $this->customer->paymentService ?? null; exports[`silent.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -6244,7 +6245,6 @@ echo @(1 / 0); exports[`silent.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -6358,6 +6358,7 @@ echo @(1 / 0); exports[`throw.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -6411,7 +6412,6 @@ $value = $a ? $a : throw new \\InvalidArgumentException("In ternary"); exports[`throw.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -6465,6 +6465,7 @@ $value = $a ? $a : throw new \\InvalidArgumentException("In ternary"); exports[`unary.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -6609,7 +6610,6 @@ if (!($token = $this->getToken())) { exports[`unary.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -6754,6 +6754,7 @@ if (!($token = $this->getToken())) { exports[`unnecessary.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -6876,7 +6877,6 @@ function foo($a = 1, $b = "string", $c = true, $d = __LINE__) exports[`unnecessary.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== @@ -6999,6 +6999,7 @@ function foo($a = 1, $b = "string", $c = true, $d = __LINE__) exports[`yield.php 1`] = ` ====================================options===================================== parsers: ["php"] +phpVersion: "8.3" printWidth: 80 | printWidth =====================================input====================================== @@ -7096,7 +7097,6 @@ function gen_one_to_three() exports[`yield.php 2`] = ` ====================================options===================================== parsers: ["php"] -phpVersion: "8.4" printWidth: 80 | printWidth =====================================input====================================== diff --git a/tests/parens/jsfmt.spec.mjs b/tests/parens/jsfmt.spec.mjs index a2c158328..354bc7ea5 100644 --- a/tests/parens/jsfmt.spec.mjs +++ b/tests/parens/jsfmt.spec.mjs @@ -1,2 +1,2 @@ +run_spec(import.meta, ["php"], {phpVersion:"8.3"}); run_spec(import.meta, ["php"]); -run_spec(import.meta, ["php"], { phpVersion: "8.4" }); diff --git a/tests/staticlookup/__snapshots__/jsfmt.spec.mjs.snap b/tests/staticlookup/__snapshots__/jsfmt.spec.mjs.snap index 101adee06..121cb5059 100644 --- a/tests/staticlookup/__snapshots__/jsfmt.spec.mjs.snap +++ b/tests/staticlookup/__snapshots__/jsfmt.spec.mjs.snap @@ -344,7 +344,7 @@ $var = $var[0]::foo; $var = $var[0][1]::foo; $var = $var[0][1]::foo; $var = $var[0][1]::foo; -$var = (new Foo())::bar; +$var = new Foo()::bar; $var = Foo::$bar["baz"](); $var = Foo::$bar["baz"](); $var = Foo::{$bar["baz"]}(); From b23adb272496434d3761b61d24f52ae5a0235eed Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Tue, 15 Jul 2025 13:27:58 +1000 Subject: [PATCH 12/17] reformat: prettier --- src/util.mjs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/util.mjs b/src/util.mjs index d24ff44e7..b4bf9e473 100644 --- a/src/util.mjs +++ b/src/util.mjs @@ -709,7 +709,6 @@ function memoize(fn) { }; } - export { printNumber, getPrecedence, From 1ea117767920d97873cdcea7ded9af88d2a903c9 Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Tue, 15 Jul 2025 13:34:55 +1000 Subject: [PATCH 13/17] fix default version --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 09dd6cff9..e9d4e2a3d 100644 --- a/README.md +++ b/README.md @@ -191,8 +191,9 @@ Prettier for PHP supports the following options. We recommend that all users set ### \* `phpVersion` Configuration Notes : The default setting `auto`, attempts to auto-detect your supported php versions from a `composer.json` with in the -current directory or any parent directory, the plugin will use minimum supported php version from `{"require":{"php":"..."}}` -to set the phpVersion. If not found, or not able to be parsed, it will default to PHP 8.3. +current directory or any parent directory, the plugin will use a minimum supported php version from +`{"require":{"php":"..."}}` to set the phpVersion. If not found or not able to be parsed, it will default to latest +supported PHP version, which is currently `8.4`. You set the `phpVersion` to `composer` and this will only use the `composer.json` file to determine the php version, prettier will crash if the PHP cannot be determined. From c4262e402b7f0d8e778eac5bb18b7620b9464f8c Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Wed, 16 Jul 2025 09:46:44 +1000 Subject: [PATCH 14/17] Update README.md to be clearer about default php version Co-authored-by: Christian Zosel --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e9d4e2a3d..ddf0782a2 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,7 @@ Prettier for PHP supports the following options. We recommend that all users set The default setting `auto`, attempts to auto-detect your supported php versions from a `composer.json` with in the current directory or any parent directory, the plugin will use a minimum supported php version from `{"require":{"php":"..."}}` to set the phpVersion. If not found or not able to be parsed, it will default to latest -supported PHP version, which is currently `8.4`. +supported PHP version. You set the `phpVersion` to `composer` and this will only use the `composer.json` file to determine the php version, prettier will crash if the PHP cannot be determined. From 2becc128ed6247f814f58219d9b0b913698c09b6 Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Wed, 16 Jul 2025 09:47:06 +1000 Subject: [PATCH 15/17] Update README.md fix typo Co-authored-by: Christian Zosel --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ddf0782a2..da9c51d3f 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,7 @@ version, prettier will crash if the PHP cannot be determined. You can also set the `phpVersion` to a specific version, such as `7.4`, `8.0`, `8.1`, `8.2`, or `8.3`. -**Please Note:** If the phpVersion is not set correctly for your environment, this plugin will product code that could +**Please Note:** If the phpVersion is not set correctly for your environment, this plugin will produce code that could be incompatible with your PHP runtime. For example, if you are using PHP 7.4, but the plugin is set to PHP 8.3, it will produce code that uses features not available in PHP 7.4. From d331e8f381237f3e36091be85dd6c07f1a88b49f Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Wed, 16 Jul 2025 09:48:56 +1000 Subject: [PATCH 16/17] Update src/options.mjs remove extra else Co-authored-by: Christian Zosel --- src/options.mjs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/options.mjs b/src/options.mjs index 232129028..e7444d804 100644 --- a/src/options.mjs +++ b/src/options.mjs @@ -95,9 +95,8 @@ export function resolvePhpVersion(options) { throw new Error( `Could not determine PHP version from composer; ${getComposerError}` ); - } else { - options.phpVersion = v; } + options.phpVersion = v; } else { options.phpVersion = parseFloat(options.phpVersion); } From c2ea236902b52c27afcf70d7df4d60a523569536 Mon Sep 17 00:00:00 2001 From: Chris Seufert Date: Wed, 16 Jul 2025 10:03:23 +1000 Subject: [PATCH 17/17] make not json example much clearer --- tests/composer-version/composer-version.spec.mjs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/composer-version/composer-version.spec.mjs b/tests/composer-version/composer-version.spec.mjs index 59871b3c5..30e6afd69 100644 --- a/tests/composer-version/composer-version.spec.mjs +++ b/tests/composer-version/composer-version.spec.mjs @@ -204,15 +204,7 @@ describe("getComposerPhpVer", () => { test("returns null when composer.json is malformed", () => { // Create a malformed JSON file (invalid syntax) - const malformedContent = `{ - "name": "test/package", - "require": { - "php": "^7.4" - }, // Invalid trailing comma - "extra": { - "key": "value" - } - }`; + const malformedContent = `{This is not JSON}`; fs.writeFileSync(tempComposerPath, malformedContent);