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
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ 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_fluent_setter = 1

" to enable but be prompted when creating the setter
let g:vim_php_refactoring_fluent_setter = 2
```


## Default Mappings

Expand Down Expand Up @@ -268,7 +279,7 @@ class Foo {
}
```

Hit `<Leader>sg` and you'll be prompted if you want to create setters and getters for existing properties.
Hit `<Leader>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
<?php
Expand All @@ -279,6 +290,8 @@ class Foo {
public function setBar($bar)
{
$this->bar = $bar;

return $this; // If you opted for a fluent setter at the prompt.
}

public function getBar()
Expand Down
8 changes: 4 additions & 4 deletions doc/refactoring-toolbox.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
*refactoring-toolbox*
*refactoring-toolbox*

__________ _____ __ .__ ___________ .__ ___.
__________ _____ __ .__ ___________ .__ ___.
\______ \ _____/ ____\____ _____/ |_ ___________|__| ____ ____ \__ ___/___ ____ | |\_ |__ _______ ___
| _// __ \ __\\__ \ _/ ___\ __\/ _ \_ __ \ |/ \ / ___\ | | / _ \ / _ \| | | __ \ / _ \ \/ /
| | \ ___/| | / __ \\ \___| | ( <_> ) | \/ | | \/ /_/ > | |( <_> | <_> ) |_| \_\ ( <_> > <
| | \ ___/| | / __ \\ \___| | ( <_> ) | \/ | | \/ /_/ > | |( <_> | <_> ) |_| \_\ ( <_> > <
|____|_ /\___ >__| (____ /\___ >__| \____/|__| |__|___| /\___ / |____| \____/ \____/|____/___ /\____/__/\_ \
\/ \/ \/ \/ \//_____/ \/ \/

Expand Down Expand Up @@ -229,7 +229,7 @@ class Foo {
private $bar;
}

Hit <Leader>sg and you'll be prompted if you want to create setters and getters for existing properties.
Hit `<Leader>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

Expand Down
25 changes: 25 additions & 0 deletions plugin/php-refactoring-toolbox.vim
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ endif
if !exists('g:vim_php_refactoring_default_method_visibility')
let g:vim_php_refactoring_default_method_visibility = 'private'
endif

if !exists('g:vim_php_refactoring_make_setter_fluent')
let g:vim_php_refactoring_make_setter_fluent = 0
endif
" }}}

" Refactoring mapping {{{
Expand Down Expand Up @@ -90,6 +94,10 @@ let s:php_regex_fqcn = '[\\_A-Za-z0-9]*'
let s:php_regex_cn = '[_A-Za-z0-9]\+'
" }}}

" Fluent {{{
let s:php_fluent_this = "normal! jo\<CR>return $this;"
" }}}

function! PhpDocAll() " {{{
if exists("*" . g:vim_php_refactoring_phpdoc) == 0
call s:PhpEchoError(g:vim_php_refactoring_phpdoc . '() vim function doesn''t exists.')
Expand Down Expand Up @@ -128,6 +136,9 @@ function! PhpCreateSettersAndGetters() " {{{
endif
if search(s:php_regex_func_line . "set" . l:camelCaseName . '\>', 'n') == 0
call s:PhpInsertMethod("public", "set" . l:camelCaseName, ['$' . substitute(l:property, '^_', '', '') ], "$this->" . l:property . " = $" . substitute(l:property, '^_', '', '') . ";\n")
if g:vim_php_refactoring_make_setter_fluent > 0
call s:PhpInsertFluent()
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")
Expand Down Expand Up @@ -525,3 +536,17 @@ function! s:PhpEchoError(message) " {{{
echohl NONE
endfunction
" }}}

function! s:PhpInsertFluent() " {{{
if g:vim_php_refactoring_make_setter_fluent == 1
exec s:php_fluent_this
elseif g:vim_php_refactoring_make_setter_fluent == 2
call s:PhpEchoError('Make fluent?')
if inputlist(["0. No", "1. Yes"]) == 1
exec s:php_fluent_this
endif
else
echoerr 'Invalid option for g:vim_php_refactoring_make_setter_fluent'
endif
endfunction
" }}}