One of the most important tools for quality developments in Magento is PhpStorm:
That’s what PhpStorm is for developers.
Maybe you have already read a lot on the topic. But we gathered our real experience and aggregated it into this post for you.
Below are key tips and tricks for configuring PhpStorm for your easy and enjoyable developments in Magento 2.
Magento 2 includes ready-made set of rules and standards for Code Sniffer (phpcs) and PHP Mess Detector (phpmd).
Use these tools to validate code against Magento 2 standards without even running.
Results you get:
Configure your Code Sniffer correctly
Code Sniffer validates the code against standards of formatting, for availability and accuracy of comments arrangement etc.
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 project follow this simple 6-step instruction:
Congratulations! You did it!
But how to check, if it is working fine? If you have configured all settings properly, you would see the following result:
P.S.: If you have not configured PhpStorm before, you had to specify the direct destination of phpcs. You can do it in the menu item PhpStorm -> Preferences -> Languages & Frameworks -> PHP -> Code Sniffer. Here you should specify the destination to the file in the section Development Environment.
PHPMD also executes the static code analysis. But it is more aimed at detecting possible errors and too complicated for interpretation code fragments (classes, methods).
We can make a bold claim according to our experience, that if your code passes all tests and validations (particularly, on compliance with the rules CyclomaticComplexity, NPathComplexity, CouplingBetweenObjects), then it is easy to read, to test and it contains less potential errors.
Configuration process of PHPMD in PhpStorm is similar to the Code Sniffer setting up procedure, except for the rules set file: dev/tests/static/testsuite/Magento/Test/Php/_files/phpmd/ruleset.xml
If you have done everything accurately, you would get the result from the screenshot below:
Unlike Magento 1, every XML file in Magento 2 (layouts, etc/*) must comply with XSD schemas.
If any error occured while XML files editing process, PhpStorm will show it:
It’s a precise habit to perform checking for errors in XML files.
To use this feature, simply execute the following command in ssh terminal: bin/magento dev:urn-catalog:generate .idea/misc.xml
In the process of development PhpStorm regularly indexes all project files and their changes. This action is important for building relations between classes and for autocomplete.
But every project includes lots of files, which are not necessary to index. Furthermore, the exclusion of those files allows to enhance PhpStorm performance in everyday activities.
We recommend you exclude the following directories:
Follow this instruction to exclude suggested directories:
So, this is it. Now your basic configuration of PhpStorm is ready. We hope our experience, tips and tricks on this process helped you to pass it easy and enjoy your developments.
This Article was originally published on this link – bit.ly/1TafjTX