PHPStan
PhpStorm provides code quality checks through integration with the PHPStan tool or its Laravel extension Larastan. Both tools validate your code for consistency against a set of validation rules.
To use PHPStan or Larastan from PhpStorm instead of the command line, you need to register it in PhpStorm and set it up as a PhpStorm code inspection. Once installed and enabled in PhpStorm, the tool is available in any opened PHP file, and no additional steps are required to launch it. The on-the-fly code check is activated upon every update in the file thus making it easy to get rid of discovered problems.
Errors and warnings reported by PHPStan on the fly are highlighted in the editor in the same way as errors and warnings from PhpStorm's internal code inspections. When the tool is run in batch mode, the errors and warnings are displayed in the Problems tool window. Each message has a phpstan
prefix to distinguish it from PhpStorm internal inspections.
The integration is implemented via the open-source PHPStan plugin. This plugin is bundled with PhpStorm and is enabled by default.
note
Larastan inspections are supported in PhpStorm via PHPStan integration. Configuration of the Larastan tool is done via PHPStan and PHPStan validation settings pages.
Prior to integrating PHPStan in PhpStorm, make sure the following prerequisites are met:
The directory containing the PHP engine executable must be added to the system
path
. This allows code quality tool scripts to execute calls to the system-wide PHP engine.For Docker Compose-based remote interpreters, make sure to use
docker-compose exec
mode to avoid spawning additional containers.In the Settings dialog (CtrlAlt0S) , go to PHP.
On the PHP page that opens, click
next to the CLI Interpreter list.
In the CLI Interpreters dialog that opens, set the Lifecycle mode for the selected interpreter to Connect to existing container ('docker-compose exec').
tip
Before you start, make sure Composer is installed on your machine and initialized in the current project as described in Composer dependency manager.
When you install PHPStan or Larastan with Composer, PhpStorm automatically downloads the necessary scripts, registers them in the IDE, and, optionally, enables and configures the corresponding code inspection.
Inside composer.json, add the
phpstan/phpstan
orlarastan/larastan
dependency record to therequire
orrequire-dev
key. To get code completion for the package name and version, press CtrlSpace.Do one of the following:
Click the Install shortcut link on top of the editor panel.
If the Non-installed Composer packages inspection is enabled, PhpStorm will highlight the declared dependencies that are not currently installed. Press AltEnter and select whether you want to install a specific dependency or all dependencies at once.
Clicking next to the package record in the composer.json editor gutter will take you to the corresponding Settings page where you can configure PHPStan manually.

After PHPStan is initially configured, further modifications in composer.json will not affect the inspection configuration. To apply newer changes, reset the PHPStan configuration.
In the Settings dialog (CtrlAlt0S) , navigate to PHP | Quality Tools | PHPStan.
Click
next to the Configuration list.
In the PHPStan dialog that opens, empty the PHPStan path field.
Update the project Composer dependencies by clicking Update on top of the composer.json editor panel. For more information, refer to Update dependencies.
PhpStorm will perform the PHPStan configuration anew and thus apply the changes in composer.json.
When you install PHPStan with Composer, PhpStorm automatically detects PHPStan's executable file in the vendor/bin
folder and sets the PHP interpreter configured in the system path to run it.
In Settings (CtrlAlt0S) | PHP | Quality Tools | PHPStan, you can change the default PHP interpreter, set the path to a manually downloaded and installed PHPStan executable file, or add some options to be passed to PHPStan when running it in PhpStorm.

Configuration: in this field, you can change the default PHP interpreter and path to the PHPStan executable file.
To only change the interpreter, select the required item from the list of local and remote PHP interpreters configured in your project.
tip
The PHPStan executable file (phpstan.bat for Windows or phpstan for Linux and macOS) contains a path to a PHP engine in it. PhpStorm lets you overwrite this path and use the PHP interpreter of your choice.
note
Learn more about configuring PHP interpreters in Configure remote PHP interpreters or in Configure local PHP interpreters.
To change the path to the PHPStan executable file, or both the interpreter and the path, click
next to the Configuration list to open the PHPStan dialog and edit the fields there as described on the PHPStan Dialog reference page.
Show ignored files: use this setting to exclude files from PHPStan validation inspection. For more information, refer to the Quality Tools reference page.
Options: in this area, add the PHPStan command options to run PHPStan as a PhpStorm inspection with. Edit the fields there as described on the PHPStan reference page.
There are two ways to set up PHPStan as a PhpStorm inspection: automatically during PHPStan installation with Composer, or manually in PhpStorm's inspections settings.
You can include the information on the PHPStan configuration file inside the scripts section of composer.json. When you install or update project dependencies, the specified configuration file will be detected and the PHPStan validation inspection will be enabled automatically.
If no configuration file is specified in the scripts
section of composer.json, PhpStorm will additionally check the project root to locate the ruleset with the phpstan.neon or phpstan.neon.dist default name.
In the
scripts
section of composer.json, add thephpstan
PHPStan launch command into one of the leaf elements.Provide the
-c
argument and the path to the configuration file:"scripts": { "phpstan": "vendor/bin/phpstan -c phpstan.neon" }
note
After PHPStan is initially configured, further modifications in composer.json will not affect the inspection configuration. To apply newer changes, reset the PHPStan configuration on the PHP |Quality Tools page of the Settings dialog (CtrlAlt0S) and update project dependencies.
In the Settings dialog (CtrlAlt0S) , click Inspections under Editor.
On the Inspections page that opens, expand the PHP | Quality Tools node and select the checkbox next to PHPStan validation.
tip
If you have installed PHPStan with Composer but the corresponding inspection is currently disabled, PhpStorm highlights its record in composer.json. Press AltEnter and use the provided Enable inspection quick-fix to enable the inspection and open the Inspections page.
On the right-hand pane of the Inspections page, configure how PhpStorm should handle the PHPStan inspection output:
Scope: choose the scope to limit the inspection application to.
Severity: choose the severity degree for the inspection. The selected value determines how seriously the detected discrepancies will be treated by PhpStorm and presented in the inspection results.
Highlighting in editor: choose how the issues detected by the inspection are highlighted in the editor.
note
You can also enable and disable the PHPStan validation inspection in the Settings dialog (CtrlAlt0S) | PHP | Quality Tools by using the ON/OFF toggle in the PHPStan section, but note that this action is applied only to the Project Default inspection profile.
In the main menu, go to Code | Inspect code.
In the Specify Inspection Scope dialog that opens, select the inspection profile from the list, or click Configure to open the Inspections dialog and configure a new profile.
You can also click Configure to check which fixes will be applied within the scope of the selected inspection profile, and make sure that the PHPStan validation inspection is enabled.
View the inspection results in the Problems tool window. Errors and warnings reported by PHPStan are prefixed with
phpstan::
to distinguish them from PhpStorm internal inspections.
When waiting for PHPStan response exceeds the limit specified in the Tool process timeout field in the PHPStan dialog, PhpStorm suggests adding the file to the ignore list.
In the Settings dialog (CtrlAlt0S) , navigate to PHP | Quality Tools | PHPStan.
Click the Show ignored files link.
To add a file, click
and locate the desired file in the dialog that opens.
To delete a file from the list and have PHPStan process it again, select the file and click
.
To remove all the files from the list, click
.
Thanks for your feedback!