Repository: phpactor/phpactor (php)

Issue:
Make "Import all uresolved classes" the first option

Pull request description:
Make Import all classes first option
Fixes #1818

Patch:
diff --git a/lib/Extension/ClassMover/Application/ClassCopy.php b/lib/Extension/ClassMover/Application/ClassCopy.php
index bbd64229..e3a81981 100644
--- a/lib/Extension/ClassMover/Application/ClassCopy.php
+++ b/lib/Extension/ClassMover/Application/ClassCopy.php
@@ -56,6 +56,9 @@ class ClassCopy
     public function copyFile(ClassCopyLogger $logger, string $srcPath, string $destPath): void
     {
         $srcPath = Phpactor::normalizePath($srcPath);
+        if (substr($destPath, -1, 1) === '/') {
+            $destPath = $destPath . basename($srcPath);
+        }
 
         if (false === Glob::isDynamic($srcPath) && !file_exists($srcPath)) {
             throw new RuntimeException(sprintf(
diff --git a/lib/Extension/ClassMover/Application/ClassMover.php b/lib/Extension/ClassMover/Application/ClassMover.php
index 2a55c886..e13d2fee 100644
--- a/lib/Extension/ClassMover/Application/ClassMover.php
+++ b/lib/Extension/ClassMover/Application/ClassMover.php
@@ -95,6 +95,9 @@ class ClassMover
     {
         $filesystem = $this->filesystemRegistry->get($filesystemName);
         $destPath = Phpactor::normalizePath($destPath);
+        if (substr($destPath, -1, 1) === '/') {
+            $destPath = $destPath . basename($srcPath);
+        }
 
         $srcPath = $filesystem->createPath($srcPath);
         $destPath = $filesystem->createPath($destPath);
diff --git a/lib/Extension/LanguageServerCodeTransform/CodeAction/ImportNameProvider.php b/lib/Extension/LanguageServerCodeTransform/CodeAction/ImportNameProvider.php
index 0c1f305b..f0644e90 100644
--- a/lib/Extension/LanguageServerCodeTransform/CodeAction/ImportNameProvider.php
+++ b/lib/Extension/LanguageServerCodeTransform/CodeAction/ImportNameProvider.php
@@ -42,7 +42,7 @@ class ImportNameProvider implements CodeActionProvider, DiagnosticsProvider
             }
 
             if (count($actions) > 1) {
-                $actions[] = $this->addImportAllAction($item);
+                array_unshift($actions, $this->addImportAllAction($item));
             }
 
             return $actions;


Test patch:
diff --git a/lib/Extension/LanguageServerCodeTransform/Tests/Unit/CodeAction/ImportNameProviderTest.php b/lib/Extension/LanguageServerCodeTransform/Tests/Unit/CodeAction/ImportNameProviderTest.php
index 3805107b..ca423f0e 100644
--- a/lib/Extension/LanguageServerCodeTransform/Tests/Unit/CodeAction/ImportNameProviderTest.php
+++ b/lib/Extension/LanguageServerCodeTransform/Tests/Unit/CodeAction/ImportNameProviderTest.php
@@ -185,9 +185,9 @@ class ImportNameProviderTest extends IntegrationTestCase
                 EOT
             , function (array $codeActions, array $diagnostics): void {
                 self::assertCount(3, $codeActions);
-                self::assertEquals('Import function "explode"', $codeActions[0]->title);
-                self::assertEquals('Import function "array_keys"', $codeActions[1]->title);
-                self::assertEquals('Import all unresolved names', $codeActions[2]->title);
+                self::assertEquals('Import function "explode"', $codeActions[1]->title);
+                self::assertEquals('Import function "array_keys"', $codeActions[2]->title);
+                self::assertEquals('Import all unresolved names', $codeActions[0]->title);
                 self::assertCount(2, $diagnostics);
             }, true
         ];
diff --git a/tests/System/Extension/ClassMover/Command/ClassCopyCommandTest.php b/tests/System/Extension/ClassMover/Command/ClassCopyCommandTest.php
index d7f606cb..83474b72 100644
--- a/tests/System/Extension/ClassMover/Command/ClassCopyCommandTest.php
+++ b/tests/System/Extension/ClassMover/Command/ClassCopyCommandTest.php
@@ -63,6 +63,12 @@ class ClassCopyCommandTest extends SystemTestCase
                     'lib/Hello/World/Foobar.php' => true,
                 ],
             ],
+            'Copy file to folder' => [
+                'class:copy lib/Aardvark/Edentate.php lib/Hello/World/',
+                [
+                    'lib/Hello/World/Edentate.php' => true,
+                ],
+            ],
             'Copy file force' => [
                 'class:copy lib/Aardvark/Edentate.php lib/Foobar.php --type=file',
             ],
diff --git a/tests/System/Extension/ClassMover/Command/ClassMoveCommandTest.php b/tests/System/Extension/ClassMover/Command/ClassMoveCommandTest.php
index 5fd13a5a..eff852e0 100644
--- a/tests/System/Extension/ClassMover/Command/ClassMoveCommandTest.php
+++ b/tests/System/Extension/ClassMover/Command/ClassMoveCommandTest.php
@@ -53,6 +53,12 @@ class ClassMoveCommandTest extends SystemTestCase
                     'lib/Hello/World/Foobar.php' => true,
                 ],
             ],
+            'Move file to folder' => [
+                'class:move lib/Aardvark/Edentate.php lib/Hello/World/',
+                [
+                    'lib/Hello/World/Edentate.php' => true,
+                ],
+            ],
             'Move file force' => [
                 'class:move lib/Aardvark/Edentate.php lib/Foobar.php --type=file',
             ],