Skip to content

Commit cbeaae3

Browse files
committed
fix
1 parent b9d315b commit cbeaae3

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

bin/simple-downgrade

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ foreach ([__DIR__ . '/../../../autoload.php', __DIR__ . '/../vendor/autoload.php
2020
$lexer = new \PhpParser\Lexer\Emulative();
2121

2222
$parser = new Php7($lexer);
23-
$printer = new PhpPrinter();
2423

2524
$phpDocParserConfig = new ParserConfig(['lines' => true, 'indexes' => true]);
2625
$constExprParser = new ConstExprParser($phpDocParserConfig);

src/Console/DowngradeCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private function processFile(string $file, array $visitors): void
157157
$newStmts = $traverser->traverse($newStmts);
158158
}
159159

160-
$printer = new PhpPrinter(['indent' => $indentDetector->indentCharacter]);
160+
$printer = new PhpPrinter(['indent' => $indentDetector->indent]);
161161
$newCode = $printer->printFormatPreserving($newStmts, $oldStmts, $oldTokens);
162162
$result = file_put_contents($file, $newCode);
163163
if ($result === false) {

src/Php/PhpPrinterIndentationDetectorVisitor.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@
1717
class PhpPrinterIndentationDetectorVisitor extends NodeVisitorAbstract
1818
{
1919

20-
public string $indentCharacter = ' ';
21-
22-
public int $indentSize = 4;
20+
public string $indent = ' ';
2321

2422
private TokenStream $origTokens;
2523

@@ -72,8 +70,11 @@ public function enterNode(Node $node)
7270
$char = ' ';
7371
}
7472

75-
$this->indentCharacter = $char;
76-
$this->indentSize = $size;
73+
if ($char === "\t") {
74+
$this->indent = $char;
75+
} else {
76+
$this->indent = str_repeat(' ', $size);
77+
}
7778

7879
return NodeTraverser::STOP_TRAVERSAL;
7980
}

tests/Visitor/AbstractVisitorTestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public function testVisitor(string $codeBefore, string $codeAfter): void
6262
/** @var Stmt[] $newStmts */
6363
$newStmts = $traverser->traverse($newStmts);
6464

65-
$printer = new PhpPrinter(['indent' => $indentDetector->indentCharacter]);
65+
$printer = new PhpPrinter(['indent' => $indentDetector->indent]);
6666
$newCode = $printer->printFormatPreserving($newStmts, $oldStmts, $oldTokens);
6767

6868
$this->assertSame($codeAfter, $newCode);

0 commit comments

Comments
 (0)