Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions autoload/phpactor/input/list.vim
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
function! phpactor#input#list#strategy()
" Hack to not use FZF in collections
" see https://github.com/phpactor/phpactor/pull/843
if g:_phpactorRpcActionIsCollection == v:true
return "phpactor#input#list#inputlist"
endif

if has_key(g:, 'phpactorInputListStrategy')
return g:phpactorInputListStrategy
endif
Expand Down
145 changes: 73 additions & 72 deletions composer.lock

Large diffs are not rendered by default.

16 changes: 0 additions & 16 deletions doc/refactorings.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ Fixes:
- [Generate Method](#generate-method)
- [Implement Contracts](#implement-contracts)
- [Import Class](#import-class)
- [Import Missing Classes](#import-missing-classes)
- [Override Method](#override-method)

Generation:
Expand Down Expand Up @@ -893,21 +892,6 @@ class Hello
}
```

Import Missing Classes
----------------------

Import all missing classes in the current file.

- **Command**: **RPC Only**
- **VIM plugin**: _Class context menu > Import Missing_
- **VIM function**:`:call phpactor#ImportMissingClasses()`

### Motivation

You may copy and paste some code from one file to another and subsequently
need to import all the foreign classes into the current namespace. This
refactoring will identify all unresolvable classes and import them.

Override Method
---------------

Expand Down
10 changes: 6 additions & 4 deletions lib/Extension/ClassMover/Application/ClassMover.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public function __construct(
public function getRelatedFiles(string $src): array
{
try {
return array_filter($this->pathFinder->destinationsFor($src), function (string $filePath) {
return (bool) file_exists($filePath);
});
return array_filter($this->pathFinder->destinationsFor($src), function (string $filePath) {
return (bool) file_exists($filePath);
});
} catch (NoMatchingSourceException $e) {
// TODO: Make pathfinder return it's own exception here, this is the class-to-file exception
return [];
Expand All @@ -70,7 +70,8 @@ public function move(
string $src,
string $dest,
bool $moveRelatedFiles
): void {
): void
{
$srcPath = $this->classFileNormalizer->normalizeToFile($src);
$destPath = $this->classFileNormalizer->normalizeToFile($dest);

Expand All @@ -92,6 +93,7 @@ public function moveFile(ClassMoverLogger $logger, string $filesystemName, strin
{
$srcPath = Phpactor::normalizePath($srcPath);
foreach (FilesystemHelper::globSourceDestination($srcPath, $destPath) as $globSrc => $globDest) {

foreach ($this->expandRelatedPaths($globSrc, $globDest, $moveRelatedFiles) as $oldPath => $newPath) {
try {
$this->doMoveFile($logger, $filesystemName, $oldPath, $newPath);
Expand Down
16 changes: 8 additions & 8 deletions lib/Extension/ClassMover/Rpc/ClassMoveHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Phpactor\Extension\ClassMover\Rpc;

use Phpactor\Extension\Rpc\Response\Input\ChoiceInput;
use Phpactor\Extension\Rpc\Response\Input\ListInput;
use Phpactor\MapResolver\Resolver;
use Phpactor\Extension\Rpc\Response\OpenFileResponse;
use Phpactor\Extension\Rpc\Response\Input\TextInput;
Expand Down Expand Up @@ -69,7 +71,7 @@ public function handle(array $arguments)
));

if (
null !== $arguments[self::PARAM_DEST_PATH] &&
null !== $arguments[self::PARAM_DEST_PATH] &&
null === $arguments[self::PARAM_CONFIRMED]
) {
$this->requireInput(ConfirmInput::fromNameAndLabel(
Expand All @@ -81,17 +83,15 @@ public function handle(array $arguments)
}

if (
null === $arguments[self::PARAM_ADDITIONAL_MOVE_CONFIRM] &&
$arguments[self::PARAM_DEST_PATH] &&
null === $arguments[self::PARAM_ADDITIONAL_MOVE_CONFIRM] &&
$arguments[self::PARAM_DEST_PATH] &&
$related = $this->classMove->getRelatedFiles($arguments[self::PARAM_SOURCE_PATH])
) {
$this->requireInput(ConfirmInput::fromNameAndLabel(
self::PARAM_ADDITIONAL_MOVE_CONFIRM,
sprintf(
"This class has the following related files:\n\n - %s\n\nMove these too? ",
implode("\n - ", $related)
)
));
sprintf("This class has the following related files:\n\n - %s\n\nMove these too? ",
implode("\n - ", $related)
)));
}

if ($this->hasMissingArguments($arguments)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/Extension/CodeTransformExtra/Application/ClassNew1.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

class ClassNew1
{
}
}
18 changes: 3 additions & 15 deletions lib/Extension/CodeTransformExtra/CodeTransformExtraExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
use Phpactor\CodeTransform\Adapter\TolerantParser\Refactor\TolerantImportClass;
use Phpactor\CodeTransform\Adapter\TolerantParser\Refactor\TolerantRenameVariable;
use Phpactor\CodeTransform\Adapter\WorseReflection\GenerateFromExisting\InterfaceFromExistingGenerator;
use Phpactor\CodeTransform\Adapter\WorseReflection\Helper\WorseUnresolvableClassNameFinder;
use Phpactor\CodeTransform\Adapter\WorseReflection\Refactor\WorseExtractConstant;
use Phpactor\CodeTransform\Adapter\WorseReflection\Refactor\WorseExtractMethod;
use Phpactor\CodeTransform\Adapter\WorseReflection\Refactor\WorseGenerateAccessor;
Expand All @@ -23,10 +22,12 @@
use Phpactor\CodeTransform\Adapter\WorseReflection\Transformer\AddMissingProperties;
use Phpactor\CodeTransform\Adapter\WorseReflection\Transformer\CompleteConstructor;
use Phpactor\CodeTransform\Adapter\WorseReflection\Transformer\ImplementContracts;
use Phpactor\CodeTransform\CodeTransform;
use Phpactor\CodeTransform\Domain\Generators;
use Phpactor\CodeTransform\Domain\Transformers;
use Phpactor\Container\Container;
use Phpactor\Container\ContainerBuilder;
use Phpactor\Container\Extension;
use Phpactor\Extension\CodeTransformExtra\Rpc\ImportMissingClassesHandler;
use Phpactor\Extension\CodeTransform\CodeTransformExtension;
use Phpactor\Extension\Logger\LoggingExtension;
use Phpactor\Extension\Rpc\RpcExtension;
Expand Down Expand Up @@ -260,12 +261,6 @@ private function registerRefactorings(ContainerBuilder $container)
$container->register('code_transform.refactor.change_visiblity', function (Container $container) {
return new TolerantChangeVisiblity();
});

$container->register('code_transform.helper.unresolvable_class_name_finder', function (Container $container) {
return new WorseUnresolvableClassNameFinder(
$container->get(WorseReflectionExtension::SERVICE_REFLECTOR)
);
});
}

private function registerUpdater(ContainerBuilder $container)
Expand Down Expand Up @@ -340,13 +335,6 @@ private function registerRpc(ContainerBuilder $container)
$container->get('code_transform.refactor.extract_expression')
);
}, [ RpcExtension::TAG_RPC_HANDLER => ['name' => ExtractExpressionHandler::NAME] ]);

$container->register('code_transform.rpc.handler.import_unresolvable_classes', function (Container $container) {
return new ImportMissingClassesHandler(
$container->get(RpcExtension::SERVICE_REQUEST_HANDLER),
$container->get('code_transform.helper.unresolvable_class_name_finder')
);
}, [ RpcExtension::TAG_RPC_HANDLER => ['name' => ImportMissingClassesHandler::NAME] ]);
}

private function registerGenerators(ContainerBuilder $container)
Expand Down

This file was deleted.

7 changes: 0 additions & 7 deletions lib/Extension/ContextMenu/menu.json
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,6 @@
"source": "%source%"
}
},
"import_missing_classes": {
"action": "import_missing_classes",
"parameters": {
"path": "%current_path%",
"source": "%source%"
}
},
"hover": {
"action": "hover",
"parameters": {
Expand Down
12 changes: 0 additions & 12 deletions plugin/phpactor.vim
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ let g:phpactorInitialCwd = getcwd()
let g:phpactorCompleteLabelTruncateLength=50
let g:_phpactorCompletionMeta = {}

" hack to avoid calling fzf strategy when using a collection
" see: https://github.com/phpactor/phpactor/pull/843
let g:_phpactorRpcActionIsCollection = v:false

if !exists('g:phpactorPhpBin')
let g:phpactorPhpBin = 'php'
endif
Expand Down Expand Up @@ -219,14 +215,8 @@ endfunction
" Insert a use statement
""""""""""""""""""""""""
function! phpactor#UseAdd()
call phpactor#ImportClass()
endfunction
function! phpactor#ImportClass()
call phpactor#rpc("import_class", {"offset": phpactor#_offset(), "source": phpactor#_source(), "path": expand('%:p')})
endfunction
function! phpactor#ImportMissingClasses()
call phpactor#rpc("import_missing_classes", {"source": phpactor#_source(), "path": expand('%:p')})
endfunction

"""""""""""""""""""""""""""
" RPC Proxy methods
Expand Down Expand Up @@ -546,9 +536,7 @@ function! phpactor#_rpc_dispatch(actionName, parameters)
" >> collection
if a:actionName == "collection"
for action in a:parameters["actions"]
let g:_phpactorRpcActionIsCollection = v:true
let result = phpactor#_rpc_dispatch(action["name"], action["parameters"])
let g:_phpactorRpcActionIsCollection = v:false

if !empty(result)
return result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function testOutdatedGitIndex()
public function testMovesRelatedFiles()
{
$this->workspace()->put('.phpactor.json', json_encode([
'navigator.destinations' => [
"source" => "lib/<kernel>.php",
'navigator.destinations' => [
"source" => "lib/<kernel>.php",
"test" => "lib/<kernel>Test.php"
]
]));
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Extension/ClassMover/Rpc/ClassMoveHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public function testItShouldAskForConfirmation()
$action = array_shift($actions);
$this->assertInstanceOf(CloseFileResponse::class, $action);
$this->assertEquals(self::SOURCE_PATH, $action->path());

}

public function testItAskIfRelatedFilesShouldBeMoved()
Expand Down Expand Up @@ -167,5 +168,6 @@ public function testMovesRelatedFiles()
'confirmed' => true,
'move_related' => true,
]);

}
}

This file was deleted.