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.
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:
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:
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:
ConfigEntityBase, we have the following code:
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.
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
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:
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.
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.
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
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.
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.
Your JetBrains PhpStorm team
The Drive to Develop
Subscribe to Blog updates
Thanks, we've got you!
PhpStorm 2023.2 Beta
In this build, we’ve added new inspections for PHP assertions and revised the integration with third-party quality tools.
PhpStorm 2023.2 EAP #6
This build brings improvements for generating PHPDocs, support for Laravel Pint, a single point of access to all PHP framework plugins, and much more!
AI Features in PhpStorm: PhpStorm 2023.2 EAP #5
The next EAP build for PhpStorm 2023.2 is now available, and it’s an exciting one! It is the first build to include features leveraging the enormous potential of generative AI and large language models (LLMs). Our Early Access Program (EAP) allows you to try new features from the upcoming PhpStor…
PhpStorm 2023.2 EAP #4
This build includes a bunch of usability improvements, such as abilities to pin Run configurations and sort files by modification time in the Project view. The EAP allows you to try new features from the upcoming PhpStorm version, 2023.2. EAP builds are free to use and you can install them side b…