Skip to content

Commit 00625b4

Browse files
xaloppmmoll
authored andcommitted
Fix uninitialized string offset in UnnecessaryNamespaceUsage, fixes #212
1 parent c8eeaaf commit 00625b4

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

MO4/Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,18 @@ protected function getUseStatements(File $phpcsFile, int $start, int $end): arra
224224
$end,
225225
true
226226
);
227-
$classNameEnd = (int) $phpcsFile->findNext(
227+
$classNameEnd = $phpcsFile->findNext(
228228
$this->classNameTokens,
229229
($classNameStart + 1),
230230
$end,
231231
true
232232
);
233-
$useEnd = $phpcsFile->findNext(
233+
234+
if (false === $classNameEnd) {
235+
break;
236+
}
237+
238+
$useEnd = $phpcsFile->findNext(
234239
[
235240
T_SEMICOLON,
236241
T_COMMA,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace T;
4+
5+
use A;class B
6+
{
7+
/**
8+
* B's constructor
9+
*/
10+
public function __construct()
11+
{
12+
$a = new A();
13+
$a->b();
14+
}
15+
}

MO4/Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class UnnecessaryNamespaceUsageUnitTest extends AbstractMo4SniffUnitTest
4040
'UnnecessaryNamespaceUsageUnitTest.pass.3.inc' => [],
4141
'UnnecessaryNamespaceUsageUnitTest.pass.4.inc' => [],
4242
'UnnecessaryNamespaceUsageUnitTest.pass.5.inc' => [],
43+
'UnnecessaryNamespaceUsageUnitTest.pass.6.inc' => [],
4344
'UnnecessaryNamespaceUsageUnitTest.fail.1.inc' => [
4445
17 => 1,
4546
19 => 1,

0 commit comments

Comments
 (0)