Skip to content

Commit 296871a

Browse files
committed
Functionality for creating only getters, closes #18
1 parent b133d81 commit 296871a

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ 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 at getter only creation, just add this line in your `~/.vimrc` file
39+
40+
```
41+
let g:vim_php_refactoring_auto_validate_g = 1
42+
```
43+
3844
If you want to disable the user validation for all rename features, just add this line in your `~/.vimrc` file
3945

4046
```
@@ -77,6 +83,7 @@ let g:vim_php_refactoring_fluent_setter = 2
7783
nnoremap <unique> <Leader>du :call PhpDetectUnusedUseStatements()<CR>
7884
vnoremap <unique> <Leader>== :call PhpAlignAssigns()<CR>
7985
nnoremap <unique> <Leader>sg :call PhpCreateSettersAndGetters()<CR>
86+
nnoremap <unique> <Leader>cog :call PhpCreateGetters()<CR>
8087
nnoremap <unique> <Leader>da :call PhpDocAll()<CR>
8188

8289
## Playground.php
@@ -301,6 +308,31 @@ class Foo {
301308
}
302309
```
303310

311+
### Create only getters
312+
313+
``` php
314+
<?php
315+
316+
class Foo {
317+
private $bar;
318+
}
319+
```
320+
321+
Hit `<Leader>cog` and you will be prompted if you want only getters for existing properties
322+
323+
``` php
324+
<?php
325+
326+
class Foo {
327+
private $bar;
328+
329+
public function getBar()
330+
{
331+
return $this->bar;
332+
}
333+
}
334+
```
335+
304336
### Document all
305337

306338
`<Leader>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.

plugin/php-refactoring-toolbox.vim

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ if !exists('g:vim_php_refactoring_auto_validate_sg')
3030
let g:vim_php_refactoring_auto_validate_sg = g:vim_php_refactoring_auto_validate
3131
endif
3232

33+
if !exists('g:vim_php_refactoring_auto_validate_g')
34+
let g:vim_php_refactoring_auto_validate_g = g:vim_php_refactoring_auto_validate
35+
endif
36+
3337
if !exists('g:vim_php_refactoring_auto_validate_rename')
3438
let g:vim_php_refactoring_auto_validate_rename = g:vim_php_refactoring_auto_validate
3539
endif
@@ -64,6 +68,7 @@ if g:vim_php_refactoring_use_default_mapping == 1
6468
nnoremap <unique> <Leader>du :call PhpDetectUnusedUseStatements()<CR>
6569
vnoremap <unique> <Leader>== :call PhpAlignAssigns()<CR>
6670
nnoremap <unique> <Leader>sg :call PhpCreateSettersAndGetters()<CR>
71+
nnoremap <unique> <Leader>cog :call PhpCreateGetters()<CR>
6772
nnoremap <unique> <Leader>da :call PhpDocAll()<CR>
6873
endif
6974
" }}}
@@ -119,6 +124,28 @@ function! PhpDocAll() " {{{
119124
endfunction
120125
" }}}
121126

127+
function! PhpCreateGetters() " {{{
128+
normal gg
129+
let l:properties = []
130+
while search(s:php_regex_member_line, 'eW') > 0
131+
normal w"xye
132+
call add(l:properties, @x)
133+
endwhile
134+
for l:property in l:properties
135+
let l:camelCaseName = substitute(l:property, '^_\?\(.\)', '\U\1', '')
136+
if g:vim_php_refactoring_auto_validate_g == 0
137+
call s:PhpEchoError('Create get' . l:camelCaseName . '()')
138+
if inputlist(["0. No", "1. Yes"]) == 0
139+
continue
140+
endif
141+
endif
142+
if search(s:php_regex_func_line . "get" . l:camelCaseName . '\>', 'n') == 0
143+
call s:PhpInsertMethod("public", "get" . l:camelCaseName, [], "return $this->" . l:property . ";\n")
144+
endif
145+
endfor
146+
endfunction
147+
" }}}
148+
122149
function! PhpCreateSettersAndGetters() " {{{
123150
normal gg
124151
let l:properties = []

0 commit comments

Comments
 (0)