@@ -263,23 +263,35 @@ protected function processTags(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $comm
263263
264264 foreach ($ this ->tags as $ tag => $ tagData )
265265 {
266- if (isset ($ tagTokens [$ tag ]) === false )
266+ // We don't use package tags in namespaced classes.
267+ if ($ tag === '@package ' || $ tag === '@subpackage ' )
267268 {
268- if ($ tagData ['required ' ] === true )
269+ // Check for a namespace token, if certain other tokens are found we can move on. This keeps us from searching the whole file.
270+ $ namespaced = $ phpcsFile ->findNext (array (T_NAMESPACE , T_CLASS , T_INTERFACE , T_TRAIT ), 0 );
271+ $ classes = array (T_CLASS , T_INTERFACE , T_TRAIT );
272+ $ class = $ phpcsFile ->findNext ($ classes , 0 );
273+
274+ // If we found a namespaced class trigger the error.
275+ if ($ tokens [$ namespaced ]['code ' ] === T_NAMESPACE && in_array ($ tokens [$ class ]['code ' ], $ classes , true ))
269276 {
270- // We don't use package tags in namespaced code
271- if ($ tag == '@package ' )
277+ if (isset ($ tagTokens [$ tag ]) === true )
272278 {
273- // Check for a namespace token, if certain other tokens are found we can move on. This keeps us from searching the whole file.
274- $ namespaced = $ phpcsFile ->findNext (array (T_NAMESPACE , T_CLASS , T_INTERFACE , T_TRAIT ), 0 );
275-
276- // If we found a namespace token we skip the error, otherwise we let the error happen
277- if ($ tokens [$ namespaced ]['code ' ] === T_NAMESPACE )
278- {
279- continue ;
280- }
279+ $ error = '%s tag found in namespaced %s comment ' ;
280+ $ data = array (
281+ $ tag ,
282+ $ docBlock ,
283+ );
284+ $ phpcsFile ->addError ($ error , $ commentEnd , ucfirst (substr ($ tag , 1 )) . 'TagInNamespace ' , $ data );
281285 }
282286
287+ continue ;
288+ }
289+ }
290+
291+ if (isset ($ tagTokens [$ tag ]) === false )
292+ {
293+ if ($ tagData ['required ' ] === true )
294+ {
283295 $ error = 'Missing %s tag in %s comment ' ;
284296 $ data = array (
285297 $ tag ,
0 commit comments