Based on the php-stubs/woocommerce-stubs package. Thanks @szepeviktor!
This package provides stub declarations for WooCommerce functions, classes, and interfaces. These stubs can help plugin and theme developers leverage static analysis tools like PHPStan, which is not able to parse WooCommerce as it is not clean OOP code.
Stubs are generated from the woocommerce-dist
repo using php-stubs/generator
.
- PHP ^8.0
Require this package as a development dependency with Composer.
composer require --dev tectalic/woocommerce-stubs
Alternatively, you may download the woocommerce-stubs.php
and woocommerce-packages-stubs.php
files directly.
Make PHPStan find it automatically using phpstan/extension-installer
.
composer require --dev phpstan/extension-installer
Or manually include it in your phpstan.neon
.
parameters:
bootstrapFiles:
- vendor/tectalic/woocommerce-stubs/woocommerce-stubs.php
# Optionally
- vendor/tectalic/woocommerce-stubs/woocommerce-packages-stubs.php
- Make sure the new version has already been added to the
woocommerce-dist
repo. - Update Private Packagist if needed.
- Run the
./generate.sh
script with the new version, e.g.,./generate.sh 7.0.0-beta.1
. - Update Private Packagist so it shows the newly generated version.