Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PSR2.Namespaces.UseDeclaration does not properly fix "use function" and "use const" statements #2143

Merged
merged 1 commit into from
Aug 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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