PhpStorm 2022.1 EAP #2: New Inspections
Last week we launched the Early Access Program for PhpStorm 2022.1, and we are going to be releasing updates every week for the next two months.
New inspections for PHP
With each release, we add many new inspections to help you prevent bugs in your code in the early development stages, before you commit it. You can manage and configure inspections under Preferences | Editor | Inspections.
If you find some inspection is irrelevant to you, you can disable it simply by pressing Alt+Enter on the highlighted code and choosing Disable inspection under the inspection name.
Let’s take a look at some notable new inspections we’re adding in v2022.1.
Duplicate array key WI-63476
The behavior of array_merge()
and merging with the +
operator is different in PHP. The latter will not override the value if the key is duplicated. That could lead to confusion and bugs, so PhpStorm will highlight such cases.
Usage of count($array) as array index WI-63865
To append an item to an array, there is no need to explicitly specify the index. PhpStorm will warn you about the redundant count()
call.
Replace pow() call with ** WI-63872
PHP has had an exponentiation operator **
available since version 5.6. PhpStorm will not highlight pow()
usages, but it will show you a handy quick-fix (Alt+Enter) to replace the old pow()
calls with the **
operator.
Property can be declared readonly WI-63995
Private properties with read-only access inside a class could be declared with the readonly
flag. Use the Alt+Enter quick-fix to update the property declaration.
Class constant can be final WI-64152
Starting with PHP 8.1, it is possible to declare constants as final. This is why PhpStorm allows you to add a final
modificator to constants that are not inherited (just use Alt+Enter).
Should everything be declared as final by default in PHP? Let us know what you think in the comments!
Rand function arguments in reverse order WI-64297
This inspection highlights function calls from the rand family where the max argument is less than the min. For example, calling rand(10, 1)
is the same as calling rand(1, 10)
, but mt_rand()
is strict about the order of its arguments.
Invalid mocking target with PHPUnit WI-64359
PhpStorm will warn you when you try to access a private or final method on a mock object.
Did you know all of PhpStorm’s checks can be also performed on CI using JetBrains Qodana? Learn more about static analysis for PHP and how to set up Qodana.
For the full list of changes in the EAP #2 build, please see 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 and don’t require a license. But they expire 30 days after the build date, and you’ll have to download a new build.
Please let us know about any problems you find by reporting them to our issue tracker or by commenting on this post.
Your JetBrains PhpStorm team
The Drive to Develop