@@ -249,6 +249,46 @@ public function validateTagGroupingFormat(File $phpcsFile, int $commentStartPtr)
249
249
}
250
250
}
251
251
252
+ /**
253
+ * Validates tag aligning format
254
+ *
255
+ * @param File $phpcsFile
256
+ * @param int $commentStartPtr
257
+ */
258
+ public function validateTagAligningFormat (File $ phpcsFile , int $ commentStartPtr ) : void
259
+ {
260
+ $ tokens = $ phpcsFile ->getTokens ();
261
+ $ noAlignmentPositions = [];
262
+ $ actualPositions = [];
263
+ $ stackPtr = null ;
264
+ foreach ($ tokens [$ commentStartPtr ]['comment_tags ' ] as $ position => $ tag ) {
265
+ $ content = $ tokens [$ tag ]['content ' ];
266
+ if (preg_match ('/^@/ ' , $ content ) && ($ tokens [$ tag ]['line ' ] === $ tokens [$ tag + 2 ]['line ' ])) {
267
+ $ noAlignmentPositions [] = $ tokens [$ tag + 1 ]['column ' ] + 1 ;
268
+ $ actualPositions [] = $ tokens [$ tag + 2 ]['column ' ];
269
+ $ stackPtr = $ stackPtr ?? $ tag ;
270
+ }
271
+
272
+ }
273
+
274
+ if (!$ this ->allTagsAligned ($ actualPositions )
275
+ && !$ this ->noneTagsAligned ($ actualPositions , $ noAlignmentPositions )) {
276
+ $ phpcsFile ->addFixableError (
277
+ 'Tags visual alignment must be consistent ' ,
278
+ $ stackPtr ,
279
+ 'MethodArguments '
280
+ );
281
+ }
282
+ }
283
+
284
+ private function allTagsAligned (array $ actualPositions ) {
285
+ return count (array_unique ($ actualPositions )) === 1 ;
286
+ }
287
+
288
+ private function noneTagsAligned (array $ actualPositions , array $ noAlignmentPositions ) {
289
+ return $ actualPositions === $ noAlignmentPositions ;
290
+ }
291
+
252
292
/**
253
293
* Validates extra newline before short description
254
294
*
0 commit comments