From 3b01749ba43f51102eabb8ece3eb656ffa84da51 Mon Sep 17 00:00:00 2001 From: Xaver Loppenstedt Date: Sat, 14 Dec 2024 21:09:49 +0100 Subject: [PATCH 1/2] Fix uninitialized string offset in UnnecessaryNamespaceUsage, fixes #212 --- .../Formatting/UnnecessaryNamespaceUsageSniff.php | 9 +++++++-- .../UnnecessaryNamespaceUsageUnitTest.pass.6.inc | 15 +++++++++++++++ .../UnnecessaryNamespaceUsageUnitTest.php | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.pass.6.inc diff --git a/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php b/MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php index 18b9d0f..28860e9 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 0000000..53448a0 --- /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 ae6dab6..2cc6048 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, From bfbe6cfc99864c0dd4506369f595260c66c1ff22 Mon Sep 17 00:00:00 2001 From: Xaver Loppenstedt Date: Mon, 16 Dec 2024 10:17:42 +0100 Subject: [PATCH 2/2] Release 10.0.1 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e49ea15..1221bad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [10.0.1] - 2024-12-16 +### Changed +- Fix uninitialized string offset in UnnecessaryNamespaceUsage, fixes #212 + ## [10.0.0] - 2024-03-13 ### Changed Allow dealerdirect/phpcodesniffer-composer-installer 1.x