Skip to content

Commit 954a1c6

Browse files
committed
Fixed bug #3053 : PSR2 incorrect fix when multiple use statements on same line do not have whitespace between them
1 parent edafaae commit 954a1c6

File tree

5 files changed

+21
-1
lines changed

5 files changed

+21
-1
lines changed

package.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
5151
-- Thanks to Thiemo Kreuz for the patch
5252
- Fixed bug #3007 : Directory exclude pattern improperly excludes directories with names that start the same
5353
-- Thanks to Steve Talbot for the patch
54+
- Fixed bug #3053 : PSR2 incorrect fix when multiple use statements on same line do not have whitespace between them
5455
- Fixed bug #3058 : Progress gets unaligned when 100% happens at the end of the available dots
5556
- Fixed bug #3059 : Squiz.Arrays.ArrayDeclaration false positive when using type casting
5657
-- Thanks to Sergei Morozov for the patch

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ public function process(File $phpcsFile, $stackPtr)
7777
$baseUse = 'use';
7878
}
7979

80+
if ($tokens[($next + 1)]['code'] !== T_WHITESPACE) {
81+
$baseUse .= ' ';
82+
}
83+
8084
$phpcsFile->fixer->replaceToken($next, ';'.$phpcsFile->eolChar.$baseUse);
8185
}
8286
} else {

src/Standards/PSR2/Tests/Namespaces/UseDeclarationUnitTest.2.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ use My\Full\Classname as Another, My\Full\NSname;
66
use function My\Full\functionname as somefunction, My\Full\otherfunction;
77
use const My\Full\constantname as someconstant, My\Full\otherconstant;
88

9+
use BarClass as Bar,FooClass,BazClass as Baz;
10+
use function My\Full\functionname as somefunction,My\Full\otherfunction;
11+
use const My\Full\constantname as someconstant,My\Full\otherconstant;
12+
913

1014
namespace AnotherProject;
1115

src/Standards/PSR2/Tests/Namespaces/UseDeclarationUnitTest.2.inc.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ use function My\Full\otherfunction;
99
use const My\Full\constantname as someconstant;
1010
use const My\Full\otherconstant;
1111

12+
use BarClass as Bar;
13+
use FooClass;
14+
use BazClass as Baz;
15+
use function My\Full\functionname as somefunction;
16+
use function My\Full\otherfunction;
17+
use const My\Full\constantname as someconstant;
18+
use const My\Full\otherconstant;
19+
1220

1321
namespace AnotherProject;
1422

src/Standards/PSR2/Tests/Namespaces/UseDeclarationUnitTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public function getErrorList($testFile='')
3434
5 => 1,
3535
6 => 1,
3636
7 => 1,
37-
12 => 1,
37+
9 => 1,
38+
10 => 1,
39+
11 => 1,
40+
16 => 1,
3841
];
3942
case 'UseDeclarationUnitTest.3.inc':
4043
return [

0 commit comments

Comments
 (0)