@@ -46,23 +46,22 @@ func! PhpRefactorExtractMethod()
4646 return
4747 endif
4848
49- let startLine= line (' v' )
50- let endLine= line (' .' )
51- let method= input (' Enter extracted method name: ' )
49+ let startLine = line (' v' )
50+ let endLine = line (' .' )
51+ let method = input (' Enter extracted method name: ' )
5252
5353 " check line numbers are the right way around
5454 if startLine > endLine
55- let temp= startLine
56- let startLine= endLine
57- let endLine= temp
55+ let temp = startLine
56+ let startLine = endLine
57+ let endLine = temp
5858 endif
5959
60- exec ' :!' .g: php_refactor_command
61- \ .' extract-method'
62- \ .' %'
63- \ .' ' .startLine.' -' .endLine
64- \ .' ' .method
65- \ .' | ' .g: php_refactor_patch_command
60+ let range = startLine . ' -' . endLine
61+
62+ let args = [range , method]
63+
64+ call PhpRefactorRunCommand (' extract-method' , args )
6665
6766 " todo : exit visual mode
6867endfunc
@@ -74,15 +73,12 @@ func! PhpRefactorLocalVariableToInstanceVariable()
7473 return
7574 endif
7675
77- let variable= expand (' <cword>' )
78- let lineNo= line (' .' )
76+ let variable = expand (' <cword>' )
77+ let lineNo = line (' .' )
78+
79+ let args = [lineNo, variable]
7980
80- exec ' :!' .g: php_refactor_command
81- \ .' convert-local-to-instance-variable'
82- \ .' %'
83- \ .' ' .lineNo
84- \ .' ' .variable
85- \ .' | ' .g: php_refactor_patch_command
81+ call PhpRefactorRunCommand (' convert-local-to-instance-variable' , args )
8682endfunc
8783
8884func ! PhpRefactorRenameLocalVariable ()
@@ -92,18 +88,13 @@ func! PhpRefactorRenameLocalVariable()
9288 return
9389 endif
9490
95- let oldName= expand (' <cword>' )
96- let lineNo= line (' .' )
97- let newName= input (' Enter new variable name: ' )
91+ let oldName = expand (' <cword>' )
92+ let lineNo = line (' .' )
93+ let newName = input (' Enter new variable name: ' )
9894
95+ let args = [lineNo, oldName, newName]
9996
100- exec ' :!' .g: php_refactor_command
101- \ .' rename-local-variable'
102- \ .' %'
103- \ .' ' .lineNo
104- \ .' ' .oldName
105- \ .' ' .newName
106- \ .' | ' .g: php_refactor_patch_command
97+ call PhpRefactorRunCommand (' rename-local-variable' , args )
10798endfunc
10899
109100func ! PhpRefactorOptimizeUse ()
@@ -113,10 +104,23 @@ func! PhpRefactorOptimizeUse()
113104 return
114105 endif
115106
116- exec ' :!' .g: php_refactor_command
117- \ .' optimize-use'
118- \ .' %'
119- \ .' | ' .g: php_refactor_patch_command
107+ call PhpRefactorRunCommand (' optimize-use' , [])
108+ endfunc
109+
110+ func ! PhpRefactorRunCommand (refactoring, args )
111+ " Enable autoread to stop prompting for reload
112+ setlocal autoread
113+
114+ let command = ' :!' . g: php_refactor_command
115+ \ . ' ' . a: refactoring . ' %'
116+
117+ for arg in a: args
118+ let command = command . ' ' . arg
119+ endfor
120+
121+ exec command .' | ' .g: php_refactor_patch_command
122+
123+ setlocal noautoread
120124endfunc
121125
122126vnoremap <expr> <Leader> rem PhpRefactorExtractMethod()
0 commit comments