-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Renaming] Handle Rename no namespace to namespaced class with existi…
…ng use statements (#5264) * [Renaming] Rename no namespace to namespaced class with existing use statements * Fixed 🎉 * Fixed 🎉
- Loading branch information
1 parent
7fca71b
commit e43a1ce
Showing
6 changed files
with
138 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...ixtureRenameToNamespacedClass/no_namespaced_to_namespaced_class_with_existing_use.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
use A\B; | ||
|
||
class FqnizeNamespacedWithUse | ||
{ | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Abc; | ||
|
||
use A\B; | ||
class FqnizeNamespacedWithUse | ||
{ | ||
} |
23 changes: 23 additions & 0 deletions
23
...xtureRenameToNamespacedClass/no_namespaced_to_namespaced_class_with_existing_use2.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use A\B; | ||
|
||
class FqnizeNamespacedWithUseWithDeclareStrictTypes | ||
{ | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
namespace Abc; | ||
|
||
use A\B; | ||
class FqnizeNamespacedWithUseWithDeclareStrictTypes | ||
{ | ||
} | ||
|
||
?> |
28 changes: 28 additions & 0 deletions
28
rules-tests/Renaming/Rector/Name/RenameClassRector/RenameToNamespacedClassTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\Renaming\Rector\Name\RenameClassRector; | ||
|
||
use Iterator; | ||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class RenameToNamespacedClassTest extends AbstractRectorTestCase | ||
{ | ||
#[DataProvider('provideData')] | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public static function provideData(): Iterator | ||
{ | ||
return self::yieldFilesFromDirectory(__DIR__ . '/FixtureRenameToNamespacedClass'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/rename_to_namespaced_class.php'; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
rules-tests/Renaming/Rector/Name/RenameClassRector/config/rename_to_namespaced_class.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\Renaming\Rector\Name\RenameClassRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [ | ||
'FqnizeNamespacedWithUse' => 'Abc\FqnizeNamespacedWithUse', | ||
'FqnizeNamespacedWithUseWithDeclareStrictTypes' => 'Abc\FqnizeNamespacedWithUseWithDeclareStrictTypes', | ||
]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters