Skip to content

Commit 9065a3c

Browse files
committed
Option to disable user validation of rename tools
1 parent f35ebc0 commit 9065a3c

File tree

2 files changed

+33
-16
lines changed

2 files changed

+33
-16
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ PHP Refactoring Toolbox for VIM
1515
* Create setters and getters
1616
* Document all code
1717

18-
## Installation
18+
## Installation
1919

2020
* [vim-plug](https://github.com/junegunn/vim-plug): `Plug 'adoy/vim-php-refactoring-toolbox'`
2121
* [vundle](https://github.com/gmarik/Vundle.vim): `Plugin 'adoy/vim-php-refactoring-toolbox'`
2222
* [pathogen](https://github.com/tpope/vim-pathogen): `git clone https://github.com/adoy/vim-php-refactoring-toolbox.git ~/.vim/bundle/`
2323
* or just copy the `plugin/php-refactoring-toolbox.vim` in your `~/.vim/plugin` folder
2424

2525

26-
If you want to disable the default mapping just add this line in your `~/.vimrc` file
26+
If you want to disable the default mapping just add this line in your `~/.vimrc` file
2727

2828
```
2929
let g:vim_php_refactoring_use_default_mapping = 0
@@ -35,6 +35,13 @@ If you want to disable the user validation at the getter/setter creation, just a
3535
let g:vim_php_refactoring_auto_validate_sg = 1
3636
```
3737

38+
If you want to disable the user validation for all rename features, just add this line in your `~/.vimrc` file
39+
40+
```
41+
let g:vim_php_refactoring_auto_validate_rename = 1
42+
```
43+
44+
3845
## Default Mappings
3946

4047
nnoremap <unique> <Leader>rlv :call PhpRenameLocalVariable()<CR>
@@ -180,8 +187,8 @@ class Dir {
180187

181188
class HelloWorld {
182189
public function sayHello($firstName = null) {
183-
$sentence = 'Hello';
184-
if ($firstName) {
190+
$sentence = 'Hello';
191+
if ($firstName) {
185192
$sentence .= ' ' . $firstName;
186193
}
187194
echo $sentence;
@@ -203,7 +210,7 @@ class HelloWorld {
203210

204211
private function prepareSentence($firstName)
205212
{
206-
$sentence = 'Hello';
213+
$sentence = 'Hello';
207214
if ($firstName) {
208215
$sentence .= ' ' . $firstName;
209216
}

plugin/php-refactoring-toolbox.vim

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@ if !exists('g:vim_php_refactoring_auto_validate')
2222
endif
2323

2424
if !exists('g:vim_php_refactoring_auto_validate_sg')
25-
let g:vim_php_refactoring_auto_validate_sg = g:vim_php_refactoring_auto_validate
25+
let g:vim_php_refactoring_auto_validate_sg = g:vim_php_refactoring_auto_validate
26+
endif
27+
28+
if !exists('g:vim_php_refactoring_auto_validate_rename')
29+
let g:vim_php_refactoring_auto_validate_rename = g:vim_php_refactoring_auto_validate
2630
endif
2731
" }}}
2832

@@ -100,7 +104,7 @@ function! PhpCreateSettersAndGetters() " {{{
100104
for l:property in l:properties
101105
let l:camelCaseName = substitute(l:property, '^_\?\(.\)', '\U\1', '')
102106
if g:vim_php_refactoring_auto_validate_sg == 0
103-
call s:PhpEchoError('Create set' . l:camelCaseName . '() and get' . l:camelCaseName . '()')
107+
call s:PhpEchoError('Create set' . l:camelCaseName . '() and get' . l:camelCaseName . '()')
104108
if inputlist(["0. No", "1. Yes"]) == 0
105109
continue
106110
endif
@@ -119,9 +123,11 @@ function! PhpRenameLocalVariable() " {{{
119123
let l:oldName = substitute(expand('<cword>'), '^\$*', '', '')
120124
let l:newName = inputdialog('Rename ' . l:oldName . ' to: ')
121125
if s:PhpSearchInCurrentFunction('$' . l:newName . '\>', 'n') > 0
122-
call s:PhpEchoError('$' . l:newName . ' seems to already exist in the current function scope. Replace anyway ?')
123-
if inputlist(["0. No", "1. Yes"]) == 0
124-
return
126+
if g:vim_php_refactoring_auto_validate_rename == 0
127+
call s:PhpEchoError('$' . l:newName . ' seems to already exist in the current function scope. Rename anyway ?')
128+
if inputlist(["0. No", "1. Yes"]) == 0
129+
return
130+
endif
125131
endif
126132
endif
127133
call s:PhpReplaceInCurrentFunction('$' . l:oldName . '\>', '$' . l:newName)
@@ -132,9 +138,11 @@ function! PhpRenameClassVariable() " {{{
132138
let l:oldName = expand('<cword>')
133139
let l:newName = inputdialog('Rename ' . l:oldName . ' to: ')
134140
if s:PhpSearchInCurrentClass('\%(\%(\%(public\|protected\|private\|static\)\_s\+\)\+\$\|$this->\)\@<=' . l:newName . '\>', 'n') > 0
135-
call s:PhpEchoError(l:newName . ' seems to already exist in the current class. Replace anyway ?')
136-
if inputlist(["0. No", "1. Yes"]) == 0
137-
return
141+
if g:vim_php_refactoring_auto_validate_rename == 0
142+
call s:PhpEchoError(l:newName . ' seems to already exist in the current class. Rename anyway ?')
143+
if inputlist(["0. No", "1. Yes"]) == 0
144+
return
145+
endif
138146
endif
139147
endif
140148
call s:PhpReplaceInCurrentClass('\%(\%(\%(public\|protected\|private\|static\)\_s\+\)\+\$\|$this->\)\@<=' . l:oldName . '\>', l:newName)
@@ -145,9 +153,11 @@ function! PhpRenameMethod() " {{{
145153
let l:oldName = expand('<cword>')
146154
let l:newName = inputdialog('Rename ' . l:oldName . ' to: ')
147155
if s:PhpSearchInCurrentClass('\%(\%(' . s:php_regex_func_line . '\)\|$this->\)\@<=' . l:newName . '\>', 'n') > 0
148-
call s:PhpEchoError(l:newName . ' seems to already exist in the current class. Replace anyway ?')
149-
if inputlist(["0. No", "1. Yes"]) == 0
150-
return
156+
if g:vim_php_refactoring_auto_validate_rename == 0
157+
call s:PhpEchoError(l:newName . ' seems to already exist in the current class. Rename anyway ?')
158+
if inputlist(["0. No", "1. Yes"]) == 0
159+
return
160+
endif
151161
endif
152162
endif
153163
call s:PhpReplaceInCurrentClass('\%(\%(' . s:php_regex_func_line . '\)\|$this->\)\@<=' . l:oldName . '\>', l:newName)

0 commit comments

Comments
 (0)