Skip to content

Commit ff4659f

Browse files
committed
Fix sniff
1 parent 160bef3 commit ff4659f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

PSR2R/Sniffs/Commenting/DocBlockPipeSpacingSniff.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,18 @@ public function process(File $phpcsFile, $stackPtr) {
2020
$tokens = $phpcsFile->getTokens();
2121

2222
$content = $tokens[$stackPtr]['content'];
23+
$isInlineDocBlock = substr($content, -1, 1) === ' ';
2324

2425
// Fix inline doc blocks
2526
$appendix = '';
2627
$varIndex = strpos($content, '$');
2728
if ($varIndex) {
2829
$appendix = substr($content, $varIndex);
29-
$content = trim(substr($content, 0, $varIndex));
30+
$content = substr($content, 0, $varIndex);
31+
}
32+
33+
if (strpos($content, '|') === false) {
34+
return;
3035
}
3136

3237
$pieces = explode('|', $content);
@@ -36,13 +41,17 @@ public function process(File $phpcsFile, $stackPtr) {
3641
}
3742
$newContent = implode('|', $newContent);
3843

39-
if ($newContent !== $content) {
44+
if (trim($newContent) !== trim($content)) {
4045
$fix = $phpcsFile->addFixableError('There should be no space around pipes in doc blocks.', $stackPtr,
4146
'PipeSpacing');
4247
if ($fix) {
4348
if ($appendix) {
4449
$appendix = ' ' . $appendix;
4550
}
51+
if ($isInlineDocBlock) {
52+
$appendix .= ' ';
53+
}
54+
4655
$phpcsFile->fixer->replaceToken($stackPtr, $newContent . $appendix);
4756
}
4857
}

0 commit comments

Comments
 (0)