PhpStorm 2020.3 EAP #2: PHPStan and Psalm Support Out-of-the-Box
This EAP build brings support for PHPStan and Psalm static analyzers to PhpStorm.
Last week, we launched the Early Access Program for PhpStorm 2020.3. For the next two months, we are going to be releasing updates every week, and today we’ve got the second build of the 2020.3 EAP for you.
- 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.
PHPStan / Psalm
Both static analyzers will be available in PhpStorm 2020.3 as first-class code quality tools.
Just like with other code quality tools, you get on-the-fly file highlighting of problems in the editor.
How to get started with PHPStan and Psalm?
You can add PHPStan or Psalm as your dev-dependency in
composer.json. Near the corresponding line, you’ll see a wrench icon that will open the tool settings. PhpStorm will detect the path to the tool binary, though you can also specify it manually.
From there you can go to the Inspection settings – this is where you can enable highlighting in the editor. Click on the PHPStan Inspection / Psalm Inspection link. To turn on highlighting, select the corresponding inspection in the PHP | Quality tools list.
Here you can specify the configuration file path and adjust the command-line arguments of the tools. For example, you can set PHPStan’s error level or toggle unused code detection for Psalm.
Note: PHPStan can work without a configuration file, but Psalm requires one.
If you have
phpstan.neon in the root directory, PhpStorm will detect them automatically.
Once you have set this up, you can then open any file and see any problems they have found highlighted in the editor. There may be a short delay before the highlighting appears.
Psalm and PHPDoc Annotations
Our main focus has been to make annotated code with extended Psalm tags look valid in the editor and to generally improve the experience of using Psalm.
PhpStorm now treats
@psalm-* tags highlighting as special, so there will be no oddities with angle brackets
< >, no undefined classes, and so on.
In most cases it is now safe to remove the
@psalm-prefix from tags, i.e.
@psalm-return -> @returnand
@psalm-param -> @param. Please vote for WI-55926 if you would like to see an inspection for this.
All the tags have code-completion. For example, in array structures, you get completion for types and for class names in
While completing the types, PhpStorm will take into account Psalm-defined types specified with
Finally, we’ve added support for some Psalm types and improved our type inference too. As a consequence, everything that depends on type inference has become more accurate: inspections, code generation, and completion.
Pseudo-types: scalar, numeric, and so on.
Constants in types
Constant value unions and wildcards are both supported in type definitions via
Type inference for array definitions
array<array-key, Type> now works as expected. This applies to nested definitions, too.
Generics with @tempate
Support for generics is the most voted feature request for PhpStorm. We still believe it’s an advanced feature that lacks a proper specification and has many edge cases. Yet, we have decided to implement basic support for the
@template construct based on the Psalm syntax to see how it goes.
So far only a simple scenario, when the function returns one of its parameters, is supported.
The support for generics is basic and still considered experimental. This is where we’d like to understand how you’d use it and what you’d like to see more of. Feel free to submit requests with your real-life template usages to our issue tracker.
This is all open-source
The support for PHPStan and Psalm is provided by two separate plugins. They will both be bundled with PhpStorm 2020.3 so you won’t need to install them separately.
Decoupling the plugins has allowed us to share them as open-source projects on GitHub under the Apache 2 license:
You are welcome to use the code as a source of inspiration for your own work, and you can participate in their development by sending us pull requests.
I found a bug, how do I report it?
Over the last couple of months, we’ve tried using issues on GitHub, but we consider the experiment a failure for many reasons. As of now, all Psalm/PHPStan issues have been moved from GitHub to our YouTrack.
Feel free to submit bug reports and feature requests related to PHPStan and Psalm to our issue tracker.
That’s all for now. We will continue to improve our support for static analysis tools, and we’re looking forward to hearing from you.
The full list of changes in the EAP #2 build is available in the release notes.
Please let us know about any problems you find by reporting them to our issue tracker or 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