PhpStorm 2020.1: support composer.json, tools for PHPUnit, code coverage with PCOV and PHPDBG, Grazie and more



Hello, Habr! We are glad to present the first major release of PhpStorm this year!

Under the cut, a detailed analysis of all the noticeable changes and new features. Caution - a lot of pictures.

PhpStorm 2020.1 Toolbox App. 30- . JetBrains .

composer.json


All actions for working with dependencies are now available directly in the file composer.jsonand work directly in the editor.

You can create a new composer.json file from the context menu or by using the hotkey Ctrl(⌘)+N. The template for this file is in the Preferences / Settings | Editor | File and Code Templates .



Managing Dependencies

To add a dependency, just start writing the name of the vendor and package, and a list of auto-completion with the appropriate options will appear. Available versions of this package will be offered



in the version field . For now, a carriage (^) or other symbol to indicate a range of versions will have to be added manually, but in future releases we will fix this.
For requirements on the version of PHP or the presence of extensions, auto-completion will also work.

Updating and installing packages

If composer.lockthere is no file yet and no packages are installed, then PhpStorm will highlight the section name requireand require-dev. To install them, you can click the Install button in the toolbar above the editor. Or use the quick click action Alt(⌥)+Enterand select Install packages.



But if not all packages are installed, then PhpStorm will highlight the missing ones. Then Alt(⌥)+Enteryou can call on any of them and select Update package or Update all packages .

Next to the specified version requirement, the gray version will be the version of the package that is actually installed. And in the pop-up dialog for packages there will be information from packagist.org about the number of downloads and stars.



PhpStorm takes all the information about packages and their versions from packagist.org and caches them.

Navigation to files and folders

Surely you know that by clicking Ctrl(⌘)+Clickand Ctrl(⌘)+Byou can go to the definition of entities or search for their use.

In composer.jsonthis, too, will work. If you click Ctrl(⌘)+Clickon a package, the corresponding directory will be highlighted in the Project Tree. And if on a file, then it will be opened in the editor.



Clicking on Ctrl(⌘)+Clickor Ctrl(⌘)+Bon any link in composer.jsonexpectedly opens it in the browser.

Auto completionin autoload sections (-dev)
Auto-completion based on information from classes and the directory structure of the project works for namespaces and paths.



Ctrl(⌘)+Clickand Ctrl(⌘)+Bto go to files and folders works here too.

Improvements for scripts

Firstly, transitions to files / folders / methods work in the same way. Secondly, aliases for teams are supported. And thirdly, scripts can be launched from the editor by pressing the [play] button opposite the script name.

This automatically creates a Run configuration. This means that you can re-run the script with a hotkey Ctrl(⌃)+R, which is quite convenient when debugging:



Installing code quality tools
If there are dev dependenciesFriendsOfPHP/PHP-CS-Fixer, then PhpStorm will check if the appropriate inspection is enabled and if the rule set is installed. If not, you can call Alt(⌥)+Enterto fix it:



PHP type inference improvements


The type inference engine is the foundation of PhpStorm, and in this version a few notable changes have been made.

Extra tag highlightingvar
Adding tags @varis a good way to tell PhpStorm the type of a variable. But we are constantly improving type inference, and some of these declarations may well be redundant, because PhpStorm already knows the type of the variable.

Such cases will be highlighted, and they can be removed using quick fix Alt(⌥)+Enter-> “Removevar :



Tracking null types is a difficult task, and there were places where PhpStorm could not handle it. Now in 2020.1 PhpStorm knows when a variable can be null and when not.

Here are some examples:



Auto-completion for an initialized array

Let's say you have an array with known elements, and later you try to iterate over it. Previously, autocompletion did not work here, since the type information was lost. In 2020.1, everything works:



Autocompletion in array_map / array_filter.

In the closure body, which is passed to the array_map () and array_filter () functions, the complement for arguments now works.



Code Coverage Using PCOV and PHPDBG


You can build code coverage with Xdebug . But since this is primarily a debugger, it has decent overhead. To speed up getting a coverage report, you can use more lightweight tools: the krakjoe / pcov extension or the PHPDBG built into PHP 5.6+.

Both are now supported in PhpStorm. You need to create a Run configuration for the tests and select the desired coverage driver in the settings. Then run the tests with coverage calculation by clicking the button :



Read more about the differences in coverage calculation between Xdebug, PCOV, and phpdbg in README .

PHPUnit Toolkit


In the recently released PHPUnit 9 (and already 9.1), many features have been removed or deprecated. To speed up migration and prevent errors, we added a bunch of inspections and quick fixes.



Create a new test for the class

By calling Alt(⌥)+Enteron the class declaration and selecting Create New PHP Test you can quickly get the skeleton for the test.



Metadata


The metadata in the file .phpstorm.meta.phpallows PhpStorm to provide additional information about your project and thereby improve code completion. For example, this feature is used in the Symfony plugin and in the Laravel IDE Helper .

You can learn more about the capabilities of metadata from a PHP report as a development tool for PhpStorm on PHP Russia 2019.

PhpStorm 2020.1 has added a number of improvements for metadata.

Parameter index directives override, map, and type

Before using override(), map()and type()you can change the behavior of the first argument functions. In PhpStorm 2020.1, you can specify an arbitrary parameter index:



Access to properties through __get

If you received property values ​​through magic __get(), then information about the type was lost. It was possible to use additional tags @varor @property, but this did not always save. Now you can specify everything through metadata.



Auto-completion of keys in objects implementing ArrayAccess

Metadata supported ArrayAccess objects, but suggested only the type of values. Now possible keys are also auto-completing.



Custom exit points

PhpStorm considers type functions die()and exit()or throwing exceptions to complete execution. But applications may have more complex exit points. For example, simple dd()or trigger_error function with argument E_USER_ERROR .

In PhpStorm 2020.1, you can mark functions as exit points, and this will adjust the flow analysis accordingly.



Icons for functions redefined via metadata

Opposite to declarations of functions whose behavior has been changed with override(), exitPoint()or expectArguments(), an icon will be displayed. Clicking the icon will open a file .phpstorm.meta.phpin which the behavior changes, because there can be several files.



Icons can be hidden in Preferences / Settings | Editor | General | Gutter Icons .

Machine learning to sort the list of add-ons


Added ranking of auto-completion options based on machine learning.

How to see ML in action?

Auto-completion with ML is disabled by default. We don’t want robots to rob us of our work! To enable it, go to Preferences / Settings | Editor | General | Code Completion and enable the options Rank completion suggestions based on Machine Learning and PHP .

If you also enable the option Show position changes in completion popup , then the auto-completion list will show how the order of the elements has changed.



We plan to prevent the uprising of cars to continue to work in this direction in future versions.

New Inspections


A private property can be a local variable.

A property definition will be highlighted if it is used in only one method and is immediately overwritten in it. To fix, you can call the quick fix Alt(⌥)+Enter “Replace property with local variable” .



Extra property initialization

Suppose a private property has a default value in a class, but in the constructor it is immediately overwritten with another value. In this case, the default value is redundant and adds only noise.

An unused initializer will be highlighted, and it can be removed with a quick fix Alt(⌥)+Enter “Remove redundant initializer” .



Change property type in PHP 7.4 to default value



Redundant ternary operator

PhpStorm will highlight trivial ternary expressions and with a quick fix Alt(⌥)+Enteryou can replace them with simpler ones:



Redundant transfer by reference

Using transfer by reference can lead to unexpected consequences, and this is one of the reasons why Nikita Popov suggested allowing explicit transfer by reference when called functions in PHP.

In the meantime, PhpStorm 2020.1 will highlight the parameters declared as passed by reference, but not used as such. They can be safely removed with quick fix Alt(⌥)+Enter.



The same will work for arrays with a link in the foreach loop:



Remove the extra PHPDoc, in which only the type declaration is now also quite simple thanks to the corresponding quick fix.



True, by default, the inspection is at the Info level , that is, it will not highlight. If you want redundant PHPDoc blocks to be highlighted, then to inspect the Redundant PHPDoc comment in Preferences | Editor | Inspections, set the Weak Warning level or higher.

Updated refactoring “Move method”


Sometimes it may be necessary to transfer a method to another class. If this method is used many times in the project code, then PhpStorm can help here.

Previously, you had to first make the method static, and then call another action to transfer it. In PhpStorm 2020.1, the “Move method” refactoring has been reworked into a single atomic action. Removed extra steps and pop-ups, and everything is done in one go.

Hover over a method and press F6(or Ctrl+T, 3). Then select the target class and you're done.



To see all the available refactorings , you can click Ctrl+Tanywhere in the code.

PHP Debug in HTTP Client


Now, to selectively enable debugging, you do not need to bother with the request parameters or install the extension in the browser. It is enough to create an HTTP request in a file .httpand send it with the PHP Debug command , which is available in the menu Alt(⌥)+Enteror by clicking on the icon. As a result, a cookie will be automatically added to the request XDEBUG_SESSION.



And some more little things for PHP


@ deprecated elements are displayed as crossed out in the Structure tree view
Ctrl(⌘)+F12



Highlighting matching tags <? php /?>



Jump to the opening / closing bracket

Shift+Ctrl+M (⌃+M)



Lexer customization for Twig

Sometimes you may need to change the tag characters for Twig templates, for example, if you also use Angular, which has such same syntax.
You can do this in the Preferences / Settings | Languages ​​& Frameworks | PHP | Twig .

IDE


Grazie Advanced Spelling and Grammar


Grazie plugin is included in PhpStorm out of the box, which checks the text not only for spelling errors, but also for grammar and style. Moreover, 16 languages ​​are supported, and all checks are performed locally without sending your data anywhere.



By default, checks are enabled for Markdown files.
You can also include them for all string literals, comments, PHPDoc blocks, and commit messages.

For PHP, you can enable in Settings / Preferences | Editor | Proofread | Grammar .

LightEdit Mode


Sometimes you need to quickly look / fix the file and open an entire IDE for this, it seems too much, but you want to have the usual backlight and functions. It is for such cases that we are working on the lightweight LightEdit mode.

It works like this: if you open the file from the command line or the context menu of the operating system, while PhpStorm is not running, the file will open in LightEdit. Well, if a full-fledged PhpStorm is already working, then the file will simply open in it.



JetBrains Mono - default font




Zen mode


The new mode combines Distraction Free and Fullscreen for deep immersion in the code.
View | Appearance | Enter Zen Mode



Interface


Terminal window split


Instead of opening new tabs and switching between them, you can now split the screen and open several sessions in one tab. To do this, select Split Horizontally / Vertically from the terminal context menu .



IntelliJ Light

Theme The light theme has been slightly updated and unified to look the same on all OSs, and its name has changed to IntelliJ Light .

Customization of the status bar

From the context menu, you can choose what information will be displayed on it.



Configuration


Unified SSH Configuration


Previously, if an SSH connection was reused in a deployment, Remote interpreter, or SSH terminal, it had to be reconfigured each time.

Now all SSH connections can be added / edited in the Preferences / Settings | Tools | SSH Configuration , and then use them repeatedly where they are needed.



The path to the IDE configs has changed


For example, on macOS:
- ~/Library/Preferences/PhpStorm2019.3
+ ~/Library/Application Support/JetBrains/PhpStorm2020.1


More in the help .

Custom path to save run configurations


Previously, Run-configurations were stored in a folder .ideathat many completely add to .gitignore (better like this ). Now you can choose any path and share the Run-configuration with colleagues through the version control system.

It can be especially convenient when onboarding new employees: pulled off a project, opened in PhpStorm, launched with one button.

To do this, in the Run / Debug configuration dialog you need to select the Store as project file option , and by clicking the gear you can select the desired path in the project.



Version control


New Commit


The Commit window is available in non-modal mode and is displayed on the left. Thus, it does not block work on other files during the preparation of the commit, and more information about the changes is placed on the screen.

The new Commit is turned on by default for new users and off for those who already have PhpStorm installed.

Enabled by the Use non-modal commit interface option in Preferences / Settings | Version Control | Commit .



Git Branch Enhancements


In the lower right corner of the IDE window, the current Git branch is indicated. If you click on it, the VCS | Git | A branches .
Here we added a search field. The Refresh button updates the list of remote branches. And for each commit, an indicator is added: incoming (blue) or outgoing (green).



Redesigned Interactive Rebase


Git Rebase lets you rewrite the history of commits. Now you can quickly get rid of "temporary" commits, correct the message or the order of commits. Of course, all this can be done from the console manually, but PhpStorm allows you to immediately see what has been changed in a particular commit.

To begin, in the history of commits, you need to select the desired basic commit and select Interactively rebase from here from the context menu .



DB Tools


PhpStorm includes almost all the features of DataGrip out of the box, so you can see the review of the DataGrip 2020.1 release from our colleagues.

Web


And, as always, all updates from WebStorm 2020.1 are also included in PhpStorm.

A complete list of changes can be found in the very large release notes .

You can also watch the release overview on the “ What's newpage and if you only have a few minutes, then here is a short video (in English) with a demonstration of the main features of the release:



And that’s all this time. Thank you for reading to the end! We will be glad to questions, wishes, bug reports and just thoughts in the comments.

Take care of yourself!
Your JetBrains PhpStorm Team

All Articles