Skip to content
Snippets Groups Projects
Unverified Commit f3ddc650 authored by Mitch Portier's avatar Mitch Portier Committed by GitHub
Browse files

fix(FullyQualifiedNamespace): Add support for multi-use statements (#3118337 by Arkener)

parent b9c7833a
No related branches found
No related tags found
No related merge requests found
......@@ -66,9 +66,11 @@ class FullyQualifiedNamespaceSniff implements Sniff
}
// Check if this is a use statement and ignore those.
$before = $phpcsFile->findPrevious([T_STRING, T_NS_SEPARATOR, T_WHITESPACE], $stackPtr, null, true);
$before = $phpcsFile->findPrevious([T_STRING, T_NS_SEPARATOR, T_WHITESPACE, T_COMMA, T_AS], $stackPtr, null, true);
if ($tokens[$before]['code'] === T_USE || $tokens[$before]['code'] === T_NAMESPACE) {
return $phpcsFile->findNext([T_STRING, T_NS_SEPARATOR], ($stackPtr + 1), null, true);
return $phpcsFile->findNext([T_STRING, T_NS_SEPARATOR, T_WHITESPACE, T_COMMA, T_AS], ($stackPtr + 1), null, true);
} else {
$before = $phpcsFile->findPrevious([T_STRING, T_NS_SEPARATOR, T_WHITESPACE], $stackPtr, null, true);
}
// If this is a namespaced function call then ignore this because use
......@@ -115,7 +117,13 @@ class FullyQualifiedNamespaceSniff implements Sniff
break;
}
$aliasName = false;
$aliasName = false;
// Check if we're currently in a multi-use statement.
if ($tokens[$endPtr]['code'] === T_COMMA) {
$useStatement = $endPtr;
continue;
}
$useStatement = $phpcsFile->findNext(T_USE, ($endPtr + 1));
}//end while
......
......@@ -8,6 +8,8 @@
use Test\Bar;
use Test\NotUsed;
use Test\Alias as TestAlias;
use Test\MultiLine as MultiLineAlias,
Test\MultiLineSecond;
/**
* Example.
......@@ -63,4 +65,11 @@ class Example {
}
/**
* Description.
*/
public function test8(Test\MultiLine $multiLine, Test\MultiLineSecond $multiLineSecond) {
}
}
......@@ -5,10 +5,12 @@
* Example.
*/
use Test\MultiLineSecond;
use Test\Foo;
use Test\NotUsed;
use Test\Bar;
use Test\Alias as TestAlias;
use Test\MultiLine as MultiLineAlias;
/**
* Example.
......@@ -64,4 +66,11 @@ class Example {
}
/**
* Description.
*/
public function test8(MultiLineAlias $multiLine, MultiLineSecond $multiLineSecond) {
}
}
......@@ -23,11 +23,12 @@ class FullyQualifiedNamespaceUnitTest extends CoderSniffUnitTest
switch ($testFile) {
case 'FullyQualifiedNamespaceUnitTest.inc':
return [
27 => 1,
34 => 1,
41 => 1,
55 => 1,
62 => 1,
29 => 1,
36 => 1,
43 => 1,
57 => 1,
64 => 1,
71 => 2,
];
case 'FullyQualifiedNamespaceUnitTest.1.inc':
return [16 => 1];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment