PhpStorm for Drupal 8

This is not a 'how to use PhpStorm with Drupal' type post, you can find good instructions here about using Drupal 8 in PhpStorm. This is a list of a few things I did when setting up a Drupal 8 project for the first time in PhpStorm.

Drupal Integration

In File > Settings > Languages & Framework > PHP > Drupal: Enable Drupal integration and let PhpStorm know details about your Drupal project.

Vagrant VM

In File > Settings > Tools > Vagrant: Let PhpStorm know about your Vagrant executable and instance, click the 3 dots and add a new remote and choose Vagrant. It should auto detect everything. If you go to File > Settings > Languages & Framework > PHP: choose the CLI Interpreter of the Vagrant environment.

Symfony Bridge

The Symfony Bridge Plugin integrates support for Symfony components. A MUST-HAVE if you're a 'proper' Drupal 8 developer. Enable by going to File > Settings > Plugins.

EditorConfig

EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs. Drupal 8 has an editorconfig file in the project folder so we can take advantage of that by installing the EditorConfig plugin at File > Settings > Plugins.

Debugging with Xdebug

Drupal VM is defaulted to work with PhpStorm so no need to change the php_xdebug_idekey but you do have to enable it by setting php_xdebug_default_enable to 1 in the Drupal VM config.yml file. Also make sure xDebug is uncommented in the installed_extras list. Then provision your vagrant box. Setting up xDebug in PhpStorm with Drupal VM is not straight forward but a there is a good video with instructions here. Note: I had to add the following to my Drupal VM config.yml file to get debugging to work with PhpStorm:

php_xdebug_remote_connect_back: 0
php_xdebug_remote_host: 10.0.2.2

Code Sniffer / Drupal Coder

Go to the site project root on the command line and do the following:

composer require drupal/coder

Then in PhpStorm go to File > Settings > Languages & Framework > PHP > Code Sniffer: Click the box with 3 dots, and under PHP Code Sniffer (phpcs) path click the box with 3 dots and navigate to your project /core/vendor/bin/phpcs file.

 

@todo complete this