How I use PHPStorm

This is from a speech I gave on Vancouver PHP meetup and where I talk about my usage of PHPStorm.

How I use PHPStorm

This post is from a speech I gave during the Vancouver PHP Meetup (if you're in the Vancouver area please do join us!) on the 19th July 2018.

Note: I'm using a Mac and the shortcut showed here will use MacOS key modifier. You can always find the equivalent for your platform with Help > Keymap Reference.

Introduction

Over the past years as a PHP developer, PHPStorm became my IDE of choice. It is a great help to every day tasks and even more. I switched to PHPStorm 5 years ago and never went back. It offers everything I need for to develop and design code. It got everything :

  • auto-completion and code navigation to anything
  • diagrams for class relationship
  • framework knowledge via plugins
  • security and performances tips
  • debugger
  • console
  • and many more

It also offer the possibility to customize it to your needs. And because I've been using for so long now, I have usually a disturbing setup for anybody else using my setup.

My Setup

As you can see I pretty much have stripped out any UI component or panel. At first sight:

  • No tabs
  • No menu
  • No panel

At first sight, because let's be honest without any UI showing up and being just a plain text editor I might be using VS or Atom at this point. But the only thing to know about PHPStorm is that every menu action is reachable by shortcuts. So yes I'm obviously using a lot of shortcuts to work in this very minimalist environment.

My 15 most used shortcut

1. ⌥ + ↑ (expand selection)

This one and is opposite ⌥ + ↓ helps to expand or narrow my selection under my cursor.

2. ⌃ + Space (auto completion)

Auto completion with context, which means it gives you really good auto completion, one I never found in any other IDE, and not even talking text editor (looking at you Sublime)

3. ⌥ +⏎ (Show intentions actions)

Menu for PHPStorm suggestion of reformatting. It combines really well with PHP EA plugin.

4. ⌘ + B (goto)

Goto definition or call, no more ⌘ + Left Click, only keyboard. This one of the most useful shortcut to navigate your code either you need to go where the current class or method you're looking at is defined or to go where it is actually called.

5. ⌘ + E (recent opened files)

As I am not using any tabs, I cycle through recent opened files with this one.

6. ⌃ + ⇥ (recent files)

This one is used in combination with the precedent to navigate through files, this is one is actually showing me the 10 recent active files I'm working on. I set that to 10 max as I am never working on more than 5 files at the time on regular basis and I should never go over 10, otherwise there is something wrong with my current PR (reduce your PRs size, everybody will thank you).

7. ⌘ + O,  ⌘ + ⇧ + O,  ⌘ + ⌥ + O (Open Class, Open File, Go to symbol)

With those 3 bad boys you should be able to OPEN. ANY. THING. And if you're only working with PHP files and PSR-4 you should not even need the second one.

8. ⌘ + F12

In PHP editor this open up the structure of the class, in Database editor you can jump to any column, and because in PHPStorm you can type anywhere to have fuzzy search in the popup/panel/window, this is actually very helpful when in a class I want to jump directly to the method I want or look for a specific method by name.

9. ⌥ + ⌘ + V,  ⌥ + ⌘ + M,  ⌥ + ⌘ + C (Extract)

Those 3 shortcuts are my absolute favorite, they are what make PHPStorm so powerful: it can extract code into a variable, a method or even a class directly.

Just try it and you'll see it will speed up your workflow.

If you don't want to remember all those 3 you can always use this one: ⌃ + T and then type the number you want to get it done directly:

Refactor menu

10. ⌥ + ⌘ + T (Surround with)

Quickly wrap your code with `if` statement or loops or try/catch or any other block. And as always you can type the number to do it directly.

11. Double ⇧ (Search Everywhere)

If you only have shortcut to remember this is gonna be this one. It allows you to search literally anywhere in PHPStorm whether it's code or even PHPStorm menu entry, or enabling/disabling options.

12. ⇧ + ⌘ + N (Scratch Files)

Scratch files are very handy when you need to mess around with some code you want to test, and PHP Scratch Files can even be ran from PHPStorm as long as you have an interpreter setup, it will give you the output in the console tab of PHPStorm. If you're familiar with Laravel Tinker, think of Tinker as being part of PHPStorm giving the possibility to use history on the scratch file for instance. I use that a lot for building SQL queries or testing stuff on the go.

13. F1 (Documentation)

Gives you the documentation extracted either from the PHPDoc of your code or even built-in functions and classes of PHP. Very handy if you don't want to switch to the official documentation and save time.

14. ⌥ + ⇧ + ⌘ + I (Inspections)

Inspections are very powerful and allows to even mass fix code with the inspection's rules or give you a quick preview of the code's health. Very nifty to run this just before a commit. You can setup your own rules or set of rules.

15. Type anywhere

In any panel/window, you can type and it does fuzzy search.

16. Bonus

  • ⌥ + ⌘ + L : format code given the rule you've set
  • ⇧ + ⌘ + F12 : toggle panes, I can quickly hide them or show them (this is the trick for a minimal look ;) )
  • ⌘ + 1 : open/close a pane associated to a number as in:
Pane with the associated number

If you want to discover what are your stats you can always go to Help > Productivity Guide.

Tools

PHPStorm comes with tools that make me stay in it and never leave it. Productivity at maximum.

  • VCS, but mostly Git (combine with the fuzzy search for the branching and task on pre-commit makes it powerful)
  • Interpreter: allows PHPStorm to be aligned with the PHP version you are using and execute some code
  • Unit Tests: running tests from the IDE and even have code coverage help is really a must-have nowadays
  • Debugger: debugging step by step is always gonna be more effective than just dumping some random var
  • Inspections: as mentioned those are very priceless

Plugins

  • PHP EA: If you have only to install this is the one, providing more insights that you could know and even gives you documentation on some suggestions. I've discovered many good practices like this.
  • Symfony/Laravel: If you work with one of those frameworks, they will make your life easier.
  • PHP Annotations: Really handy if you're working with Doctrine.
  • Key Promoter X: Everytime you use your mouse for an action and if a shortcut exists it will tell you.

I just want to add that it’s only me and and my way of using PHPStorm, I don’t want to convince anyone that PHPStorm is better that what you are currently using, you may have the same features on your IDE.