mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-22 02:36:52 +01:00
Fix fqn doc with alraedy PHP imported namespace (#1891)
Fix fqn doc with alraedy PHP imported namespace
This commit is contained in:
commit
ca1cff688c
@ -13,12 +13,16 @@ use Rector\CodingStyle\Application\UseAddingCommander;
|
||||
use Rector\CodingStyle\Imports\AliasUsesResolver;
|
||||
use Rector\CodingStyle\Imports\ShortNameResolver;
|
||||
use Rector\CodingStyle\Naming\ClassNaming;
|
||||
use Rector\CodingStyle\Tests\Rector\Namespace_\ImportFullyQualifiedNamesRector\ImportFullyQualifiedNamesRectorTest;
|
||||
use Rector\NodeTypeResolver\Node\AttributeKey;
|
||||
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockManipulator;
|
||||
use Rector\Rector\AbstractRector;
|
||||
use Rector\RectorDefinition\CodeSample;
|
||||
use Rector\RectorDefinition\RectorDefinition;
|
||||
|
||||
/**
|
||||
* @see ImportFullyQualifiedNamesRectorTest
|
||||
*/
|
||||
final class ImportFullyQualifiedNamesRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
|
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture;
|
||||
|
||||
final class IncludeUsedLocalClass
|
||||
{
|
||||
/**
|
||||
* @var \Rector\CodingStyle\Tests\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture\SharedShortName
|
||||
*/
|
||||
private $join;
|
||||
|
||||
public function __construct(SharedShortName $join)
|
||||
{
|
||||
}
|
||||
|
||||
public function getJoin(): SharedShortName
|
||||
{
|
||||
return $this->join;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
-----
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rector\CodingStyle\Tests\Rector\Namespace_\ImportFullyQualifiedNamesRector\Fixture;
|
||||
|
||||
final class IncludeUsedLocalClass
|
||||
{
|
||||
/**
|
||||
* @var SharedShortName
|
||||
*/
|
||||
private $join;
|
||||
|
||||
public function __construct(SharedShortName $join)
|
||||
{
|
||||
}
|
||||
|
||||
public function getJoin(): SharedShortName
|
||||
{
|
||||
return $this->join;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -22,6 +22,7 @@ final class ImportFullyQualifiedNamesRectorTest extends AbstractRectorTestCase
|
||||
// same short class with namespace
|
||||
yield [__DIR__ . '/Fixture/same_namespaced_class.php.inc'];
|
||||
yield [__DIR__ . '/Fixture/skip_same_namespaced_used_class.php.inc'];
|
||||
yield [__DIR__ . '/Fixture/include_used_local_class.php.inc'];
|
||||
|
||||
yield [__DIR__ . '/Fixture/fixture.php.inc'];
|
||||
yield [__DIR__ . '/Fixture/double_import.php.inc'];
|
||||
|
@ -712,13 +712,17 @@ final class DocBlockManipulator
|
||||
$namespaceName = $node->getAttribute(AttributeKey::NAMESPACE_NAME);
|
||||
|
||||
// the class in the same namespace as different file can se used in this code, the short names would colide → skip
|
||||
if (class_exists($namespaceName . '\\' . $shortName)) {
|
||||
if ($this->isCurrentNamespaceSameShortClassAlreadyUsed(
|
||||
$node,
|
||||
$namespaceName . '\\' . $shortName,
|
||||
$shortName
|
||||
)) {
|
||||
return $attributeAwareNode;
|
||||
$currentNamespaceShortName = $namespaceName . '\\' . $shortName;
|
||||
|
||||
if (class_exists($currentNamespaceShortName)) {
|
||||
if ($currentNamespaceShortName !== $fullyQualifiedName) {
|
||||
if ($this->isCurrentNamespaceSameShortClassAlreadyUsed(
|
||||
$node,
|
||||
$currentNamespaceShortName,
|
||||
$shortName
|
||||
)) {
|
||||
return $attributeAwareNode;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -751,11 +755,11 @@ final class DocBlockManipulator
|
||||
|
||||
$joinChar = '|'; // default
|
||||
if (Strings::contains($type, '|')) { // intersection
|
||||
$types = explode('|', $type);
|
||||
$joinChar = '|';
|
||||
$types = explode($joinChar, $type);
|
||||
} elseif (Strings::contains($type, '&')) { // union
|
||||
$types = explode('&', $type);
|
||||
$joinChar = '&';
|
||||
$types = explode($joinChar, $type);
|
||||
} else {
|
||||
$types = [$type];
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user