Skip to content

Commit fa46d08

Browse files
committed
Fix "Option 'indent' must either be all spaces or a single tab"
1 parent 0b60b27 commit fa46d08

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Analyser/RuleErrorTransformer.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use SebastianBergmann\Diff\Output\UnifiedDiffOutputBuilder;
3030
use function get_class;
3131
use function sha1;
32+
use function str_contains;
3233
use function str_repeat;
3334

3435
#[AutowiredService]
@@ -137,7 +138,12 @@ public function transform(
137138
$newStmts = $traverser->traverse($newStmts);
138139

139140
if ($visitor->isFound()) {
140-
$printer = new PhpPrinter(['indent' => str_repeat($indentDetector->indentCharacter, $indentDetector->indentSize)]);
141+
if (str_contains($indentDetector->indentCharacter, "\t")) {
142+
$indent = "\t";
143+
} else {
144+
$indent = str_repeat($indentDetector->indentCharacter, $indentDetector->indentSize);
145+
}
146+
$printer = new PhpPrinter(['indent' => $indent]);
141147
$newCode = $printer->printFormatPreserving($newStmts, $fileNodes, $oldTokens);
142148

143149
if ($oldCode !== $newCode) {

tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,4 +827,5 @@ public function testFixWithTabs(): void
827827
$this->checkMissingOverrideMethodAttribute = true;
828828
$this->fix(__DIR__ . '/data/fix-with-tabs.php', __DIR__ . '/data/fix-with-tabs.php.fixed');
829829
}
830+
830831
}

0 commit comments

Comments
 (0)