Setting up PhpStorm for Magento 2

Page 1

Setting up PhpStorm for Magento 2 Magento 2 combines a lot of approaches and built-in tools designed to facilitate all development processes, and most significantly, enhance our source code quality. If used correctly, it raises our product’s quality significantly. One of the most important tools for quality developments in Magento is PhpStorm, also known as “Intelligent coding assistance” and a “PHP IDE that actually “gets” your code”. And that’s not just a slogan from an ad banner, that’s what PhpStorm actually is for developers. Listed below are some key tips & tricks for configuring your PhpStorm for the easiest and most enjoyable developments in Magento 2. Use Static Code Analysis Magento 2 already includes a ready-made set of standards and rules for PHP Mess Detector (phpmd) and Code Sniffer (phpcs). Use these tools to validate code against Magento 2 standards without even running the code itself. Results you get by correctly using static code analysis include code validation on-the-fly and high validation speed. How to configure your Code Sniffer in Magento 2 correctly? Code Sniffer validates the code against many different standards of formatting, for availability and accuracy of comments arrangement and other similar administrative functions. You can find the file with the rules set in: dev/tests/static/testsuite/Magento/Test/Php/_files/phpcs/ruleset.xml To include the rules set into Code Sniffer in Magento 2, just project follow these simple instructions:      

Go to PhpStorm / “Preferences” From the sub-menu “Editor” in the left menu choose “Inspections” Find in the list PHP / “PHP Code Sniffer validation” Turn “Validation” on Choose “Coding Standard” / “Custom” and click “...“ Now choose the directory “dev/tests/static/testsuite/Magento/Test/Php/_files/phpcs/”

How to use PHP Mess Detector to detect possible errors and complications? PHP Mess Detector detects possible errors and complications, but PHPMD also executes the static code analysis. Also it rather targets detecting possible errors and code fragments which are too complicated for interpretation (classes, methods). If your code passes all validations and tests (especially on compliance with the rules CyclomaticComplexity, CouplingBetweenObjects, NPathComplexity), then it is easy to read and to test. This way code also contains less of potential errors.


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.