Skip to content

Commit f030db2

Browse files
committed
Sniff now ignores USE keywords used inside closures
1 parent c9dfd56 commit f030db2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

CodeSniffer/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php

+6
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
5454
{
5555
$tokens = $phpcsFile->getTokens();
5656

57+
// Ignore USE keywords inside closures.
58+
$next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true);
59+
if ($tokens[$next]['code'] === T_OPEN_PARENTHESIS) {
60+
return;
61+
}
62+
5763
// Only one USE declaration allowed per statement.
5864
$next = $phpcsFile->findNext(array(T_COMMA, T_SEMICOLON), ($stackPtr + 1));
5965
if ($tokens[$next]['code'] === T_COMMA) {

CodeSniffer/Standards/PSR2/Tests/Namespaces/UseDeclarationUnitTest.1.inc

+6
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,9 @@ use LastThing;
1313

1414
class Foo {
1515
}
16+
17+
$var = new MyClass(
18+
function () use ($foo, $bar) {
19+
return true;
20+
}
21+
);

0 commit comments

Comments
 (0)