PhpStorm Guide

First off, please check out the PhpStorm Docs & Demos. You’ll want to take a close look at WordPress Development using PhpStorm.

See also the How we use PhpStorm for WordPress Development from Delicious Brains.

Projects

When you start working with PhpStorm you should create a new project. The PhpStorm project should be rooted in the site project you’re working on, usually where the .git directory is located; on VIP projects, you can create the PhpStorm project at the root of the VIP Quickstart repo, so one PhpStorm project would be used for multiple VIP sites and clients.

When you create a PhpStorm project, you’ll see a .idea directory created. Add this to your Git repo’s .gitignore.

CLI Command

PhpStorm provides a pstorm command line tool. You install this via Tools > Create Command-line Launcher…. Once installed, you can open the .idea PhpStorm project from the current directory via:

pstorm .

If the project doesn’t already exist, PhpStorm will create the project (the .idea directory) in the current working directory.

Keyboard Shortcuts

  • Command-Shift-A: Bring up a quick search for all commands (so you don’t need to know the keyboard shortcut), such as “To tabs” to convert indents to tabs.
  • Command-Option-O: Open a search box for finding any symbol in the project, such as variable name, function name, class name, WP filter/action hooks, etc.
  • Command-Shift-O: Open search box for all files in the project to quickly open.
  • Command-O: Open search box for PHP classes.
  • Command-Shift-Backspace: Navigate back to the previous change you made.
  • Command-[ & Command-]: Navigate to previous location, or navigate forward.
  • Ctrl-Space: Bring up a list of autocomplete options.
  • Command-B: Jump to source declaration for the function, variable, or other construct.
  • Command-P: Show list of parameters in the current argument list.

Code Style

There is a WordPress code style that is bundled with PhpStorm. This will help auto-format your PHP and JS code as you write it to adhere with WordPress Coding Standards. To select the WordPress code styles for the current project, go to preferences and Editor > Code Style and then select “WordPress” in the dropdown.

Recommended Plugins

  • BashSupport — add syntax highlighting and code intelligence to Bash scripts

Version Control

Navigate to the Version Control pane in the preferences to see the (nested) repos that PhpStorm discovered in your project. For non-VIP projects, this may only be the root repo. But for VIP projects, there will be quite a few, for instance:

  • www/wp (SVN)
  • wp-content/themes/vip/plugins (SVN)
  • www/wp-content/themes/vip/newscorpau-metro (Git)
  • www/wp-content/themes/vip/newscorpau-metro-perthnow (Git)

When PhpStorm recognizes a file as being part of a repo, it will show in the left margin that it is modified (blue), added (green), or deleted (arrow):

phpstorm-modified

Clicking on the indicator will bring up a menu that allows you to see what was there before the change. You can navigate to the next/previous change, revert the change, open the diff in a viewer, or copy the initial value to the clipboard.

phpstorm-modified-menu

Languages & Frameworks

See:

Add your local clone of WP-CLI to your PHP include path:

php-include-path

And enable WordPress integration, pointing to your source on your local machine:

wordpress-integration

Other Resources

Xdebug Profiling

5 thoughts on “PhpStorm Guide”

  1. Solarized Color Schemes for PhpStorm

    Screenshot 2015-07-21 10.57.35

    Solarized is a sixteen color palette (eight monotones, eight accent colors) designed for use with terminal and gui applications. It has several unique properties. I designed this colorscheme with both precise CIELAB lightness relationships and a refined set of hues based on fixed color wheel relationships. It has been tested extensively in real world use on color calibrated displays (as well as uncalibrated/intentionally miscalibrated displays) and in a variety of lighting conditions.

    https://github.com/jkaving/intellij-colors-solarized

  2. Anyone know how to get PHPStorm’s builtin PHPCS tool (which includes code coverage indications besides line numbers) working with Vagrant?

    1. PhpStorm should just use the phpcs that is available on your system’s PATH. On my machine, I’m using PHPCS which is installed in VVV:

      /Users/thunderboy/Projects/vvv/www/phpcs/scripts/phpcs

      See also info on how to install PHPCS standalone.

      Here’s what my PhpStorm settings look like:

      code sniffer config

      code sniffer config 2

      If you just install PHPCS and WPCS into a directory inside of a Vagrant synced folder, then it will be available inside and outside.

  3. I’ve enabled the “WordPress Code Style” but when I actually write code it doesn’t enforce it. For instance, when I open an if statement, I still have to add the spaces around the parenthesis myself. If I don’t add them, I have to run phpcs to detect the error. Is this usual behaviour?

    1. @mattgeri I think the code style feature is specifically for when pasting in code snippets and when doing the “Reformat Code” feature. Beyond that, the code style is limited in how it forces you to write in a certain style. That’s my experience.

Leave a Reply

Your email address will not be published. Required fields are marked *