diff --git a/README.md b/README.md index 11f5350..fb2d901 100644 --- a/README.md +++ b/README.md @@ -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 @@ -268,7 +279,7 @@ class Foo { } ``` -Hit `sg` and you'll be prompted if you want to create setters and getters for existing properties. +Hit `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 bar = $bar; + + return $this; // If you opted for a fluent setter at the prompt. } public function getBar() diff --git a/doc/refactoring-toolbox.txt b/doc/refactoring-toolbox.txt index a42729d..38e6b03 100755 --- a/doc/refactoring-toolbox.txt +++ b/doc/refactoring-toolbox.txt @@ -1,9 +1,9 @@ -*refactoring-toolbox* +*refactoring-toolbox* -__________ _____ __ .__ ___________ .__ ___. +__________ _____ __ .__ ___________ .__ ___. \______ \ _____/ ____\____ _____/ |_ ___________|__| ____ ____ \__ ___/___ ____ | |\_ |__ _______ ___ | _// __ \ __\\__ \ _/ ___\ __\/ _ \_ __ \ |/ \ / ___\ | | / _ \ / _ \| | | __ \ / _ \ \/ / - | | \ ___/| | / __ \\ \___| | ( <_> ) | \/ | | \/ /_/ > | |( <_> | <_> ) |_| \_\ ( <_> > < + | | \ ___/| | / __ \\ \___| | ( <_> ) | \/ | | \/ /_/ > | |( <_> | <_> ) |_| \_\ ( <_> > < |____|_ /\___ >__| (____ /\___ >__| \____/|__| |__|___| /\___ / |____| \____/ \____/|____/___ /\____/__/\_ \ \/ \/ \/ \/ \//_____/ \/ \/ @@ -229,7 +229,7 @@ class Foo { private $bar; } -Hit sg and you'll be prompted if you want to create setters and getters for existing properties. +Hit `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. 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.') @@ -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") @@ -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 +" }}}