Skip to content

Commit a60d541

Browse files
author
Steffen Ritter
committed
fixed namespace sniff crash when no namespace in file
1 parent 568c008 commit a60d541

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Sniffs/Formatting/UnnecessaryNamespaceUsageSniff.php

+5
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ protected function getNamespace(PHP_CodeSniffer_File $phpcsFile, $start, $end)
228228
$end,
229229
true
230230
);
231+
232+
if (false === $namespaceStart) {
233+
return '';
234+
}
235+
231236
$namespaceEnd = $phpcsFile->findNext(
232237
[T_NS_SEPARATOR, T_STRING],
233238
$namespaceStart + 1,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
4+
class Bazz
5+
{
6+
7+
}

Tests/Formatting/UnnecessaryNamespaceUsageUnitTest.php

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ protected function getWarningList($testFile = '')
6060
switch ($testFile) {
6161
case 'UnnecessaryNamespaceUsageUnitTest.pass.inc':
6262
case 'UnnecessaryNamespaceUsageUnitTest.pass.2.inc':
63+
case 'UnnecessaryNamespaceUsageUnitTest.pass.3.inc':
6364
return array();
6465
case 'UnnecessaryNamespaceUsageUnitTest.fail.inc':
6566
return array(

0 commit comments

Comments
 (0)