From 42bbb8588a3023d632c2b24b476743efa50f42e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 16 Jun 2024 18:43:47 +0200 Subject: [PATCH 1/2] fix: Configure the printer to preserve formatting --- src/PhpParser/Printer/StandardPrinter.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PhpParser/Printer/StandardPrinter.php b/src/PhpParser/Printer/StandardPrinter.php index 7950b859..279abf02 100644 --- a/src/PhpParser/Printer/StandardPrinter.php +++ b/src/PhpParser/Printer/StandardPrinter.php @@ -24,7 +24,11 @@ public function __construct(private PrettyPrinter $decoratedPrinter) public function print(array $newStmts, array $oldStmts, array $oldTokens): string { - $printedStatements = $this->decoratedPrinter->prettyPrintFile($newStmts); + $printedStatements = $this->decoratedPrinter->printFormatPreserving( + $newStmts, + $oldStmts, + $oldTokens, + ); return $printedStatements."\n"; } From 2e104d79f2030a59b13c35f5ae2cdc387169138f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sun, 16 Jun 2024 19:01:15 +0200 Subject: [PATCH 2/2] fix some errors --- specs/use/use-class.php | 2 ++ specs/use/use-trait.php | 4 ++-- tests/Scoper/PhpScoperTest.php | 5 +---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/specs/use/use-class.php b/specs/use/use-class.php index a61cbde2..8dea04c4 100644 --- a/specs/use/use-class.php +++ b/specs/use/use-class.php @@ -37,6 +37,7 @@ class Foo {} class Foo { } + use Humbug\Foo; PHP, @@ -56,6 +57,7 @@ class Foo {} class Foo { } + use Humbug\Foo; PHP, diff --git a/specs/use/use-trait.php b/specs/use/use-trait.php index 91cc732e..223efbfc 100644 --- a/specs/use/use-trait.php +++ b/specs/use/use-trait.php @@ -36,8 +36,7 @@ class HTML5DOMDocument { namespace Humbug\IvoPetkov; - class HTML5DOMDocument - { + class HTML5DOMDocument { use \Humbug\IvoPetkov\Internal\QuerySelector; } @@ -60,6 +59,7 @@ class HTML5DOMDocument { namespace Humbug\IvoPetkov; use Humbug\IvoPetkov\Internal\QuerySelector; + class HTML5DOMDocument { use QuerySelector; diff --git a/tests/Scoper/PhpScoperTest.php b/tests/Scoper/PhpScoperTest.php index 65287b9b..8df0c02c 100644 --- a/tests/Scoper/PhpScoperTest.php +++ b/tests/Scoper/PhpScoperTest.php @@ -120,8 +120,6 @@ public function test_can_scope_a_php_file(): void PHP; $expected = <<<'PHP' - #!/usr/bin/env php