Cover Image for How To Setup PHPStorm for Magento Development

How To Setup PHPStorm for Magento Development

PHPStorm from JetBrains

Magicento

Go buy this extension and install it.

Magicento

It's $32 so the first time you use it to automatically build a Module Stub you'll have saved yourself 15-20 minutes and you'll have covered the cost.

Line Sepator

Hit CTRL-ALT-s to bring up the settings menu.

Navigate to: Editor > Code Style : General

Line separator => Unix and macOS (\n)

Line Separator

2. PSR-1 / PSR-2

Hit CTRL-ALT-s to bring up the settings menu.

Navigate to: Editor > Code Style > PHP

Click "Set from..." on the top right.

Set PSR

Choose "PSR1/PSR2" from the drop down menu.

PHP

Hit CTRL-ALT-s to bring up the settings menu.

Navigate to: Languages & Frameworks > PHP

Set your PHP Language level

Set Language level

Click the "..." next to CLI Interpreter

CLI interpreter

Click "+" to add a new binary

Add new binary

Choose where ever your PHP executable is located

PHP executable location

Hit OK

PHP_CodeSniffer

This step requires PHP and composer installed so you don't meet those criteria go do that now.

Install via composer: https://github.com/squizlabs/PHP_CodeSniffer

composer global require "squizlabs/php_codesniffer=*"

Clone the Magento Coding Standard repo to your computer somewhere.

git clone https://github.com/magento/magento-coding-standard.git

Add the Magento Coding Standard sniffs to php_codsniffer

phpcs --config-set installed_paths F:\magento-coding-standard\

Note here the path that is specified above is where you cloned the Magento Coding Standard repo to.

Verify that phpcs has the sniffs

phpcs -i

command output

Hit CTRL-ALT-s to bring up the settings menu.

Navigate to: Languages & Frameworks > PHP > Quality Tools

Expand PHP_CodeSniffer

CodeSniffer configuration

Click "..." to choose a preset standard

Standards chooser

Choose the phpcs executable in for the path

Set executable path

In Windows 10 for me it was: C:\Users\Will\AppData\Roaming\Composer\vendor\bin\phpcs.bat

Click "Validate" and you should get a success message

Validation success message

Navigate to: Editor > Inspections

Search for: "quality tools"

Search input

Choose: PHP_CodeSniffer validation

Click the checkbox such that it's enabled

Checkbox location

Choose a "Severity" and a "Warning" level. I like "Weak Warning"

Severtiy chooser

Check "Show sniff name"

show sniff name toggle

In the drop down list for "Coding standard" choose "Magento2"

Standards picker

Click "Apply"