Skip to content

Commit 82df49e

Browse files
authored
Fix naming resolution issue (#401)
1 parent aecad33 commit 82df49e

File tree

2 files changed

+95
-2
lines changed

2 files changed

+95
-2
lines changed

specs/misc/name-resolution.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of the humbug/php-scoper package.
7+
*
8+
* Copyright (c) 2017 Théo FIDRY <[email protected]>,
9+
* Pádraic Brady <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
return [
16+
'meta' => [
17+
'title' => 'Name resolution',
18+
// Default values. If not specified will be the one used
19+
'prefix' => 'Humbug',
20+
'whitelist' => [],
21+
'whitelist-global-constants' => true,
22+
'whitelist-global-classes' => false,
23+
'whitelist-global-functions' => true,
24+
'registered-classes' => [],
25+
'registered-functions' => [],
26+
],
27+
28+
'Internal class & function with the same name' => [
29+
'registered-functions' => [],
30+
'payload' => <<<'PHP'
31+
<?php
32+
33+
namespace PHPUnit\Framework;
34+
35+
use function assert;
36+
37+
abstract class TestCase extends Assert {
38+
function __construct() {
39+
\assert();
40+
}
41+
}
42+
43+
----
44+
<?php
45+
46+
namespace Humbug\PHPUnit\Framework;
47+
48+
use function assert;
49+
abstract class TestCase extends \Humbug\PHPUnit\Framework\Assert
50+
{
51+
function __construct()
52+
{
53+
\assert();
54+
}
55+
}
56+
57+
PHP
58+
],
59+
60+
'Internal class & const with the same name' => [
61+
'registered-functions' => [],
62+
'payload' => <<<'PHP'
63+
<?php
64+
65+
namespace PHPUnit\Framework;
66+
67+
use const SORT_NUMERIC;
68+
69+
abstract class TestCase extends SORT_NUMERIC {
70+
function __construct() {
71+
echo SORT_NUMERIC;
72+
}
73+
}
74+
75+
----
76+
<?php
77+
78+
namespace Humbug\PHPUnit\Framework;
79+
80+
use const SORT_NUMERIC;
81+
abstract class TestCase extends \Humbug\PHPUnit\Framework\SORT_NUMERIC
82+
{
83+
function __construct()
84+
{
85+
echo \SORT_NUMERIC;
86+
}
87+
}
88+
89+
PHP
90+
],
91+
];

src/PhpParser/NodeVisitor/UseStmt/UseStmtCollection.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,10 @@ private function find(array $useStatements, bool $isFunctionName, bool $isConsta
142142
continue;
143143
}
144144

145-
// Match the alias
146-
return UseStmtManipulator::getOriginalName($useStatement);
145+
if (Use_::TYPE_NORMAL === $use_->type) {
146+
// Match the alias
147+
return UseStmtManipulator::getOriginalName($useStatement);
148+
}
147149
}
148150
}
149151
}

0 commit comments

Comments
 (0)