Timestamped Live Template 'Todos' in PHPStorm
Sometimes when working on a web application we sometimes come across certain code that should be changed
or we've half-implmented a feature and have to shift our focus on something else,
and we often add a simple // TODO: This field should be validated as an Email instead of String
-comment
or something like that which gives a brief but concise explanation of what needs to be done to the code
before we shift our focus to something else.
When writing these I like to put the date and my name, so that I and others on my team can get an idea of when the comment was made and who made it.
Example:
if (!Csrf::check($requestToken)) {
// TODO(03 aug 2016) ~ Helge: Gracefully handle this instead of dying
die("CSRF Token Mismatch");
}
So let me walk you through the process of adding this type of comment in PHPStorm.
How to add Live Template in PHPStorm
Click on File -> Settings ( Ctrl + Alt + S)
Type live template in the search box to quickly be taken to the live template settings.
Click on the green plus icon to add a new live template
Write "todo" or whatever abbreviation you want to use into the Abbreviation text box.
Then write the following in the "Template text" box: // TODO($date$) ~ Your Name:
Then click on Edit variables and write the following into the fields that appear.
We then need to define the context (Which programming language this Live Template is available in), I use PHP and Javascript as they use the same syntax for comments.
Then click OK and Apply, we can now use this nippet in our code.
Results in: