Skip to content

Commit

Permalink
Account for PHP case-insensitiveness (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
theofidry authored Oct 7, 2017
1 parent 01ac291 commit 866a9a3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
37 changes: 37 additions & 0 deletions specs/misc.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,41 @@

PHP
,

[
'spec' => <<<'SPEC'
When resolving fully qualified class names, keep in mind that classes are case insensitive in PHP.
SPEC
,
'payload' => <<<'PHP'
<?php
namespace Foo {
class X {}
}
namespace {
use FOO\x as Y;
use Foo\stdClass;
var_dump(new y());
var_dump(new STDCLASS());
}
----
<?php
namespace Humbug\Foo {
class X
{
}
}
namespace {
use Humbug\FOO\x as Y;
use Humbug\Foo\stdClass;
\var_dump(new \Humbug\FOO\x());
\var_dump(new \Humbug\Foo\stdClass());
}

PHP
],
];
9 changes: 2 additions & 7 deletions src/NodeVisitor/Collection/UseStmtCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,19 @@ public function add(?Name $namespaceName, Use_ $node): void
*/
public function findStatementForNode(?Name $namespaceName, Name $node): ?Name
{
$name = $node->getFirst();
$name = strtolower($node->getFirst());

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

foreach ($useStatements as $use_) {
foreach ($use_->uses as $useStatement) {
if ($useStatement instanceof UseUse) {
if ($name === $useStatement->alias) {
if ($name === strtolower($useStatement->alias)) {
// Match the alias
return $useStatement->name;
} elseif (null !== $useStatement->alias) {
continue;
}

if ($name === $useStatement->name->getLast() && $useStatement->alias === null) {
// Match a simple use statement
return $useStatement->name;
}
}
}
}
Expand Down

0 comments on commit 866a9a3

Please sign in to comment.