Skip to content

Commit f91c424

Browse files
committed
Add configuration option for fluent setters.
This commit adds g:php_refactoring_make_setter_fluent which is by default 0. Possible values are: 0 - Disabled 1 - Enabled 2 - Prompt Other - Error
1 parent b3fd864 commit f91c424

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,17 @@ let g:vim_php_refactoring_default_property_visibility = 'private'
5252
let g:vim_php_refactoring_default_method_visibility = 'private'
5353
```
5454

55+
To enable fluent setters add either of these lines to your `~/.vimrc` file
56+
```
57+
" default is 0 -- disabled
58+
59+
" to enable for all setters
60+
let g:vim_php_refactoring_fluent_setter = 1
61+
62+
" to enable but be prompted when creating the setter
63+
let g:vim_php_refactoring_fluent_setter = 2
64+
```
65+
5566

5667
## Default Mappings
5768

plugin/php-refactoring-toolbox.vim

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ endif
4545
if !exists('g:vim_php_refactoring_default_method_visibility')
4646
let g:vim_php_refactoring_default_method_visibility = 'private'
4747
endif
48+
49+
if !exists('g:vim_php_refactoring_make_setter_fluent')
50+
let g:vim_php_refactoring_make_setter_fluent = 0
51+
endif
4852
" }}}
4953

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

97+
" Fluent {{{
98+
let s:php_fluent_this = "normal! jo\<CR>return $this;"
99+
" }}}
100+
93101
function! PhpDocAll() " {{{
94102
if exists("*" . g:vim_php_refactoring_phpdoc) == 0
95103
call s:PhpEchoError(g:vim_php_refactoring_phpdoc . '() vim function doesn''t exists.')
@@ -128,9 +136,8 @@ function! PhpCreateSettersAndGetters() " {{{
128136
endif
129137
if search(s:php_regex_func_line . "set" . l:camelCaseName . '\>', 'n') == 0
130138
call s:PhpInsertMethod("public", "set" . l:camelCaseName, ['$' . substitute(l:property, '^_', '', '') ], "$this->" . l:property . " = $" . substitute(l:property, '^_', '', '') . ";\n")
131-
call s:PhpEchoError('Make fluent?')
132-
if inputlist(["0. No", "1. Yes"]) == 1
133-
exec "normal! jo\<CR>return $this;"
139+
if g:vim_php_refactoring_make_setter_fluent > 0
140+
call s:PhpInsertFluent()
134141
endif
135142
endif
136143
if search(s:php_regex_func_line . "get" . l:camelCaseName . '\>', 'n') == 0
@@ -529,3 +536,17 @@ function! s:PhpEchoError(message) " {{{
529536
echohl NONE
530537
endfunction
531538
" }}}
539+
540+
function! s:PhpInsertFluent() " {{{
541+
if g:vim_php_refactoring_make_setter_fluent == 1
542+
exec s:php_fluent_this
543+
elseif g:vim_php_refactoring_make_setter_fluent == 2
544+
call s:PhpEchoError('Make fluent?')
545+
if inputlist(["0. No", "1. Yes"]) == 1
546+
exec s:php_fluent_this
547+
endif
548+
else
549+
echoerr 'Invalid option for g:vim_php_refactoring_make_setter_fluent'
550+
endif
551+
endfunction
552+
" }}}

0 commit comments

Comments
 (0)