Skip to main content

Issue with PHPStorm & PHPStan on WSL2

· 2 min read
Stephan Hochdörfer
Head of IT Business Operations

While working on a PHPStan extension at a hackathon last month, I had some issues with the code completion for PHPStan classes in PHPStorm.

I was completely confused as I was pretty sure it worked in the past. However, I reinstalled PHPStan multiple times via Composer, invalidated the PHPStorm cache numerous times, and could not get the auto-completion for the PHPStan classes working.

After the hackathon, I took the time to dig a bit deeper into the issue. And I found the issue mentioned in a PHPStorm ticket: "Apparently, it is an intentional behavior to avoid WI-57899"

Now, I am even more confused, but at least I knew I was right. It did work in the past.

Thankfully there exists a workaround for the problem:

  • Open the built-in IDE Registry (Help > Find Action > Registry) and untick the php.include.paths.tree.view option
  • Afterward, copy the phpstan.phar file somewhere to a local volume
  • Navigate to "PHP > Include Path" and add the path to the local copy of phpstan.phar file

After following these steps, I managed to get the code completion working again. Not ideal to have a phpstan.phar copy on a different volume, but at least for now, everything is working fine.