Write Setters and Getters for PHP
Just simple automation of writing Setters and Getters like Doctrine might use.
Start file
<?php class Example { firstProperty secondItem lastAttribute }
End file
<?php class Example { private $firstProperty; public function getFirstProperty() { return $this->firstProperty; } public function setFirstProperty($value) { $this->firstProperty = $value; } private $secondItem; public function getSecondItem() { return $this->secondItem; } public function setSecondItem($value) { $this->secondItem = $value; } private $lastAttribute; public function getLastAttribute() { return $this->lastAttribute; } public function setLastAttribute($value) { $this->lastAttribute = $value; } }
View Diff
4,6c4,38 < firstProperty < secondItem < lastAttribute --- > private $firstProperty; > > public function getFirstProperty() > { > return $this->firstProperty; > } > > public function setFirstProperty($value) > { > $this->firstProperty = $value; > } > > private $secondItem; > > public function getSecondItem() > { > return $this->secondItem; > } > > public function setSecondItem($value) > { > $this->secondItem = $value; > } > > private $lastAttribute; > > public function getLastAttribute() > { > return $this->lastAttribute; > } > > public function setLastAttribute($value) > { > $this->lastAttribute = $value; > }
Solutions
The best way to learn is to practice. Below, you will find some of the solutions other golfers have entered. To unlock higher ranked solutions, submit your own entry which does as well or better than the solutions you can currently see - climb the ladder!
Check out these helpful resources to improve your Vim skills... Game on.
Unlock 32 remaining solutions by signing in and submitting your own entry
#33 Eric Potter / @pottereric - Score: 262 - 03/03/14 @ 02:57
:4,6s/\S/private $&<CR>A;<Esc>ka;<Esc>kA;<CR><CR>public functino<BS><BS>on getX()<CR>{<CR><Tab>return this<BS><BS><BS><BS>$this->X;<CR><BS>}<CR><Esc>:6,10y<CR>pfgrs<CR><CR>dwA<BS> = $value;<Esc>hcya<Esc><Up><Up>i$value<Esc>:5,15y<CR>:16<CR>p:28<CR>p:39<CR>dd:5,15s/X/firstProperty<CR>:17,27s/X/secondItem<CR>:29,39//<BS><BS>s/X/lastAttribute<CR>:%s/tf/tF<CR>:%s/ts/tS<CR>:%s/tl/tL<CR>ZZ
0 comments