Skip to content

Commit

Permalink
Fixed bug #3053 : PSR2 incorrect fix when multiple use statements on …
Browse files Browse the repository at this point in the history
…same line do not have whitespace between them
  • Loading branch information
gsherwood committed Sep 24, 2020
1 parent dd20321 commit 4377de2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Standards/PSR2/Sniffs/Namespaces/UseDeclarationSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public function process(File $phpcsFile, $stackPtr)
$baseUse = 'use';
}

if ($tokens[($next + 1)]['code'] !== T_WHITESPACE) {
$baseUse .= ' ';
}

$phpcsFile->fixer->replaceToken($next, ';'.$phpcsFile->eolChar.$baseUse);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ 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;

use BarClass as Bar,FooClass,BazClass as Baz;
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 @@ -9,6 +9,14 @@ use function My\Full\otherfunction;
use const My\Full\constantname as someconstant;
use const My\Full\otherconstant;

use BarClass as Bar;
use FooClass;
use BazClass as Baz;
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 @@ -34,7 +34,10 @@ public function getErrorList($testFile='')
5 => 1,
6 => 1,
7 => 1,
12 => 1,
9 => 1,
10 => 1,
11 => 1,
16 => 1,
];
case 'UseDeclarationUnitTest.3.inc':
return [
Expand Down

0 comments on commit 4377de2

Please sign in to comment.