Skip to content

Commit 160bef3

Browse files
committed
Fix inline docblock sniff
1 parent e5766fc commit 160bef3

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

PSR2R/Sniffs/Commenting/DocBlockPipeSpacingSniff.php

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

2222
$content = $tokens[$stackPtr]['content'];
23-
if (substr_count($content, '|') !== 1) {
24-
return;
23+
24+
// Fix inline doc blocks
25+
$appendix = '';
26+
$varIndex = strpos($content, '$');
27+
if ($varIndex) {
28+
$appendix = substr($content, $varIndex);
29+
$content = trim(substr($content, 0, $varIndex));
2530
}
2631

27-
list($left, $right) = explode('|', $content);
28-
$newContent = trim($left) . '|' . trim($right);
32+
$pieces = explode('|', $content);
33+
$newContent = [];
34+
foreach ($pieces as $piece) {
35+
$newContent[] = trim($piece);
36+
}
37+
$newContent = implode('|', $newContent);
2938

3039
if ($newContent !== $content) {
3140
$fix = $phpcsFile->addFixableError('There should be no space around pipes in doc blocks.', $stackPtr,
3241
'PipeSpacing');
3342
if ($fix) {
34-
$phpcsFile->fixer->replaceToken($stackPtr, $newContent);
43+
if ($appendix) {
44+
$appendix = ' ' . $appendix;
45+
}
46+
$phpcsFile->fixer->replaceToken($stackPtr, $newContent . $appendix);
3547
}
3648
}
3749
}

0 commit comments

Comments
 (0)