What’s New in PhpStorm 2020.2

PHP 8 Union Types support, new control flow engine for PHP, Extract Class refactoring, full support for GitHub pull requests, brand-new Inspection Widget, and support for OpenAPI.

PHP 8 Union Types

We have started rolling out support for PHP 8 with support for Union Types. In PHP 8.0 it will be possible to declare more than one type for properties, arguments, and return types. PhpStorm already fully supports this feature and can help you migrate effectively.

Convert PHPDoc to native union types

Convert PHPDoc to native union types

Union types used to be provided via PHPDoc, and now PhpStorm highlights such occurrences.

With the Alt+Enter quick-fix, they can now be converted into native union types.

This works anywhere that union types are applicable, including function arguments, return types, and properties. For properties, it takes into account default values, too.

Switch Language Level to PHP 8

Switch Language Level to PHP 8

To enable the PHP 8 related features, switch the language level to PHP 8 in any of the following ways:

  • Use the Alt+Enter quick-fix directly in the code editor.
  • Go to Preferences | Languages & Frameworks | PHP and use the PHP language level list.
  • Specify the PHP version requirement in composer.json, and PhpStorm will pick it up automatically.
Perform type validation

Perform type validation

PhpStorm analyzes calls, calculates possible types, and highlights problem areas relating to union types.

The checks work on all levels: properties, arguments, and return values.

In complex code bases, it helps you see the problems at first glance. PhpStorm will highlight places that require attention even before the code is run.

Detect duplicate and redundant types

Detect duplicate and redundant types

There are many type combinations that are forbidden or redundant. For example:

  • bool|false
  • Foo|Foo
  • object|User
  • iterable|array or iterable|Traversable

All of them are highlighted by PhpStorm as invalid.

Work with nullable types

Work with nullable types

When there is a single nullable type, it is allowed to use either ?Type notation or Type|null in PHP 8.

But when there are multiple types combined with null, using ?Type1|Type2 is forbidden as ambiguous.

PhpStorm highlights these violations and provides an Alt+Enter quick-fix to convert them.

Follow variance rules

Follow variance rules

During inheritance, PHP allows you to modify types if you follow these basic rules:

  • Parameter types are contravariant, i.e. can be extended.
  • Return types are covariant, i.e. can only be narrowed down.
  • Property types have to evaluate to the same type.

Luckily, with PhpStorm there is no need to remember these rules as it will check the code and highlight any violations.

Use pseudotype false

Use pseudotype false

In PHP 8 there will be a special false pseudotype that can be used only in union type declarations.

It is widely used in the standard library, see strpos() or array_search(), for example, and can be applied elsewhere to indicate a negative result.

PhpStorm highlights incorrect usages and takes type inference into account.

Remove redundant PHPDoc

Remove redundant PHPDoc

After adding a native union type declaration, a PHPDoc may become unnecessary because it does not provide any extra information.

You can now remove it with a quick-fix Alt+Enter.

New Control Flow Engine

Condition always true

Condition always true

PhpStorm can now analyze complex code paths and detect if the condition in an if-else block makes sense or is redundant.

Result of ‘instanceof’ is always true

Result of ‘instanceof’ is always true

Similar to conditions, PhpStorm is able to detect when instanceof checks are appropriate, or if they always evaluate to true because of the inferred type in the type hierarchy.

New action: Type Info

New action: Type Info

The new action lets you see the inferred type of any selected expression.

When coding, you can select an expression and check its type by using the shortcut Ctrl+Shift+P or View | Type Info menu.

Expression is always ‘null’

Expression is always ‘null’

PhpStorm can detect when the variable is guaranteed to be null only. In this case, the IDE suggests simplifying the expression to make it clearer.

Quality Tools Improvements

Quality Tools Improvements
  • It is now possible to run quality tools via Docker Compose.
    To do this, go to Preferences/Settings | Languages & Frameworks | PHP, and add a new remote interpreter based on Docker Compose.
  • Reformat action for PHP-CS-Fixer and PHPCBF can now be run through a remote interpreter too.
  • If PHP_CodeSniffer’s ruleset.xml has an "exclude-pattern" section, PhpStorm will now take this into account and not analyze files under the specified path.

Composer Improvements

Managing Composer dependencies can be done in the editor directly inside the composer.json file.

Support for custom Satis/Packagist packages

Support for custom Satis/Packagist packages

If there are custom sources specified in the “repositories” section, you will get completion for custom packages.

There is now a gutter icon showing the current state of the caching of custom repositories.

Completion for multiple versions

Completion for multiple versions

When a package has multiple versions separated with a comma or pipes (||), PhpStorm provides completion with all available versions for this package.

It used to be that completion was lost after typing ~, ^, or >=, but now it works as expected with any of these range constraints in composer.json.

Quick access to settings of tools added as dependencies

Quick access to settings of tools added as dependencies

PhpStorm provides many integrations with third-party tools. Now, if a supported tool is declared in composer.json, there will be a wrench icon in the gutter beside it. You can click it to go straight to the corresponding section of preferences.

Extract Class Refactoring

Extract Class Refactoring

If a class gets cluttered and burdened with a lot of additional responsibilities, it is now possible to refactor it by moving methods and properties to a new class with the Extract Class refactoring.

Select a function, a method, or a property you’d like to move and press Ctrl+T and select Extract class.

The refactoring will create a new file, instantiate an object of the class in the constructor, and adjust the usages automatically.

Command Line Tools Improvements

Command Line Tools Improvements

Support for remote interpreters is now available for PHP Command Line Tools.

Under Preferences/Settings | Tools | Command Line Tool Support, add a new tool entry and choose one of the configured remote interpreters.

Laravel Artisan will now be detected automatically! It means that when you open a Laravel project, you can press Ctrl-Ctrl and start typing a command. PhpStorm will provide completion and suggest available commands.

New Inspections

Array used only with write access

Array used only with write access

If there is an array declared and updated somewhere in the code, but it is never read, it means that the array is very likely redundant and adds noise to the code.

The inspection detects such cases and prompts you to remove the array to make the code cleaner.

Typed property might be unassigned

Typed property might be unassigned

If a typed property does not have a default value, it is considered uninitialized. Reading uninitialized properties will generate a TypeError (unless magic __get() is defined).

PhpStorm detects uninitialized properties and highlights code that attempts to read them.

Full Support for GitHub Pull Requests

The entire Pull Request workflow can now be done in PhpStorm, and there is no longer any need to switch to a browser. You can manage pull requests; view the timeline and inline comments; add comments and reviews; and accept changes.

Full Support for GitHub Pull Requests

To start working with GitHub pull requests, open the Pull Requests tool window either from the toolbar or from the main menu VCS | Git | View Pull Requests.

Then select a pull request in the list to view all its details: the message, branch names, author, and so on.

From here, you can start the review process by checking the changed files and commenting on the changes – on both the commit level and line level.

Merging pull requests without leaving the IDE is also possible. There’s no need to create a local branch from a pull request, it all works out of the box.

OpenAPI Support

PhpStorm 2020.2 supports the OpenAPI Specifications plugin. This is a free plugin developed by JetBrains that provides completion, navigation, and validation in the OpenAPI spec files (openapi.yaml/openapi.json and swagger.yaml/swagger.json).

OpenAPI Support

The plugin also provides:

  • Swagger UI Integration.
  • Code generation.
  • Built-in structure Diff between OpenAPI specifications.
  • Gutter icons to create HTTP Client requests from specification.
  • Autocompletion for endpoints in HTTP Client.

New Inspections Widget and Problems View

New Inspections Widget and Problems View

In the top right-hand corner of the editor, you’ll see the brand new Inspections Widget with a summary of the problems in the current file.

  • Click arrows to jump between issues (or use shortcuts F2 / Shift+F2).
  • Click on the widget to see a list of all issues in the file in the Problems tool window.
  • Hover over the widget to see the settings popup and choose which issues to highlight.

Web Technologies

All the new features and improvements of WebStorm 2020.2 are available in PhpStorm 2020.2, either out of the box or with free plugins available in the Plugin Marketplace.

Prettier as the default formatter in JavaScript projects

Want to use Prettier instead of the built-in formatter to tidy up your code? With this update, it has become even easier than before. Just tick the new On code reformat checkbox and the IDE will use Prettier whenever you reformat your .js, .ts, .jsx, and .tsx files. Other file types can be easily added, too.

Best-in-class Vue.js support

Nuxt.js support, Vue-specific code style settings, improvements around Vue in TypeScript projects, and a lot of other things were added in the past year. Vue support in PhpStorm has never been so advanced!

Save some time with new features for JavaScript

New smart Alt+Enter intentions will help you perform some actions faster. For example, you can now quickly convert a for loop with a numeric index into a forEach array method. Looking through documentation comments in JavaScript and TypeScript files has also become easier as you can now render them right in the editor, minimizing distractions.

Version Control

Support for Git installed in WSL 2

Support for Git installed in WSL 2

PhpStorm 2020.2 supports Git installed in WSL 2 for working with projects located in Linux and Windows file systems.

The IDE can switch between Git executables depending on the project location. When a project is opened from WSL (via \\wsl$ path), the IDE will automatically switch to Git from WSL, and it will also provide you with the ability to use all the Git-related features in the IDE.

New UI to compare branches

When you want to compare two branches to see which commits do not belong to one another, PhpStorm 2020.2 will show the logs in the editor instead of the Git tool window. This will ensure that there is enough space to display all the information.

Choose the Compare with Current action from the Git Branches popup menu VCS | Branches.

Drop commit action

Drop commit action

You can now easily remove redundant local commits by selecting them in the Log tab of the Git tool window and choosing Drop Commit from the context menu.

Squash local commits

Squash local commits

It is also possible to combine several local commits into one single commit, for example, to clean up history before pushing.

In the Git tool window, select commits and choose Squash Commits… from the context menu.

The IDE will run an interactive rebase behind the scenes.

Database Tools

Take a look at What’s new in DataGrip 2020.2 – all these features are available in PhpStorm too.

Separate editor for cell values

Separate editor for cell values

Now if you have a huge value in your cell, it can be viewed or edited in a separate panel. You can also toggle soft wrap mode using the right-hand toolbar. Use all the power of our code editor for your data.

Google BigQuery dialect

Google BigQuery dialect

We’ve added a new SQL dialect: Google BigQuery. Full support for BigQuery is not here yet, but all things must begin somewhere. So far, PhpStorm can correctly highlight and provide coding assistance for your queries if you use Google BigQuery.

DML preview

DML preview

You can review the query that represents your changes in the data editor. There is a DML button that is active if there are pending changes. This query is not the exact SQL that will be run to modify your data, because PhpStorm uses a JDBC driver to update tables, but most of the time it will be the same.

Other Improvements

  • Customizing getters and setters
  • Resolve for multiple projects in one window
  • New action: Add Carets to Ends of Selected Lines