PhpStorm plugin User Guide

Coding Standards

Project Structure

Analyze used code consistency with the specified module dependencies

The Magento 2 & Adobe Commerce are systems that use modules under the hood as a part of their components. Each module can interact with any of the core modules, 3rd party extensions or customisations through the SAPI principle, plugins, observers, preferences etc. This makes the system flexible and easy to customize. But with this flexibility, it is essential to pay attention to the sequences between modules and, as a result, components. This is an integral part of high-quality solutions because, with the significant change of one module (or even its deactivation) that is a sequence to the list of other modules, the whole component can be broken.
According to the best practice of Magento 2 & Adobe Commerce and general principles of the software architecture, there are two files that should be maintained in the scope of the sequence setup between components: module.xml and composer.json of the module.
The “Analyze used code consistency with the specified module dependencies” inspection helps to identify unspecified sequence declarations. Two examples below show how the corresponding functionality works for composer.json and module.xml.


Compare *.phtml templates overridden in the Magento 2 module

One of the common tasks during the project analysis or investigation of errors in templates is to compare differences between *.phtml templates. Having the ability to quickly access the difference between files saves a lot of developers' time.
The “Compare *.phtml templates overridden in the Magento 2 module” functionality benefits in the ability to show the difference between *.phtml files based on the Set the template used by a bloc. In such cases, described functionality identifies the original file automatically and shows the difference.
Compare functionality also represents selection between parent and overwritten theme comparison.


Show template overrides in the editor context action

This feature provides the ability to show template overwrites directly from the file context menu in the PhpStorm which is possible to show with the right click on the file. This feature is valuable for quick access to the file that allows developers to avoid search for the block and then file usage.

Navigate to Factory and Proxy classes from their declaration in XML files

Better user experience of software engineers is the goal of this functionality. The factory and proxy classes navigation from the XML files leads engineers to the classes directly from the XML. This feature is enabled by default and its setting can be find by the following path Preferences > PHP > Magento 2 Support > Navigation Settings > Navigate to real class if generated(factory/proxy) class is available (only XML files are supported).

Navigate to the class source from its declaration in different XML files

With this functionality it is possible to be directly redirected to the class form XML files. For example, in the di.xml file from the plugin type declaration.

Navigate to the module from the module name in the config.php file

With this functionality developers can quickly access modules from the config.php by their names. Open the config.php file, choose the needed module and click on its name.

Navigate to the module from the sequence tag

With this functionality, engineers can navigate from the module.xml sequence tag to the corresponding module in the project tree.

Auto-detect Magento 2 / Adobe Commerce installation path

The plugin can automatically detect that the current project is Magento 2 or Adobe Commerce based and define its installation path.  When the plugin detects, it shows the corresponding notification, as on the screenshot below.

Custom code and design directories support

As an application-level dependency manager, the composer provides excellent flexibility for project component structure. The prominent feature is the ability to use different types of code sources through the repository concept. Composer allows engineers to add the local directory with the repository path type.

Described functionality in the paragraph above is one of the possible way of components organisation in Magento based projects. With the "Custom code and design directories support" functionality, engineers get full functionality support for custom directories: inspections, module creation options, navigation etc.

The plugin automatically detects custom code and design directories defined in composer.json with the path type and updates the plugin's configuration settings. The following path can find the configuration setting responsible for the custom directories path keeping: Preferences > PHP > Magento 2 Support > Project Settings > Composer local paths. Automatically detected paths are represented in the grid. You can manually add, edit or remove paths.

Components elements generation

Create new Magento 2 module/theme action

The plugin provides functionality for the new Magento 2 module generation. A new module can be created on the vendor level if it already exists. Or vendor namespace can also be initiated during module generation. To run module generation on the vendor's level, choose in the navigation tree necessary vendor, call the context menu on the selected vendor folder and choose the New > Magento 2 module.
In the appeared pop-up define the module's name, and description and, if needed add dependencies. To add dependencies click on the plus symbol in the Dependencies section. In the pop-up use the search field for modules search or scroll the list. To select a module and add it as a dependency, click on it in the list of modules and be sure that it is selected in the search field. This is a required step because this is the standard behaviour of the search form in PhpStorm IDE.
When all data is set, press the OK button to create a new module. The module created with the help of the described functionality has etc/module.xml, registration.php,, composer.json
The same approach is used for theme generation. The main idea is to create a basic theme skeleton. To do this select the theme folder under the design directory, call the context menu on it, and the New > Magento 2 theme click.
In the appeared pop-up the theme the basics should be configured: vendor, name and parent theme.
After pressing the OK button a new theme is going to be created with the following files: composer.json, theme.xml, registration.php

Inject copyright into the configuration files

This functionality allows engineers to automatically add copyright text into the module's configuration files such as module.xml, di.xml etc.

To define copyright for project you can do following: open PhpStorm > Preferences > Editor > Copyright > Copyright Profiles. Then define profile and select it in the Copyright section.

Magento Test Coverage Support

Add test source filter support for Magento

This functionality allows developers to quickly sort test files in the project tree. That allows to save time for project maintenance and search in case of a large number of test files.


Run configurations for the Magento CLI commands execution

The PhpStorm IDE has a beneficial functionality which is called Run/Debug Configuration. It allows engineers to create, for example, run configuration for a specific CLI command that can be quickly executed locally or even on a remote instance. This saves time and reduces cognitive pressure if you need to run a list of commands too often during your development phase.

The plugin provides the possibility for engineers to create Run/Debug Configuration for the Magento CLI commands. Under the standard menu that represents Run Configurations there is a new option: Magento CLI Command.
The Magento 2 CLI Command run configuration helps engineers define to which domain run configuration belongs (cache, catalog, CMS, etc.) and automatically show the list of available commands. This is very helpful. For example, if the application development process requires running, reindexing and cache clean operations call often. There is no need to create custom scripts or copy-paste sequences of CLI commands. Everything can be configured in the IDE and run by click. Note that you can generate a series of run configurations and even run/define CLI commands with parameters.
There is one required precondition: the PHP interpreter should be configured. How to configure it you can find at the official PhpStorm documentation: Configure local PHP interpreters

Git related features

Analyse if a new module is added to the config.php file while committing it

This functionality's primary goal is to prevent situations when newly created modules are not added to the config.php. This situation leads to unnecessary commit and re-deployment. And as a result, time-consuming operations slow down delivery.

Described functionality is enabled by default. If it is needed to turn off, setting is located under the following path: Preferences > PHP > Magento 2 Support > VCS Settings > Check if modules are added to the config.php while commiting
The screenshots below show different situations. At the first one, the commit is organised and prepared to be delivered with the help of the PhpStorm Git functionality. The plugin identifies a new module in the project, but it was not declared in the config.php. Appropriated notification is showing.
Another level of assistance with this case is to check whether the config.php with the new module was added to the commit. It is possible that after adding a module to the config.php engineer can forget to add it to the commit. The plugin identifies this problem and reports it back to the engineer.