Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ If you want to disable the user validation at the getter/setter creation, just a
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

```
Expand Down Expand Up @@ -77,6 +83,7 @@ let g:vim_php_refactoring_fluent_setter = 2
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>

## Playground.php
Expand Down Expand Up @@ -301,6 +308,31 @@ class Foo {
}
```

### Create only getters

``` php
<?php

class Foo {
private $bar;
}
```

Hit `<Leader>cog` and you will be prompted if you want only getters for existing properties

``` php
<?php

class Foo {
private $bar;

public function getBar()
{
return $this->bar;
}
}
```

### Document all

`<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.
Expand Down
27 changes: 27 additions & 0 deletions plugin/php-refactoring-toolbox.vim
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ if !exists('g:vim_php_refactoring_auto_validate_sg')
let g:vim_php_refactoring_auto_validate_sg = g:vim_php_refactoring_auto_validate
endif

if !exists('g:vim_php_refactoring_auto_validate_g')
let g:vim_php_refactoring_auto_validate_g = g:vim_php_refactoring_auto_validate
endif

if !exists('g:vim_php_refactoring_auto_validate_rename')
let g:vim_php_refactoring_auto_validate_rename = g:vim_php_refactoring_auto_validate
endif
Expand Down Expand Up @@ -64,6 +68,7 @@ if g:vim_php_refactoring_use_default_mapping == 1
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>
endif
" }}}
Expand Down Expand Up @@ -119,6 +124,28 @@ function! PhpDocAll() " {{{
endfunction
" }}}

function! PhpCreateGetters() " {{{
normal gg
let l:properties = []
while search(s:php_regex_member_line, 'eW') > 0
normal w"xye
call add(l:properties, @x)
endwhile
for l:property in l:properties
let l:camelCaseName = substitute(l:property, '^_\?\(.\)', '\U\1', '')
if g:vim_php_refactoring_auto_validate_g == 0
call s:PhpEchoError('Create get' . l:camelCaseName . '()')
if inputlist(["0. No", "1. Yes"]) == 0
continue
endif
endif
if search(s:php_regex_func_line . "get" . l:camelCaseName . '\>', 'n') == 0
call s:PhpInsertMethod("public", "get" . l:camelCaseName, [], "return $this->" . l:property . ";\n")
endif
endfor
endfunction
" }}}

function! PhpCreateSettersAndGetters() " {{{
normal gg
let l:properties = []
Expand Down