In my quest to avoid repetitive tasks and try to speed up my work a bit, I've been looking at my IDE, PhpStorm. It seems like customizing the code generating tools is not that hard to do, and it's also easy to share across a team. Here is what I've found so far.
File and Code Templates
There is an easy way in PhpStorm to generate the methods to process our properties, getters-setters. But what if we don't want to use that convention: get or set? Then we have to edit it every time unless we modify the template a bit.
Go to
Preferences -> Editor -> File and Code Templates
In there we can find the code bits used for the generator. The language this template use is Apache Velocity, but without much knowledge of it, it's possible to change this behavior. Simply by removing the first variable
${GET_OR_IS}
Now in the PHP Getter Method, we can have only the property name as the method name.
Code Expansion
It is similarly easy if we want to add the return type to the function code expansion tool.
Preferences -> Editor -> Live Templates -> PHP
Here we will find a lot of snippets.
Then we choose the one we want to modify. Let's start with public methods (pubf). The variables are declared with $ at the beginning and the end. We can change the expected value of each variable in the edit variables form
We could, of course, add new code expansions for our most used functions if they don't already exist. I will add this to my list of to-do for the next round. Stay tuned.
- Velocity in PhpStorm with custom code generators
- Carmen Maymó
- coding-environment
- phpstorm