Menu

Stub Files

PHPStan depends on PHPDocs in the analysed and used code. You might encounter a PHPDoc in your vendor/ that’s imprecise and causes an error in the analysis of your project that’s a false positive.

To mitigate this, you can write a stub file with the right PHPDoc. It’s like source code, but PHPStan only reads PHPDocs from it. So the namespace and class/interface/trait/method/function names must match with the original source you’re describing. Method bodies can stay empty, PHPStan is only interested in the PHPDocs.

Native parameter types and return types added in stubs are not considered.

Get inspired by the stubs PHPStan itself uses or by the stubs from the phpstan-doctrine extension.

Stub files aren’t a replacement for discovering symbols so if you’re trying to fix errors like “Function not found” or “Class not found”, check out the discovering symbols guide instead.

The stub file needs to be added to the stubFiles key in the configuration file:

parameters:
	stubFiles:
		- stubs/Foo.stub
		- stubs/Bar.stub

They can have any file extension you’d like. Consider choosing .stub over .php so that the stubs don’t confuse your IDE.

Relative paths in the stubFiles key are resolved based on the directory of the config file is in.

Edit this page on GitHub

Theme
A
© 2016–2024 Ondřej Mirtes