|
| 1 | +Given php (condition on if): |
| 2 | + <?php |
| 3 | + |
| 4 | + $sentence = 'Hello'; |
| 5 | + |
| 6 | + if ('foo' === $firstName) { |
| 7 | + $sentence .= ' ' . $firstName; |
| 8 | + } |
| 9 | + |
| 10 | +Do (select the condition and extract variable): |
| 11 | + /foo\<CR> |
| 12 | + vi( |
| 13 | + ;ev |
| 14 | + firstNameIsValid\<CR> |
| 15 | + |
| 16 | +Expect php (variable is extracted): |
| 17 | + <?php |
| 18 | + |
| 19 | + $sentence = 'Hello'; |
| 20 | + |
| 21 | + $firstNameIsValid = 'foo' === $firstName; |
| 22 | + |
| 23 | + if ($firstNameIsValid) { |
| 24 | + $sentence .= ' ' . $firstName; |
| 25 | + } |
| 26 | + |
| 27 | +Given php (condition on if and on function): |
| 28 | + <?php |
| 29 | + |
| 30 | + function prepareSentence() |
| 31 | + { |
| 32 | + $sentence = 'Hello'; |
| 33 | + |
| 34 | + if ('foo' === $firstName) { |
| 35 | + $sentence .= ' ' . $firstName; |
| 36 | + } |
| 37 | + |
| 38 | + return $sentence; |
| 39 | + } |
| 40 | + |
| 41 | +Do (select the condition and extract variable): |
| 42 | + /foo\<CR> |
| 43 | + vi( |
| 44 | + ;ev |
| 45 | + firstNameIsValid\<CR> |
| 46 | + |
| 47 | +Expect php (variable is extracted): |
| 48 | + <?php |
| 49 | + |
| 50 | + function prepareSentence() |
| 51 | + { |
| 52 | + $sentence = 'Hello'; |
| 53 | + |
| 54 | + $firstNameIsValid = 'foo' === $firstName; |
| 55 | + |
| 56 | + if ($firstNameIsValid) { |
| 57 | + $sentence .= ' ' . $firstName; |
| 58 | + } |
| 59 | + |
| 60 | + return $sentence; |
| 61 | + } |