Skip to content

Commit

Permalink
refactor: Leverage the PhpParser v5 printer changes (#1040)
Browse files Browse the repository at this point in the history
- Typehint against the interface instead of the abstract method.
- Correct the type for the old tokens.
  • Loading branch information
theofidry authored Jun 10, 2024
1 parent c9646d2 commit 49af316
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/PhpParser/Printer/Printer.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
namespace Humbug\PhpScoper\PhpParser\Printer;

use PhpParser\Node;
use PhpParser\Token;

interface Printer
{
/**
* @param Node[] $newStmts
* @param Node[] $oldStmts
* @param array<mixed> $oldTokens
* @param Node[] $newStmts
* @param Node[] $oldStmts
* @param Token[] $oldTokens
*/
public function print(array $newStmts, array $oldStmts, array $oldTokens): string;
}
8 changes: 5 additions & 3 deletions src/PhpParser/Printer/StandardPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@

namespace Humbug\PhpScoper\PhpParser\Printer;

use PhpParser\PrettyPrinterAbstract;
use PhpParser\PrettyPrinter;

final readonly class StandardPrinter implements Printer
{
public function __construct(private PrettyPrinterAbstract $decoratedPrinter)
public function __construct(private PrettyPrinter $decoratedPrinter)
{
}

public function print(array $newStmts, array $oldStmts, array $oldTokens): string
{
return $this->decoratedPrinter->prettyPrintFile($newStmts)."\n";
$printedStatements = $this->decoratedPrinter->prettyPrintFile($newStmts);

return $printedStatements."\n";
}
}

0 comments on commit 49af316

Please sign in to comment.