When you are trying PhpStorm—or working with it—consider these tips to make the most of it:
Learn Shortcuts
… and I don’t mean copy and paste. PhpStorm can do many things that make your development faster—and nearly all of it can be mapped to a shortcut. Some of my most used shortcuts are
- Introduce Variable/Method/Constant,
- Go to Test, and
- Run/Debug Tests.
Additionally, I would recommend creating your own keymap for shortcuts with ones you can easily remember. I’m a big fan of two-key shortcuts—for example I have configured:
- Ctrl-G Ctrl-T for Go to Test
- Ctrl-G Ctrl-L for Go to Line
- Ctrl-R Ctrl-U for Run Unit Tests
Use Live Templates and “Generate”
Live templates allow you to create custom shortcut code that expands to bigger snippets. For example writing “$apples.fe” and pressing tab results in “foreach ($apples as <cursor>) {}”. There are some configured by default but you can also add your own for code you use often.
With Code > Generate (or in my case Alt+Insert in a file) you can additionally generate some common code/comment parts like getters/setters, copyright notices, or PHPDoc.
Quick Navigation
Learn how to get around in your code base: Make use of Navigate to File/Class/Symbol, learn how to open the file browser at the location of any file with a shortcut, find out how to quickly switch between test and implementation and navigate between the usages and declaration of a method with no more than a keystroke. While it doesn’t make you a better programmer, it gets you where you want to be faster and makes it a lot easier to follow code structures—for example when debugging an issue.
Run Tests
Running tests inside the IDE has the advantage that you can directly jump to offending code if tests fail as the files are linked in the info window. Additionally, when generating coverage in the IDE you can highlight uncovered code lines in the editor, making it easy to see missing tests while staying focused on the code.
Use the Debugger
Last but not least: Use the debugger. Do not var_dump/echo your way through the code — you will be much more efficient with a debugger as you can see more context, see the stack trace as well as evaluate code at a specific point of time. For example, when setting a breakpoint the PhpStorm debugger console allows you to not only inspect the current context but also to execute PHP in that context — calling a method, evaluating a condition and whatever else seems necessary. It takes some time to get used to it, but once you do, it’s an amazing tool.