@@ -30,6 +30,7 @@ nnoremap <unique> <Leader>rcv :call PhpRenameClassVariable()<CR>
30
30
nnoremap <unique> <Leader>rm :call PhpRenameMethod()<CR>
31
31
nnoremap <unique> <Leader>eu :call PhpExtractUse()<CR>
32
32
vnoremap <unique> <Leader>ec :call PhpExtractConst()<CR>
33
+ vnoremap <unique> <Leader>ev :call PhpExtractVariable()<CR>
33
34
nnoremap <unique> <Leader>ep :call PhpExtractClassProperty()<CR>
34
35
vnoremap <unique> <Leader>em :call PhpExtractMethod()<CR>
35
36
nnoremap <unique> <Leader>np :call PhpCreateProperty()<CR>
@@ -47,11 +48,12 @@ Examples *refactoring-to
47
48
4. Extract Use Statement........................................|extract-use-statement|
48
49
5. Extract Class Property.......................................|extract-class-property|
49
50
6. 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|
55
57
56
58
Note: ↑ Is the position of your cursor
57
59
@@ -191,7 +193,41 @@ class HelloWorld {
191
193
}
192
194
193
195
===============================================================================
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*
195
231
196
232
<Leader>np will create a new property in your current class.
197
233
0 commit comments