Skip to content

Commit b5a117e

Browse files
committed
Add default visibility and auto validate configs
1 parent 4c0f71e commit b5a117e

File tree

2 files changed

+47
-12
lines changed

2 files changed

+47
-12
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ If you want to disable the user validation for all rename features, just add thi
4141
let g:vim_php_refactoring_auto_validate_rename = 1
4242
```
4343

44+
If you want to disable the user validation for the visibility (private/public) add this line in your `~/.vimrc` file
45+
```
46+
let g:vim_php_refactoring_auto_validate_visibility = 1
47+
```
48+
49+
To change the default visibility add one/both of those lines in your `~/.vimrc` file
50+
```
51+
let g:vim_php_refactoring_default_property_visibility = 'private'
52+
let g:vim_php_refactoring_default_method_visibility = 'private'
53+
```
54+
4455

4556
## Default Mappings
4657

plugin/php-refactoring-toolbox.vim

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ endif
2828
if !exists('g:vim_php_refactoring_auto_validate_rename')
2929
let g:vim_php_refactoring_auto_validate_rename = g:vim_php_refactoring_auto_validate
3030
endif
31+
32+
if !exists('g:vim_php_refactoring_auto_validate_visibility')
33+
let g:vim_php_refactoring_ask_visibility = g:vim_php_refactoring_auto_validate
34+
endif
35+
36+
if !exists('g:vim_php_refactoring_default_property_visibility')
37+
let g:vim_php_refactoring_default_property_visibility = 'private'
38+
endif
39+
40+
if !exists('g:vim_php_refactoring_default_method_visibility')
41+
let g:vim_php_refactoring_default_method_visibility = 'private'
42+
endif
3143
" }}}
3244

3345
" Refactoring mapping {{{
@@ -79,7 +91,7 @@ function! PhpDocAll() " {{{
7991
return
8092
endif
8193
normal magg
82-
while search(s:php_regex_class_line, 'eW') > 0
94+
while search(s:php_regex_class_line, 'eW') > 0
8395
call s:PhpDocument()
8496
endwhile
8597
normal gg
@@ -201,9 +213,13 @@ function! PhpExtractClassProperty() " {{{
201213
normal mr
202214
let l:name = expand('<cword>')
203215
call s:PhpReplaceInCurrentFunction('$' . l:name . '\>', '$this->' . l:name)
204-
let l:visibility = inputdialog("Visibility (default is private): ")
205-
if empty(l:visibility)
206-
let l:visibility = 'private'
216+
if g:vim_php_refactoring_auto_validate_visibility == 0
217+
let l:visibility = inputdialog("Visibility (default is " . g:vim_php_refactoring_default_property_visibility . "): ")
218+
if empty(l:visibility)
219+
let l:visibility = g:vim_php_refactoring_default_property_visibility
220+
endif
221+
else
222+
let l:visibility = g:vim_php_refactoring_default_property_visibility
207223
endif
208224
call s:PhpInsertProperty(l:name, l:visibility)
209225
normal `r
@@ -216,9 +232,13 @@ function! PhpExtractMethod() range " {{{
216232
return
217233
endif
218234
let l:name = inputdialog("Name of new method: ")
219-
let l:visibility = inputdialog("Visibility (default is private): ")
220-
if empty(l:visibility)
221-
let l:visibility = 'private'
235+
if g:vim_php_refactoring_auto_validate_visibility == 0
236+
let l:visibility = inputdialog("Visibility (default is " . g:vim_php_refactoring_default_method_visibility . "): ")
237+
if empty(l:visibility)
238+
let l:visibility = g:vim_php_refactoring_default_method_visibility
239+
endif
240+
else
241+
let l:visibility = g:vim_php_refactoring_default_method_visibility
222242
endif
223243
normal gv"xdmr
224244
let l:middleLine = line('.')
@@ -265,9 +285,13 @@ endfunction
265285

266286
function! PhpCreateProperty() " {{{
267287
let l:name = inputdialog("Name of new property: ")
268-
let l:visibility = inputdialog("Visibility (default is private): ")
269-
if empty(l:visibility)
270-
let l:visibility = 'private'
288+
if g:vim_php_refactoring_auto_validate_visibility == 0
289+
let l:visibility = inputdialog("Visibility (default is " . g:vim_php_refactoring_default_property_visibility . "): ")
290+
if empty(l:visibility)
291+
let l:visibility = g:vim_php_refactoring_default_property_visibility
292+
endif
293+
else
294+
let l:visibility = g:vim_php_refactoring_default_property_visibility
271295
endif
272296
call s:PhpInsertProperty(l:name, l:visibility)
273297
endfunction
@@ -391,10 +415,10 @@ function! s:PhpInsertProperty(name, visibility) " {{{
391415
if match(l:line, s:php_regex_class_line) > -1
392416
call search('{', 'W')
393417
call s:PhpInsertPropertyExtended(a:name, a:visibility, line('.'), 0)
394-
else
418+
else
395419
call s:PhpInsertPropertyExtended(a:name, a:visibility, line('.'), 1)
396420
endif
397-
else
421+
else
398422
call s:PhpInsertPropertyExtended(a:name, a:visibility, line('.'), 0)
399423
endif
400424
endfunction

0 commit comments

Comments
 (0)