@@ -20,13 +20,18 @@ public function process(File $phpcsFile, $stackPtr) {
20
20
$ tokens = $ phpcsFile ->getTokens ();
21
21
22
22
$ content = $ tokens [$ stackPtr ]['content ' ];
23
+ $ isInlineDocBlock = substr ($ content , -1 , 1 ) === ' ' ;
23
24
24
25
// Fix inline doc blocks
25
26
$ appendix = '' ;
26
27
$ varIndex = strpos ($ content , '$ ' );
27
28
if ($ varIndex ) {
28
29
$ 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 ;
30
35
}
31
36
32
37
$ pieces = explode ('| ' , $ content );
@@ -36,13 +41,17 @@ public function process(File $phpcsFile, $stackPtr) {
36
41
}
37
42
$ newContent = implode ('| ' , $ newContent );
38
43
39
- if ($ newContent !== $ content ) {
44
+ if (trim ( $ newContent) !== trim ( $ content) ) {
40
45
$ fix = $ phpcsFile ->addFixableError ('There should be no space around pipes in doc blocks. ' , $ stackPtr ,
41
46
'PipeSpacing ' );
42
47
if ($ fix ) {
43
48
if ($ appendix ) {
44
49
$ appendix = ' ' . $ appendix ;
45
50
}
51
+ if ($ isInlineDocBlock ) {
52
+ $ appendix .= ' ' ;
53
+ }
54
+
46
55
$ phpcsFile ->fixer ->replaceToken ($ stackPtr , $ newContent . $ appendix );
47
56
}
48
57
}
0 commit comments