3
3
namespace PSR2R \Sniffs \Commenting ;
4
4
5
5
use PHP_CodeSniffer \Files \File ;
6
+ use PHP_CodeSniffer \Util \Tokens ;
6
7
use PSR2R \Tools \AbstractSniff ;
7
8
8
9
/**
@@ -192,7 +193,11 @@ protected function findErrors(File $phpCsFile, $contentIndex) {
192
193
193
194
preg_match ('|^(.+?)(\s+)(.+?)\s*$| ' , $ comment , $ contentMatches );
194
195
if (!$ contentMatches || !$ contentMatches [1 ] || !$ contentMatches [3 ]) {
195
- $ phpCsFile ->addError ('Invalid Inline Doc Block content ' , $ contentIndex , 'ContentInvalid ' );
196
+ if ($ this ->hasReturnAsFollowingToken ($ phpCsFile , $ contentIndex )) {
197
+ return [];
198
+ }
199
+
200
+ $ phpCsFile ->addError ('Invalid Inline Doc Block content, expected `{Type} ${var}` style ' , $ contentIndex , 'ContentInvalid ' );
196
201
return [];
197
202
}
198
203
@@ -209,4 +214,21 @@ protected function findErrors(File $phpCsFile, $contentIndex) {
209
214
return $ errors ;
210
215
}
211
216
217
+ /**
218
+ * @param \PHP_CodeSniffer\Files\File $phpCsFile
219
+ * @param int $contentIndex
220
+ *
221
+ * @return bool
222
+ */
223
+ protected function hasReturnAsFollowingToken (File $ phpCsFile , $ contentIndex ) {
224
+ $ nextIndex = $ phpCsFile ->findNext (Tokens::$ emptyTokens , $ contentIndex + 1 , null , true );
225
+ if (!$ nextIndex ) {
226
+ return false ;
227
+ }
228
+
229
+ $ tokens = $ phpCsFile ->getTokens ();
230
+
231
+ return $ tokens [$ nextIndex ]['code ' ] === T_RETURN ;
232
+ }
233
+
212
234
}
0 commit comments