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 edafaae commit 954a1c6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
-- Thanks to Thiemo Kreuz for the patch
- Fixed bug #3007 : Directory exclude pattern improperly excludes directories with names that start the same
-- Thanks to Steve Talbot for the patch
- Fixed bug #3053 : PSR2 incorrect fix when multiple use statements on same line do not have whitespace between them
- Fixed bug #3058 : Progress gets unaligned when 100% happens at the end of the available dots
- Fixed bug #3059 : Squiz.Arrays.ArrayDeclaration false positive when using type casting
-- Thanks to Sergei Morozov for the patch
Expand Down
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 954a1c6

Please sign in to comment.