Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
},
"require-dev": {
"doctrine/annotations": "^2.0",
"nikic/php-parser": "^5.1",
"nikic/php-parser": "^5.3.0",
"php-parallel-lint/php-parallel-lint": "^1.2",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^2.0",
Expand Down
10 changes: 9 additions & 1 deletion tests/PHPStan/Printer/IntegrationPrinterWithPhpParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use LogicException;
use PhpParser\Comment\Doc;
use PhpParser\Internal\TokenStream;
use PhpParser\Node as PhpNode;
use PhpParser\NodeTraverser as PhpParserNodeTraverser;
use PhpParser\NodeVisitor\CloningVisitor as PhpParserCloningVisitor;
use PhpParser\NodeVisitorAbstract;
use PhpParser\ParserFactory;
use PhpParser\PrettyPrinter\Standard;
use PHPStan\PhpDocParser\Ast\AbstractNodeVisitor;
use PHPStan\PhpDocParser\Ast\Node;
use PHPStan\PhpDocParser\Ast\NodeTraverser;
Expand All @@ -28,6 +30,7 @@

class IntegrationPrinterWithPhpParserTest extends TestCase
{
private const TAB_WIDTH = 4;

/**
* @return iterable<array{string, string, NodeVisitor}>
Expand Down Expand Up @@ -73,7 +76,6 @@ public function testPrint(string $file, string $expectedFile, NodeVisitor $visit
$phpTraverser = new PhpParserNodeTraverser();
$phpTraverser->addVisitor(new PhpParserCloningVisitor());

$printer = new PhpPrinter();
$fileContents = file_get_contents($file);
if ($fileContents === false) {
$this->fail('Could not read ' . $file);
Expand All @@ -85,6 +87,11 @@ public function testPrint(string $file, string $expectedFile, NodeVisitor $visit
}
$oldTokens = $phpParser->getTokens();

$phpTraverserIndent = new PhpParserNodeTraverser();
$indentDetector = new PhpPrinterIndentationDetectorVisitor(new TokenStream($oldTokens, self::TAB_WIDTH));
$phpTraverserIndent->addVisitor($indentDetector);
$phpTraverserIndent->traverse($oldStmts);

$phpTraverser2 = new PhpParserNodeTraverser();
$phpTraverser2->addVisitor(new class ($visitor) extends NodeVisitorAbstract {

Expand Down Expand Up @@ -134,6 +141,7 @@ public function enterNode(PhpNode $phpNode)
$newStmts = $phpTraverser->traverse($oldStmts);
$newStmts = $phpTraverser2->traverse($newStmts);

$printer = new Standard(['indent' => str_repeat($indentDetector->indentCharacter, $indentDetector->indentSize)]);
$newCode = $printer->printFormatPreserving($newStmts, $oldStmts, $oldTokens);
$this->assertStringEqualsFile($expectedFile, $newCode);
}
Expand Down
58 changes: 0 additions & 58 deletions tests/PHPStan/Printer/PhpPrinter.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use PhpParser\Internal\TokenStream;
use PhpParser\Node;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor;
use PhpParser\NodeVisitorAbstract;
use function count;
use function preg_match;
Expand Down Expand Up @@ -71,7 +72,7 @@ public function enterNode(Node $node)
$this->indentCharacter = $char;
$this->indentSize = $size;

return NodeTraverser::STOP_TRAVERSAL;
return NodeVisitor::STOP_TRAVERSAL;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive-by deprecation fix

}

return null;
Expand Down
Loading