Skip to content

Commit

Permalink
Stop function and const being lost in UseDeclarationSniff
Browse files Browse the repository at this point in the history
  • Loading branch information
thewilkybarkid committed Aug 28, 2018
1 parent 89150c8 commit 2908150
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,18 @@ public function process(File $phpcsFile, $stackPtr)
if ($tokens[$next]['code'] === T_COMMA) {
$fix = $phpcsFile->addFixableError($error, $stackPtr, 'MultipleDeclarations');
if ($fix === true) {
$phpcsFile->fixer->replaceToken($next, ';'.$phpcsFile->eolChar.'use ');
switch ($tokens[($stackPtr + 2)]['content']) {
case 'const':
$baseUse = 'use const';
break;
case 'function':
$baseUse = 'use function';
break;
default:
$baseUse = 'use';
}

$phpcsFile->fixer->replaceToken($next, ';'.$phpcsFile->eolChar.$baseUse);
}
} else {
$closingCurly = $phpcsFile->findNext(T_CLOSE_USE_GROUP, ($next + 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ namespace MyProject;

use BarClass as Bar;
use My\Full\Classname as Another, My\Full\NSname;
use function My\Full\functionname as somefunction, My\Full\otherfunction;
use const My\Full\constantname as someconstant, My\Full\otherconstant;


namespace AnotherProject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ namespace MyProject;
use BarClass as Bar;
use My\Full\Classname as Another;
use My\Full\NSname;
use function My\Full\functionname as somefunction;
use function My\Full\otherfunction;
use const My\Full\constantname as someconstant;
use const My\Full\otherconstant;


namespace AnotherProject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public function getErrorList($testFile='')
return [
4 => 1,
5 => 1,
10 => 2,
6 => 1,
7 => 1,
12 => 2,
];
case 'UseDeclarationUnitTest.3.inc':
return [
Expand Down

0 comments on commit 2908150

Please sign in to comment.