Skip to content

Fix naming resolution issue #401

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

Merged
merged 3 commits into from
Aug 7, 2020
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
91 changes: 91 additions & 0 deletions specs/misc/name-resolution.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

declare(strict_types=1);

/*
* This file is part of the humbug/php-scoper package.
*
* Copyright (c) 2017 Théo FIDRY <[email protected]>,
* Pádraic Brady <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

return [
'meta' => [
'title' => 'Name resolution',
// Default values. If not specified will be the one used
'prefix' => 'Humbug',
'whitelist' => [],
'whitelist-global-constants' => true,
'whitelist-global-classes' => false,
'whitelist-global-functions' => true,
'registered-classes' => [],
'registered-functions' => [],
],

'Internal class & function with the same name' => [
'registered-functions' => [],
'payload' => <<<'PHP'
<?php

namespace PHPUnit\Framework;

use function assert;

abstract class TestCase extends Assert {
function __construct() {
\assert();
}
}

----
<?php

namespace Humbug\PHPUnit\Framework;

use function assert;
abstract class TestCase extends \Humbug\PHPUnit\Framework\Assert
{
function __construct()
{
\assert();
}
}

PHP
],

'Internal class & const with the same name' => [
'registered-functions' => [],
'payload' => <<<'PHP'
<?php

namespace PHPUnit\Framework;

use const SORT_NUMERIC;

abstract class TestCase extends SORT_NUMERIC {
function __construct() {
echo SORT_NUMERIC;
}
}

----
<?php

namespace Humbug\PHPUnit\Framework;

use const SORT_NUMERIC;
abstract class TestCase extends \Humbug\PHPUnit\Framework\SORT_NUMERIC
{
function __construct()
{
echo \SORT_NUMERIC;
}
}

PHP
],
];
6 changes: 4 additions & 2 deletions src/PhpParser/NodeVisitor/UseStmt/UseStmtCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ private function find(array $useStatements, bool $isFunctionName, bool $isConsta
continue;
}

// Match the alias
return UseStmtManipulator::getOriginalName($useStatement);
if (Use_::TYPE_NORMAL === $use_->type) {
// Match the alias
return UseStmtManipulator::getOriginalName($useStatement);
}
}
}
}
Expand Down