From ebd592a68d80f25dff1e1b067e7c473549104874 Mon Sep 17 00:00:00 2001 From: Xaver Loppenstedt Date: Sat, 14 Dec 2024 21:09:49 +0100 Subject: [PATCH] Fix phpcbf crash in UnnecessaryNamespaceUsageSniff when class name is empty, fixes #212 --- MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php b/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php index 18b9d0f..6b8df42 100644 --- a/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php +++ b/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php @@ -230,7 +230,12 @@ protected function getUseStatements(File $phpcsFile, int $start, int $end): arra $end, true ); - $useEnd = $phpcsFile->findNext( + + if (0 === $classNameEnd) { + break; + } + + $useEnd = $phpcsFile->findNext( [ T_SEMICOLON, T_COMMA,