@@ -95,13 +95,7 @@ protected function processTokenWithinScope(
95
95
if ($ code === T_DOC_COMMENT_CLOSE_TAG ) {
96
96
$ commentStart = $ tokens [$ commentEnd ]['comment_opener ' ];
97
97
98
- if ($ tokens [$ commentStart ]['line ' ] === $ tokens [$ commentEnd ]['line ' ]) {
99
- $ phpcsFile ->addError (
100
- 'property doc comment must be multi line ' ,
101
- $ commentEnd ,
102
- 'NotMultiLineDocBlock '
103
- );
104
- }
98
+ $ isCommentOneLiner = $ tokens [$ commentStart ]['line ' ] === $ tokens [$ commentEnd ]['line ' ];
105
99
106
100
$ length = $ commentEnd - $ commentStart + 1 ;
107
101
$ tokensAsString = $ phpcsFile ->getTokensAsString (
@@ -116,15 +110,44 @@ protected function processTokenWithinScope(
116
110
$ commentStart ,
117
111
'NoVarDefined '
118
112
);
119
- } else if ($ varCount > 1 ) {
113
+ } elseif ($ varCount > 1 ) {
120
114
$ phpcsFile ->addError (
121
115
'property doc comment must no multiple @var annotations ' ,
122
116
$ commentStart ,
123
117
'MultipleVarDefined '
124
118
);
125
119
}
120
+
121
+ if ($ varCount === 1 ) {
122
+ if ($ isCommentOneLiner ) {
123
+ $ fix = $ phpcsFile ->addFixableError (
124
+ 'property doc comment must be multi line ' ,
125
+ $ commentEnd ,
126
+ 'NotMultiLineDocBlock '
127
+ );
128
+
129
+ if ($ fix ) {
130
+ $ phpcsFile ->fixer ->beginChangeset ();
131
+ $ phpcsFile ->fixer ->addContent ($ commentStart , "\n * " );
132
+ $ phpcsFile ->fixer ->replaceToken (
133
+ $ commentEnd - 1 ,
134
+ rtrim ($ tokens [$ commentEnd - 1 ]['content ' ])
135
+ );
136
+ $ phpcsFile ->fixer ->addContentBefore ($ commentEnd , "\n " );
137
+ $ phpcsFile ->fixer ->endChangeset ();
138
+ }
139
+ }
140
+ } else {
141
+ if ($ isCommentOneLiner ) {
142
+ $ phpcsFile ->addError (
143
+ 'property doc comment must be multi line ' ,
144
+ $ commentEnd ,
145
+ 'NotMultiLineDocBlock '
146
+ );
147
+ }
148
+ }
126
149
} elseif ($ code === T_COMMENT ) {
127
- $ commentStart = $ phpcsFile ->findPrevious ([ T_COMMENT ] , $ commentEnd , null , true );
150
+ $ commentStart = $ phpcsFile ->findPrevious (T_COMMENT , $ commentEnd , null , true );
128
151
$ phpcsFile ->addError (
129
152
'property doc comment must begin with /** ' ,
130
153
$ commentStart + 1 ,
0 commit comments