Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for PHP case-insensitiveness #118

Merged
merged 1 commit into from
Oct 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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