Early Access Program

PhpStorm 2020.2 EAP #4

The Early Access Program for PhpStorm 2020.2 is in full swing, and today we’ve got Build 4 of the 2020.2 EAP for you.

Read on to learn about the new control flow engine, the Add caret per selected line action, and smart handling of terminal commands.

If you prefer to watch rather than read, check out our EAP video series on the JetBrainsTV YouTube channel. Episode 1 is already available.

Download PhpStorm 2020.2 EAP

New control flow engine

PhpStorm 2020.2 introduces a new version of the control flow engine, which is now more powerful than ever. We’ve already shown some improvements in the EAP#1 post. Let’s explore what it offers in more detail by looking at some scenarios from real-life projects.

Condition always true

Let’s start with the new Condition always true inspection:

always_true

In this code snippet, PhpStorm understands that $item must always have the type FOFTable, as otherwise the function returns false. As a result, is_object($item) is always true, and the whole ternary operation can be simplified.
To help you more easily understand what’s going on, the inspection message provides detailed information about the cause. There is also a quick-fix that lets you navigate to the expression that uniquely defines the current value.
Here is another example of this inspection in action:

always_true_2

PhpStorm knows that as part of the elseif chain, the case with $stubContent === null has already been covered, so the last condition can be simplified.
There are several other new inspections based on the new engine, including Expression is always ‘null’, Result of ‘instanceof’ is always ‘true’, and Variable is always true/false when reached. Let’s look at them in more detail.

Result of ‘instanceof’ is always ‘true

Suppose we have the following non-trivial hierarchy:

hierarchy

Inside ConfigEntityBase, we have the following code:

always_true_3

Because ConfigEntityBase implements ThirdPartySettingsInterface, the expression is always true. PhpStorm highlights it as redundant and displays a warning that suggests unwrapping the if statement for clarity.

Variable is always true/false when reached

PhpStorm not only analyzes conditions but also tracks the values of variables. It can suggest increasing code readability by replacing the always true/false variables with the corresponding boolean values.

always_true_6

In this example, the ternary operator makes sure that $empty is always true in the first branch, so we can safely replace the variable with just the true value.
The inspection is disabled on purpose for the case below. This is because, according to our investigations, such code is often used to quickly change the default value:

always_true_5

Expression is always ‘null’

In addition to true/false values, PhpStorm now also tracks the null value of the variable. Let’s take a look at the Expression is always ‘null’ inspection.

always_null

In this example, PhpStorm builds the control flow and sees that the assigned null value isn’t rewritten, neither by a new assignment nor by a pass-by-reference call. The IDE highlights the usage of $default and suggests simplifying the expression to make it more clear.

Add caret per selected line action

The new Add Caret Per Selected Line action creates carets at the end of each selected line, and deselects the lines. Invoke it using the shortcut Alt+Shift+G on Windows/Linux or ⌥⇧G on macOS.

add_caret_action

Smart handling of terminal commands

PhpStorm has many features that can help you do specific jobs faster. In the upcoming v2020.2, if you run certain commands from the built-in terminal, the IDE will now suggest using existing IDE features instead.
Let’s say you want to check commit logs. If you type git log in the built-in terminal, the IDE will highlight the command in a different color, indicating that it can be handled by the IDE itself. Press Ctrl+Enter, and the IDE will open the Git tool window on the Log tab so you can explore commit logs with less effort.

terminal_smart_commands

This is still a work in progress, so we’d love to hear what other PHP-related commands you would like PhpStorm to handle in a similar fashion.
If you don’t find this feature useful in your workflow, you can disable smart commands by unchecking Smart command handling in Preferences/Settings | Tools | Terminal.


The full list of changes, including bug-fixes and improvements, is available in the release notes.

  • Important! PhpStorm EAP builds are not fully tested and may be unstable.
  • You can install an EAP build side by side with a stable PhpStorm version to try out the latest features.
  • EAP builds are free to use but expire 30 days after the build date.

Please report any problems you find to our issue tracker, or by commenting on this post. Your feedback is much appreciated, and the most active EAPers will get special limited-edition gifts from us!

Your JetBrains PhpStorm team
The Drive to Develop

image description