Setting the file. One moment.
Subchapter 12.2
references/third-party-classes.mdMarkdown3 KBView on GitHub
When PHPStan reports legitimate classes as missing (e.g. because WordPress or a plugin is not installed in the analysis environment), prefer fixing discovery first and only then add targeted ignores.
ignoreErrorsStubs are useful when the analysis environment does not include WordPress (or a plugin API) but you still want real type checking (instead of blanket ignores).
Common packages:
composer require --dev szepeviktor/phpstan-wordpress
composer require --dev php-stubs/wordpress-stubs
composer require --dev php-stubs/woocommerce-stubs
composer require --dev php-stubs/acf-pro-stubsWhen stubs are useful (and sometimes necessary):
add_action(), get_option()).ignoreErrors.Notes:
Installing stubs is not enough if PHPStan does not scan them. Add stub paths in phpstan.neon.
parameters:
bootstrapFiles:
- %rootDir%/../../php-stubs/woocommerce-stubs/woocommerce-stubs.php
scanFiles:
- %rootDir%/../../php-stubs/wordpress-stubs/wordpress-stubs.php
- %rootDir%/../../php-stubs/acf-pro-stubs/acf-pro-stubs.php
- %rootDir%/../../woocommerce/action-scheduler/functions.phpparameters:
ignoreErrors:
# Admin Columns Pro
- '#.*(unknown class|invalid type|call to method .* on an unknown class) AC\\ListScreen.*#'
# Elementor
- '#.*(unknown class|invalid type|call to method .* on an unknown class) Elementor\\.*#'
# Yoast SEO
- '#.*(unknown class|invalid type|call to method .* on an unknown class) WPSEO_.*#'Pattern creation rules:
unknown class, invalid type, call to method .* on an unknown class.When to add exceptions: