@@ -30,6 +30,7 @@ nnoremap <unique> <Leader>rcv :call PhpRenameClassVariable()<CR>
3030nnoremap <unique> <Leader>rm :call PhpRenameMethod()<CR>
3131nnoremap <unique> <Leader>eu :call PhpExtractUse()<CR>
3232vnoremap <unique> <Leader>ec :call PhpExtractConst()<CR>
33+ vnoremap <unique> <Leader>ev :call PhpExtractVariable()<CR>
3334nnoremap <unique> <Leader>ep :call PhpExtractClassProperty()<CR>
3435vnoremap <unique> <Leader>em :call PhpExtractMethod()<CR>
3536nnoremap <unique> <Leader>np :call PhpCreateProperty()<CR>
@@ -47,11 +48,12 @@ Examples *refactoring-to
47484. Extract Use Statement........................................|extract-use-statement|
48495. Extract Class Property.......................................|extract-class-property|
49506. Extract Method...............................................|extract-method|
50- 7. Create Property..............................................|create-property|
51- 8. Detect Unused Use Statements.................................|detect-unused-use|
52- 9. Align assignments............................................|align-assignments|
53- 10. Create Setters and Getters..................................|create-set-get|
54- 11. Document all................................................|document-all|
51+ 7. Extract Variable.............................................|extract-variable|
52+ 8. Create Property..............................................|create-property|
53+ 9. Detect Unused Use Statements.................................|detect-unused-use|
54+ 10. Align assignments...........................................|align-assignments|
55+ 11. Create Setters and Getters..................................|create-set-get|
56+ 12. Document all................................................|document-all|
5557
5658Note: ↑ Is the position of your cursor
5759
@@ -191,7 +193,41 @@ class HelloWorld {
191193}
192194
193195===============================================================================
194- Create Property *create-property*
196+ Extract Variable *extract-variable*
197+
198+ <?php
199+
200+ class HelloWorld {
201+ private function prepareSentence($firstName)
202+ {
203+ $sentence = 'Hello';
204+ if ('foo' === $firstName) {
205+ $sentence .= ' ' . $firstName;
206+ }
207+ return $sentence;
208+ }
209+ }
210+
211+ Select in visual mode (V) the code you want to extract in a variable and hit `<Leader>ev`.
212+ You'll be prompted for a variable name. Enter a variable name and press enter
213+
214+ <?php
215+
216+ class HelloWorld {
217+ private function prepareSentence($firstName)
218+ {
219+ $sentence = 'Hello';
220+ $firstNameIsValid = 'foo' === $firstName;
221+
222+ if ($firstNameIsValid) {
223+ $sentence .= ' ' . $firstName;
224+ }
225+ return $sentence;
226+ }
227+ }
228+
229+ ===============================================================================
230+ Create Property *create-property*
195231
196232<Leader>np will create a new property in your current class.
197233
0 commit comments