Skip to content

Commit 866a9a3

Browse files
authored
Account for PHP case-insensitiveness (#118)
1 parent 01ac291 commit 866a9a3

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

specs/misc.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,41 @@
4141

4242
PHP
4343
,
44+
45+
[
46+
'spec' => <<<'SPEC'
47+
When resolving fully qualified class names, keep in mind that classes are case insensitive in PHP.
48+
SPEC
49+
,
50+
'payload' => <<<'PHP'
51+
<?php
52+
53+
namespace Foo {
54+
class X {}
55+
}
56+
57+
namespace {
58+
use FOO\x as Y;
59+
use Foo\stdClass;
60+
61+
var_dump(new y());
62+
var_dump(new STDCLASS());
63+
}
64+
----
65+
<?php
66+
67+
namespace Humbug\Foo {
68+
class X
69+
{
70+
}
71+
}
72+
namespace {
73+
use Humbug\FOO\x as Y;
74+
use Humbug\Foo\stdClass;
75+
\var_dump(new \Humbug\FOO\x());
76+
\var_dump(new \Humbug\Foo\stdClass());
77+
}
78+
79+
PHP
80+
],
4481
];

src/NodeVisitor/Collection/UseStmtCollection.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,19 @@ public function add(?Name $namespaceName, Use_ $node): void
5757
*/
5858
public function findStatementForNode(?Name $namespaceName, Name $node): ?Name
5959
{
60-
$name = $node->getFirst();
60+
$name = strtolower($node->getFirst());
6161

6262
$useStatements = $this->nodes[(string) $namespaceName] ?? [];
6363

6464
foreach ($useStatements as $use_) {
6565
foreach ($use_->uses as $useStatement) {
6666
if ($useStatement instanceof UseUse) {
67-
if ($name === $useStatement->alias) {
67+
if ($name === strtolower($useStatement->alias)) {
6868
// Match the alias
6969
return $useStatement->name;
7070
} elseif (null !== $useStatement->alias) {
7171
continue;
7272
}
73-
74-
if ($name === $useStatement->name->getLast() && $useStatement->alias === null) {
75-
// Match a simple use statement
76-
return $useStatement->name;
77-
}
7873
}
7974
}
8075
}

0 commit comments

Comments
 (0)