Skip to content

Commit fc992f7

Browse files
committed
Fix indentation issue.
1 parent c552156 commit fc992f7

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

PhpCollective/Sniffs/Commenting/DisallowArrayTypeHintSyntaxSniff.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
use SlevomatCodingStandard\Helpers\AnnotationHelper;
2525
use SlevomatCodingStandard\Helpers\AnnotationTypeHelper;
2626
use SlevomatCodingStandard\Helpers\DocCommentHelper;
27-
use SlevomatCodingStandard\Helpers\FixerHelper;
2827
use SlevomatCodingStandard\Helpers\FunctionHelper;
2928
use SlevomatCodingStandard\Helpers\NamespaceHelper;
3029
use SlevomatCodingStandard\Helpers\SniffSettingsHelper;
@@ -143,23 +142,46 @@ public function process(File $phpcsFile, $pointer): void
143142
new IdentifierTypeNode($genericIdentifier),
144143
[$this->fixArrayNode($arrayTypeNode->type)],
145144
);
146-
$this->fixAnnotation($phpcsFile, $annotation, $genericTypeNode);
145+
$this->fixAnnotation($phpcsFile, $annotation, AnnotationTypeHelper::print($genericTypeNode));
147146

148147
continue;
149148
}
150149

151-
$phpcsFile->fixer->beginChangeset();
152-
FixerHelper::change(
150+
$this->applyFixWithoutTabConversion(
153151
$phpcsFile,
154152
$parsedDocComment->getOpenPointer(),
155153
$parsedDocComment->getClosePointer(),
156154
$fixedDocComment,
157155
);
158-
$phpcsFile->fixer->endChangeset();
159156
}
160157
}
161158
}
162159

160+
/**
161+
* Apply a fix without converting spaces to tabs
162+
*
163+
* @param \PHP_CodeSniffer\Files\File $phpcsFile
164+
* @param int $startPointer
165+
* @param int $endPointer
166+
* @param string $content
167+
*
168+
* @return void
169+
*/
170+
protected function applyFixWithoutTabConversion(File $phpcsFile, int $startPointer, int $endPointer, string $content): void
171+
{
172+
$phpcsFile->fixer->beginChangeset();
173+
174+
// Remove all tokens between start and end
175+
for ($i = $startPointer; $i <= $endPointer; $i++) {
176+
$phpcsFile->fixer->replaceToken($i, '');
177+
}
178+
179+
// Add the new content without tab conversion
180+
$phpcsFile->fixer->replaceToken($startPointer, $content);
181+
182+
$phpcsFile->fixer->endChangeset();
183+
}
184+
163185
/**
164186
* @param \PHP_CodeSniffer\Files\File $phpcsFile
165187
* @param \SlevomatCodingStandard\Helpers\Annotation $annotation

0 commit comments

Comments
 (0)