Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adoy/vim-php-refactoring-toolbox
VIM Php Refactoring Toolbox
https://github.com/adoy/vim-php-refactoring-toolbox
php refactoring refactoring-tools vim
Last synced: about 2 months ago
JSON representation
VIM Php Refactoring Toolbox
- Host: GitHub
- URL: https://github.com/adoy/vim-php-refactoring-toolbox
- Owner: adoy
- License: mit
- Created: 2014-09-18T05:59:37.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2022-10-01T19:39:53.000Z (over 2 years ago)
- Last Synced: 2024-12-10T05:32:56.783Z (2 months ago)
- Topics: php, refactoring, refactoring-tools, vim
- Language: Vim script
- Size: 43 KB
- Stars: 180
- Watchers: 14
- Forks: 28
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - adoy/vim-php-refactoring-toolbox - VIM Php Refactoring Toolbox (Vim Script)
README
# VIM Php Refactoring Toolbox
[![License: MIT](https://img.shields.io/github/license/adoy/vim-php-refactoring-toolbox)](https://opensource.org/licenses/MIT)
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## Installation
* [vim-plug](https://github.com/junegunn/vim-plug): `Plug 'adoy/vim-php-refactoring-toolbox'`
* [vundle](https://github.com/gmarik/Vundle.vim): `Plugin 'adoy/vim-php-refactoring-toolbox'`
* [pathogen](https://github.com/tpope/vim-pathogen): `git clone https://github.com/adoy/vim-php-refactoring-toolbox.git ~/.vim/bundle/`
* or just copy the `plugin/php-refactoring-toolbox.vim` in your `~/.vim/plugin` folderIf you want to disable the default mapping just add this line in your `~/.vimrc` file
```
let g:vim_php_refactoring_use_default_mapping = 0
```If 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 = 1
```If 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 = 1
```If 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 = 1
```If 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 = 1
```To 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 setters
let g:vim_php_refactoring_make_setter_fluent = 1" to enable but be prompted when creating the setter
let g:vim_php_refactoring_make_setter_fluent = 2
```## Default Mappings
nnoremap rlv :call PhpRenameLocalVariable()
nnoremap rcv :call PhpRenameClassVariable()
nnoremap rm :call PhpRenameMethod()
nnoremap eu :call PhpExtractUse()
vnoremap ec :call PhpExtractConst()
nnoremap ep :call PhpExtractClassProperty()
vnoremap em :call PhpExtractMethod()
nnoremap np :call PhpCreateProperty()
nnoremap du :call PhpDetectUnusedUseStatements()
vnoremap == :call PhpAlignAssigns()
nnoremap sg :call PhpCreateSettersAndGetters()
nnoremap cog :call PhpCreateGetters()
nnoremap da :call PhpDocAll()## Playground.php
You'll find in this project a `playground.php` file. You can use this file to start playing with this refactoring plugin.
## Examples
↑ Is the position of your cursor
### Rename Local Variable
``` php
rlv` in normal mode, specify the new `$name```` php
foobar = $name;
}
public function sayHello() {
echo $this->foobar;
} ↑
}
````rcv` in normal mode, specify the new `$name`
``` php
name = $name;
}
public function sayHello() {
echo $this->name;
}
}
```### Rename method
``` php
sayHello();
} ↑
}
````rm` in normal mode, specify the new method name
``` php
newMethodName();
} ↑
}
```### Extract Use Statement
``` php
eu` in normal mode``` php
ep` in normal mode will extract the local variable and create a property inside the current class.``` php
realpath = $path;
} ↑
}
```### Extract Method
``` php
em`.
You'll be prompted for a method name. Enter a method name and press enter``` php
prepareSentence($firstName);
echo $sentence;
}private function prepareSentence($firstName)
{
$sentence = 'Hello';
if ($firstName) {
$sentence .= ' ' . $firstName;
}
return $sentence;
}
}
```### Create Property
`np` will create a new property in your current class.
### Detect unused "use" statements
`du` will detect all unused "use" statements in your code so that you can remove them.
### Align assignments
``` php
==```` php
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.``` php
bar = $bar;return $this; // If you opted for a fluent setter at the prompt.
}public function getBar()
{
return $this->bar;
}
}
```### Create only getters
``` php
cog` and you will be prompted if you want only getters for existing properties``` php
bar;
}
}
```### Document all
`da` will call your documentation plugin (by default Php Documentor for vim https://github.com/tobyS/pdv) for every uncommented classes, methods, functions and properties.