Skip to content

Commit a131a15

Browse files
authored
Fix IntegrationPrinterWithPhpParserTest
* Fix IntegrationPrinterWithPhpParserTest * rais min php-parser version * Update PhpPrinterIndentationDetectorVisitor.php * Update phpstan-baseline.neon * manual cs fix
1 parent 5260317 commit a131a15

5 files changed

+24
-67
lines changed

Diff for: composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
},
88
"require-dev": {
99
"doctrine/annotations": "^2.0",
10-
"nikic/php-parser": "^5.1",
10+
"nikic/php-parser": "^5.3.0",
1111
"php-parallel-lint/php-parallel-lint": "^1.2",
1212
"phpstan/extension-installer": "^1.0",
1313
"phpstan/phpstan": "^2.0",

Diff for: phpstan-baseline.neon

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,31 @@
11
parameters:
22
ignoreErrors:
33
-
4-
message: "#^Method PHPStan\\\\PhpDocParser\\\\Ast\\\\ConstExpr\\\\ConstExprStringNode\\:\\:escapeDoubleQuotedString\\(\\) should return string but returns string\\|null\\.$#"
4+
message: '#^Method PHPStan\\PhpDocParser\\Ast\\ConstExpr\\ConstExprStringNode\:\:escapeDoubleQuotedString\(\) should return string but returns string\|null\.$#'
5+
identifier: return.type
56
count: 1
67
path: src/Ast/ConstExpr/ConstExprStringNode.php
78

89
-
9-
message: "#^Cannot use array destructuring on array\\<int, array\\<PHPStan\\\\PhpDocParser\\\\Ast\\\\Node\\>\\|int\\|string\\>\\|null\\.$#"
10+
message: '#^Cannot use array destructuring on list\<array\<PHPStan\\PhpDocParser\\Ast\\Node\>\|int\|string\>\|null\.$#'
11+
identifier: offsetAccess.nonArray
1012
count: 1
1113
path: src/Ast/NodeTraverser.php
1214

1315
-
14-
message: "#^Variable property access on PHPStan\\\\PhpDocParser\\\\Ast\\\\Node\\.$#"
16+
message: '#^Variable property access on PHPStan\\PhpDocParser\\Ast\\Node\.$#'
17+
identifier: property.dynamicName
1518
count: 1
1619
path: src/Ast/NodeTraverser.php
1720

1821
-
19-
message: "#^Method PHPStan\\\\PhpDocParser\\\\Parser\\\\StringUnescaper\\:\\:parseEscapeSequences\\(\\) should return string but returns string\\|null\\.$#"
22+
message: '#^Method PHPStan\\PhpDocParser\\Parser\\StringUnescaper\:\:parseEscapeSequences\(\) should return string but returns string\|null\.$#'
23+
identifier: return.type
2024
count: 1
2125
path: src/Parser/StringUnescaper.php
2226

2327
-
24-
message: "#^Variable property access on PHPStan\\\\PhpDocParser\\\\Ast\\\\Node\\.$#"
28+
message: '#^Variable property access on PHPStan\\PhpDocParser\\Ast\\Node\.$#'
29+
identifier: property.dynamicName
2530
count: 2
2631
path: src/Printer/Printer.php

Diff for: tests/PHPStan/Printer/IntegrationPrinterWithPhpParserTest.php

+11-1
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
use LogicException;
66
use PhpParser\Comment\Doc;
7+
use PhpParser\Internal\TokenStream;
78
use PhpParser\Node as PhpNode;
89
use PhpParser\NodeTraverser as PhpParserNodeTraverser;
910
use PhpParser\NodeVisitor\CloningVisitor as PhpParserCloningVisitor;
1011
use PhpParser\NodeVisitorAbstract;
1112
use PhpParser\ParserFactory;
13+
use PhpParser\PrettyPrinter\Standard;
1214
use PHPStan\PhpDocParser\Ast\AbstractNodeVisitor;
1315
use PHPStan\PhpDocParser\Ast\Node;
1416
use PHPStan\PhpDocParser\Ast\NodeTraverser;
@@ -25,10 +27,13 @@
2527
use PHPStan\PhpDocParser\ParserConfig;
2628
use PHPUnit\Framework\TestCase;
2729
use function file_get_contents;
30+
use function str_repeat;
2831

2932
class IntegrationPrinterWithPhpParserTest extends TestCase
3033
{
3134

35+
private const TAB_WIDTH = 4;
36+
3237
/**
3338
* @return iterable<array{string, string, NodeVisitor}>
3439
*/
@@ -73,7 +78,6 @@ public function testPrint(string $file, string $expectedFile, NodeVisitor $visit
7378
$phpTraverser = new PhpParserNodeTraverser();
7479
$phpTraverser->addVisitor(new PhpParserCloningVisitor());
7580

76-
$printer = new PhpPrinter();
7781
$fileContents = file_get_contents($file);
7882
if ($fileContents === false) {
7983
$this->fail('Could not read ' . $file);
@@ -85,6 +89,11 @@ public function testPrint(string $file, string $expectedFile, NodeVisitor $visit
8589
}
8690
$oldTokens = $phpParser->getTokens();
8791

92+
$phpTraverserIndent = new PhpParserNodeTraverser();
93+
$indentDetector = new PhpPrinterIndentationDetectorVisitor(new TokenStream($oldTokens, self::TAB_WIDTH));
94+
$phpTraverserIndent->addVisitor($indentDetector);
95+
$phpTraverserIndent->traverse($oldStmts);
96+
8897
$phpTraverser2 = new PhpParserNodeTraverser();
8998
$phpTraverser2->addVisitor(new class ($visitor) extends NodeVisitorAbstract {
9099

@@ -134,6 +143,7 @@ public function enterNode(PhpNode $phpNode)
134143
$newStmts = $phpTraverser->traverse($oldStmts);
135144
$newStmts = $phpTraverser2->traverse($newStmts);
136145

146+
$printer = new Standard(['indent' => str_repeat($indentDetector->indentCharacter, $indentDetector->indentSize)]);
137147
$newCode = $printer->printFormatPreserving($newStmts, $oldStmts, $oldTokens);
138148
$this->assertStringEqualsFile($expectedFile, $newCode);
139149
}

Diff for: tests/PHPStan/Printer/PhpPrinter.php

-58
This file was deleted.

Diff for: tests/PHPStan/Printer/PhpPrinterIndentationDetectorVisitor.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use PhpParser\Internal\TokenStream;
66
use PhpParser\Node;
7-
use PhpParser\NodeTraverser;
7+
use PhpParser\NodeVisitor;
88
use PhpParser\NodeVisitorAbstract;
99
use function count;
1010
use function preg_match;
@@ -71,7 +71,7 @@ public function enterNode(Node $node)
7171
$this->indentCharacter = $char;
7272
$this->indentSize = $size;
7373

74-
return NodeTraverser::STOP_TRAVERSAL;
74+
return NodeVisitor::STOP_TRAVERSAL;
7575
}
7676

7777
return null;

0 commit comments

Comments
 (0)