- Notifications
You must be signed in to change notification settings - Fork28
VIM Php Refactoring Toolbox
License
adoy/vim-php-refactoring-toolbox
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
PHP Refactoring Toolbox for VIM
- Rename Local Variable
- Rename Class Variable
- Rename Method
- Extract Use
- Extract Const
- Extract Class Property
- Extract Method
- Create Property
- Detect Unused Use Statements
- Align Assigns
- Create setters and getters
- Document all code
- vim-plug:
Plug 'adoy/vim-php-refactoring-toolbox' - vundle:
Plugin 'adoy/vim-php-refactoring-toolbox' - pathogen:
git clone https://github.com/adoy/vim-php-refactoring-toolbox.git ~/.vim/bundle/ - or just copy the
plugin/php-refactoring-toolbox.vimin your~/.vim/pluginfolder
If you want to disable the default mapping just add this line in your~/.vimrc file
let g:vim_php_refactoring_use_default_mapping = 0If you want to disable the user validation at the getter/setter creation, just add this line in your~/.vimrc file
let g:vim_php_refactoring_auto_validate_sg = 1If you want to disable the user validation at getter only creation, just add this line in your~/.vimrc file
let g:vim_php_refactoring_auto_validate_g = 1If you want to disable the user validation for all rename features, just add this line in your~/.vimrc file
let g:vim_php_refactoring_auto_validate_rename = 1If you want to disable the user validation for the visibility (private/public) add this line in your~/.vimrc file
let g:vim_php_refactoring_auto_validate_visibility = 1To change the default visibility add one/both of those lines in your~/.vimrc file
let g:vim_php_refactoring_default_property_visibility = 'private'let g:vim_php_refactoring_default_method_visibility = 'private'To enable fluent setters add either of these lines to your~/.vimrc file
" default is 0 -- disabled" to enable for all setterslet g:vim_php_refactoring_make_setter_fluent = 1" to enable but be prompted when creating the setterlet g:vim_php_refactoring_make_setter_fluent = 2nnoremap <unique> <Leader>rlv :call PhpRenameLocalVariable()<CR>nnoremap <unique> <Leader>rcv :call PhpRenameClassVariable()<CR>nnoremap <unique> <Leader>rm :call PhpRenameMethod()<CR>nnoremap <unique> <Leader>eu :call PhpExtractUse()<CR>vnoremap <unique> <Leader>ec :call PhpExtractConst()<CR>nnoremap <unique> <Leader>ep :call PhpExtractClassProperty()<CR>vnoremap <unique> <Leader>em :call PhpExtractMethod()<CR>nnoremap <unique> <Leader>np :call PhpCreateProperty()<CR>nnoremap <unique> <Leader>du :call PhpDetectUnusedUseStatements()<CR>vnoremap <unique> <Leader>== :call PhpAlignAssigns()<CR>nnoremap <unique> <Leader>sg :call PhpCreateSettersAndGetters()<CR>nnoremap <unique> <Leader>cog :call PhpCreateGetters()<CR>nnoremap <unique> <Leader>da :call PhpDocAll()<CR>You'll find in this project aplayground.php file. You can use this file to start playing with this refactoring plugin.
↑ Is the position of your cursor
<?phpfunctionhelloWorld($foobar =null) {echo"Hello" .$foobar;} ↑
<Leader>rlv in normal mode, specify the new$name
<?phpfunctionhelloWorld($name =null) {echo"Hello" .$name;} ↑
<?phpclass HelloWorld {private$foobar;publicfunction__construct($name) {$this->foobar =$name; }publicfunctionsayHello() {echo$this->foobar; } ↑}
<Leader>rcv in normal mode, specify the new$name
<?phpclass HelloWorld {private$name;publicfunction__construct($name) {$this->name =$name; }publicfunctionsayHello() {echo$this->name; }}
<?phpclass HelloWorld {publicfunctionsayHello() {echo$this->sayHello(); } ↑}
<Leader>rm in normal mode, specify the new method name
<?phpclass HelloWorld {publicfunctionnewMethodName() {echo$this->newMethodName(); } ↑}
<?php$obj1 =newFoo\Bar\Baz;$obj2 =newFoo\Bar\Baz; ↑
<Leader>eu in normal mode
<?phpuseFoo\Bar\Baz;$obj1 = Baz;$obj2 = Baz;
<?phpclass Dir {publicfunction__construct($path) {$realpath =$path; } ↑}
<Leader>ep in normal mode will extract the local variable and create a property inside the current class.
<?phpclass Dir {private$realpath;publicfunction__construct($path) {$this->realpath =$path; } ↑}
<?phpclass HelloWorld {publicfunctionsayHello($firstName =null) {$sentence ='Hello';if ($firstName) {$sentence .='' .$firstName; }echo$sentence; }}
Select in visual mode (V) the code you want to extract in an other method and hit<Leader>em.You'll be prompted for a method name. Enter a method name and press enter
<?phpclass HelloWorld {publicfunctionsayHello($firstName =null) {$sentence =$this->prepareSentence($firstName);echo$sentence; }privatefunctionprepareSentence($firstName) {$sentence ='Hello';if ($firstName) {$sentence .='' .$firstName; }return$sentence; }}
<Leader>np will create a new property in your current class.
<Leader>du will detect all unused "use" statements in your code so that you can remove them.
<?php$oneVar ='Foo';$anOtherVar ='Bar';$oneVar +='Baz';
Select the code you want to align and then hit<Leader>==
<?php$oneVar ='Foo';$anOtherVar ='Bar';$oneVar +='Baz';
<?phpclass Foo {private$bar;}
Hit<Leader>sg and you'll be prompted if you want to create setters and getters for existing properties and if you want to make the setter fluent.
<?phpclass Foo {private$bar;publicfunctionsetBar($bar) {$this->bar =$bar;return$this;// If you opted for a fluent setter at the prompt. }publicfunctiongetBar() {return$this->bar; }}
<?phpclass Foo {private$bar;}
Hit<Leader>cog and you will be prompted if you want only getters for existing properties
<?phpclass Foo {private$bar;publicfunctiongetBar() {return$this->bar; }}
<Leader>da will call your documentation plugin (by default Php Documentor for vimhttps://github.com/tobyS/pdv) for every uncommented classes, methods, functions and properties.
About
VIM Php Refactoring Toolbox
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Contributors7
Uh oh!
There was an error while loading.Please reload this page.