Skip to content

Commit fd78875

Browse files
authored
Fix group use bug (#413)
1 parent 0ef8095 commit fd78875

File tree

5 files changed

+64
-16
lines changed

5 files changed

+64
-16
lines changed

specs/use/use-class-group.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
use A\{B\C, D};
3333
use \A\B\{C\D as ABCD, E};
3434
35+
B::class;
36+
C::class;
37+
D::class;
38+
ABCD::class;
39+
E::class;
40+
3541
----
3642
<?php
3743
@@ -42,6 +48,11 @@
4248
use Humbug\A\D;
4349
use Humbug\A\B\C\D as ABCD;
4450
use Humbug\A\B\E;
51+
\Humbug\A\B::class;
52+
\Humbug\A\B\C::class;
53+
\Humbug\A\D::class;
54+
\Humbug\A\B\C\D::class;
55+
\Humbug\A\B\E::class;
4556

4657
PHP
4758
,
@@ -79,6 +90,12 @@
7990
use A\{B\C, D};
8091
use \A\B\{C\G, E};
8192
93+
B::class;
94+
C::class;
95+
D::class;
96+
G::class;
97+
E::class;
98+
8299
----
83100
<?php
84101
@@ -89,6 +106,11 @@
89106
use Humbug\A\D;
90107
use Humbug\A\B\C\G;
91108
use Humbug\A\B\E;
109+
\Humbug\A\B::class;
110+
\Humbug\A\B\C::class;
111+
\Humbug\A\D::class;
112+
\Humbug\A\B\C\G::class;
113+
\Humbug\A\B\E::class;
92114

93115
PHP
94116
],

specs/use/use-const-group.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
use const A\{B\C, D};
3333
use const \A\B\{C\D as ABCD, E};
3434
35+
B;
36+
C;
37+
D;
38+
ABCD;
39+
E;
40+
3541
----
3642
<?php
3743
@@ -42,6 +48,11 @@
4248
use const Humbug\A\D;
4349
use const Humbug\A\B\C\D as ABCD;
4450
use const Humbug\A\B\E;
51+
\Humbug\A\B;
52+
\Humbug\A\B\C;
53+
\Humbug\A\D;
54+
\Humbug\A\B\C\D;
55+
\Humbug\A\B\E;
4556

4657
PHP
4758
,

specs/use/use-func-group.php

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,31 @@
2828
<<<'PHP'
2929
<?php
3030
31-
use A\{b};
32-
use A\{B\c, d};
33-
use \A\B\{C\g, e};
31+
use function A\{b};
32+
use function A\{B\c, d};
33+
use function \A\B\{C\g, e};
34+
35+
b();
36+
c();
37+
d();
38+
g();
39+
e();
3440
3541
----
3642
<?php
3743
3844
namespace Humbug;
3945
40-
use Humbug\A\b;
41-
use Humbug\A\B\c;
42-
use Humbug\A\d;
43-
use Humbug\A\B\C\g;
44-
use Humbug\A\B\e;
46+
use function Humbug\A\b;
47+
use function Humbug\A\B\c;
48+
use function Humbug\A\d;
49+
use function Humbug\A\B\C\g;
50+
use function Humbug\A\B\e;
51+
\Humbug\A\b();
52+
\Humbug\A\B\c();
53+
\Humbug\A\d();
54+
\Humbug\A\B\C\g();
55+
\Humbug\A\B\e();
4556

4657
PHP
4758
,

specs/use/use-mix-group.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
3131
use A\B\{C\D, function b\c, const D};
3232
33+
D::class;
34+
c();
35+
D;
36+
3337
----
3438
<?php
3539
@@ -38,6 +42,9 @@
3842
use Humbug\A\B\C\D;
3943
use function Humbug\A\B\b\c;
4044
use const Humbug\A\B\D;
45+
\Humbug\A\B\C\D::class;
46+
\Humbug\A\B\b\c();
47+
\Humbug\A\B\D;
4148

4249
PHP
4350
,

src/PhpParser/NodeVisitor/UseStmt/UseStmtCollection.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ public function add(?Name $namespaceName, Use_ $use): void
6262
* use Y;
6363
*
6464
* will return the use statement for `Bar\Foo`.
65-
*
66-
* @param Name|null $namespaceName
67-
* @param Name $node
68-
*
69-
* @return null|Name
7065
*/
7166
public function findStatementForNode(?Name $namespaceName, Name $node): ?Name
7267
{
@@ -125,24 +120,26 @@ private function find(array $useStatements, bool $isFunctionName, bool $isConsta
125120
continue;
126121
}
127122

123+
$type = Use_::TYPE_UNKNOWN !== $use_->type ? $use_->type : $useStatement->type;
124+
128125
if ($name === $useStatement->getAlias()->toLowerString()) {
129126
if ($isFunctionName) {
130-
if (Use_::TYPE_FUNCTION === $use_->type) {
127+
if (Use_::TYPE_FUNCTION === $type) {
131128
return UseStmtManipulator::getOriginalName($useStatement);
132129
}
133130

134131
continue;
135132
}
136133

137134
if ($isConstantName) {
138-
if (Use_::TYPE_CONSTANT === $use_->type) {
135+
if (Use_::TYPE_CONSTANT === $type) {
139136
return UseStmtManipulator::getOriginalName($useStatement);
140137
}
141138

142139
continue;
143140
}
144141

145-
if (Use_::TYPE_NORMAL === $use_->type) {
142+
if (Use_::TYPE_NORMAL === $type) {
146143
// Match the alias
147144
return UseStmtManipulator::getOriginalName($useStatement);
148145
}

0 commit comments

Comments
 (0)