@@ -177,21 +177,53 @@ protected function checkLineLength(File $phpcsFile, array $tokens, int $stackPtr
177177 if ($ this ->absoluteLineLimit > 0
178178 && $ lineLength > $ this ->absoluteLineLimit
179179 ) {
180+ $ code = 'MaxExceeded ' ;
181+ if ($ this ->isLineNamespacedName ($ tokens , $ tokens [$ stackPtr ]['line ' ]) === true ) {
182+ $ code = 'NamespacedNameMaxExceeded ' ;
183+ }
184+
180185 $ data = [
181186 $ this ->absoluteLineLimit ,
182187 $ lineLength ,
183188 ];
184189
185190 $ error = 'Line exceeds maximum limit of %s characters; contains %s characters ' ;
186- $ phpcsFile ->addError ($ error , $ stackPtr , ' MaxExceeded ' , $ data );
191+ $ phpcsFile ->addError ($ error , $ stackPtr , $ code , $ data );
187192 } elseif ($ lineLength > $ this ->lineLimit ) {
193+ $ code = 'TooLong ' ;
194+ if ($ this ->isLineNamespacedName ($ tokens , $ tokens [$ stackPtr ]['line ' ]) === true ) {
195+ $ code = 'NamespacedNameTooLong ' ;
196+ }
197+
188198 $ data = [
189199 $ this ->lineLimit ,
190200 $ lineLength ,
191201 ];
192202
193203 $ warning = 'Line exceeds %s characters; contains %s characters ' ;
194- $ phpcsFile ->addWarning ($ warning , $ stackPtr , ' TooLong ' , $ data );
204+ $ phpcsFile ->addWarning ($ warning , $ stackPtr , $ code , $ data );
195205 }
196206 }
207+
208+
209+ /**
210+ * Checks if a line is a namespaced name
211+ *
212+ * @param array $tokens The token stack.
213+ * @param int $line The line to check validate
214+ *
215+ * @return bool
216+ */
217+ private function isLineNamespacedName (array $ tokens , int $ line ): bool
218+ {
219+ $ filteredTokens = array_filter (
220+ $ tokens ,
221+ function ($ token ) use ($ line ) {
222+ return $ token ['line ' ] === $ line
223+ && in_array ($ token ['code ' ], [T_NAME_QUALIFIED , T_NAME_FULLY_QUALIFIED , T_NAME_RELATIVE ], true );
224+ }
225+ );
226+
227+ return $ filteredTokens !== [];
228+ }
197229}
0 commit comments