mirror of
https://github.com/rectorphp/rector.git
synced 2025-02-24 03:35:01 +01:00
[PseudoNamespaceToNamespaceRector] fix class rename
This commit is contained in:
parent
79d665decf
commit
d55c97be88
@ -13,11 +13,6 @@ use Rector\Node\Attribute;
|
||||
use Rector\Node\NodeFactory;
|
||||
use Rector\Rector\AbstractRector;
|
||||
|
||||
/**
|
||||
* Basically inversion of https://github.com/nikic/PHP-Parser/blob/master/doc/2_Usage_of_basic_components.markdown#example-converting-namespaced-code-to-pseudo-namespaces
|
||||
*
|
||||
* Requested on SO: https://stackoverflow.com/questions/29014957/converting-pseudo-namespaced-classes-to-use-real-namespace
|
||||
*/
|
||||
final class PseudoNamespaceToNamespaceRector extends AbstractRector
|
||||
{
|
||||
/**
|
||||
@ -81,6 +76,11 @@ final class PseudoNamespaceToNamespaceRector extends AbstractRector
|
||||
$parentNode = $nameOrIdentifierNode->getAttribute(Attribute::PARENT_NODE);
|
||||
$lastNewNamePart = $newNameParts[count($newNameParts) - 1];
|
||||
|
||||
// do not rename classes
|
||||
if ($parentNode instanceof Class_) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($nameOrIdentifierNode instanceof Name) {
|
||||
if ($parentNode instanceof UseUse) {
|
||||
$this->oldToNewUseStatements[$oldName] = $lastNewNamePart;
|
||||
@ -93,7 +93,7 @@ final class PseudoNamespaceToNamespaceRector extends AbstractRector
|
||||
return $nameOrIdentifierNode;
|
||||
}
|
||||
|
||||
if ($nameOrIdentifierNode instanceof Identifier && $parentNode instanceof Class_) {
|
||||
if ($nameOrIdentifierNode instanceof Identifier) {
|
||||
$namespaceParts = $newNameParts;
|
||||
array_pop($namespaceParts);
|
||||
|
||||
|
@ -13,16 +13,18 @@ final class Test extends AbstractConfigurableRectorTestCase
|
||||
__DIR__ . '/wrong/wrong.php.inc',
|
||||
__DIR__ . '/correct/correct.php.inc'
|
||||
);
|
||||
|
||||
$this->doTestFileMatchesExpectedContent(
|
||||
__DIR__ . '/wrong/wrong2.php.inc',
|
||||
__DIR__ . '/correct/correct2.php.inc'
|
||||
);
|
||||
|
||||
$this->doTestFileMatchesExpectedContent(
|
||||
__DIR__ . '/wrong/wrong3.php.inc',
|
||||
__DIR__ . '/correct/correct3.php.inc'
|
||||
);
|
||||
$this->doTestFileMatchesExpectedContent(
|
||||
__DIR__ . '/wrong/wrong4.php.inc',
|
||||
__DIR__ . '/correct/correct4.php.inc'
|
||||
);
|
||||
}
|
||||
|
||||
protected function provideConfig(): string
|
||||
|
@ -0,0 +1,13 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace SomeNamespace;
|
||||
|
||||
class PHPUnit_TestCase
|
||||
{
|
||||
/**
|
||||
* @return Synapse|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function getSynapseMock(int $output = 2): \PHPUnit_Framework_MockObject_MockObject
|
||||
{
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace SomeNamespace;
|
||||
|
||||
class PHPUnit_TestCase
|
||||
{
|
||||
/**
|
||||
* @return Synapse|\PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function getSynapseMock(int $output = 2): \PHPUnit_Framework_MockObject_MockObject
|
||||
{
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user