File tree Expand file tree Collapse file tree
tests/Application/ApplicationFileProcessor Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -86,6 +86,12 @@ private function importNameAndCollectNewUseStatement(
8686 // make use of existing use import
8787 $ nameInUse = $ this ->resolveNameInUse ($ fullyQualified , $ currentUses );
8888 if ($ nameInUse instanceof Name) {
89+ // already written with this name, nothing to change
90+ $ originalName = $ fullyQualified ->getAttribute (AttributeKey::ORIGINAL_NAME );
91+ if ($ originalName instanceof Name && $ originalName ->toString () === $ nameInUse ->toString ()) {
92+ return null ;
93+ }
94+
8995 $ nameInUse ->setAttribute (AttributeKey::NAMESPACED_NAME , $ fullyQualified ->toString ());
9096 return $ nameInUse ;
9197 }
Original file line number Diff line number Diff line change @@ -43,6 +43,21 @@ public function testCleanFileIsCachedAsUnchanged(): void
4343 $ this ->assertFalse ($ this ->changedFilesDetector ->hasFileChanged ($ filePath ));
4444 }
4545
46+ public function testShortNameNextToSameShortNameAliasIsCachedAsUnchanged (): void
47+ {
48+ self ::$ rectorConfig = null ;
49+ $ this ->bootFromConfigFiles ([__DIR__ . '/config-import-names.php ' ]);
50+ $ applicationFileProcessor = $ this ->make (ApplicationFileProcessor::class);
51+ $ changedFilesDetector = $ this ->make (ChangedFilesDetector::class);
52+ $ changedFilesDetector ->clear ();
53+
54+ $ filePath = __DIR__ . '/Source/ImportedNextToSameShortNameAlias.php ' ;
55+
56+ $ applicationFileProcessor ->processFiles ([$ filePath ], new Configuration (isDryRun: true ));
57+
58+ $ this ->assertFalse ($ changedFilesDetector ->hasFileChanged ($ filePath ));
59+ }
60+
4661 public function testOnlyRuleRunCachesUnderOwnScopeWithoutPoisoningFullRun (): void
4762 {
4863 $ filePath = __DIR__ . '/Source/CleanFile.php ' ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Rector \Tests \Application \ApplicationFileProcessor \Source ;
6+
7+ use PhpParser \Node \Expr \BinaryOp \Plus ;
8+ use PhpParser \Node \Expr \AssignOp \Plus as AssignPlus ;
9+
10+ final class ImportedNextToSameShortNameAlias
11+ {
12+ public function run (Plus $ plus , AssignPlus $ assignPlus ): void
13+ {
14+ }
15+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use Rector \Config \RectorConfig ;
6+
7+ return static function (RectorConfig $ rectorConfig ): void {
8+ $ rectorConfig ->cacheDirectory (sys_get_temp_dir () . '/_rector_import_names_test ' );
9+ $ rectorConfig ->importNames ();
10+ };
You can’t perform that action at this time.
0 commit comments