diff --git a/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php b/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php index 18b9d0f9..28860e98 100644 --- a/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php +++ b/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php @@ -224,13 +224,18 @@ protected function getUseStatements(File $phpcsFile, int $start, int $end): arra $end, true ); - $classNameEnd = (int) $phpcsFile->findNext( + $classNameEnd = $phpcsFile->findNext( $this->classNameTokens, ($classNameStart + 1), $end, true ); - $useEnd = $phpcsFile->findNext( + + if (false === $classNameEnd) { + break; + } + + $useEnd = $phpcsFile->findNext( [ T_SEMICOLON, T_COMMA, diff --git a/MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.pass.6.inc b/MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.pass.6.inc new file mode 100644 index 00000000..53448a0d --- /dev/null +++ b/MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.pass.6.inc @@ -0,0 +1,15 @@ +b(); + } +} diff --git a/MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php b/MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php index ae6dab69..2cc60485 100644 --- a/MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php +++ b/MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php @@ -40,6 +40,7 @@ class UnnecessaryNamespaceUsageUnitTest extends AbstractMo4SniffUnitTest 'UnnecessaryNamespaceUsageUnitTest.pass.3.inc' => [], 'UnnecessaryNamespaceUsageUnitTest.pass.4.inc' => [], 'UnnecessaryNamespaceUsageUnitTest.pass.5.inc' => [], + 'UnnecessaryNamespaceUsageUnitTest.pass.6.inc' => [], 'UnnecessaryNamespaceUsageUnitTest.fail.1.inc' => [ 17 => 1, 19 => 1,