diff --git a/README.md b/README.md index 52b728f..014bbd2 100644 --- a/README.md +++ b/README.md @@ -1,34 +1,45 @@ # Polylang PHPStan This package provides a [PHPStan](https://phpstan.org/) extension for [Polylang](https://wordpress.org/plugins/polylang/) and [Polylang Pro](https://polylang.pro). -It's should be used in combination with [Polylang Stubs](https://github.com/polylang/polylang-stubs/). +It should be used in combination with [Polylang Stubs](https://github.com/polylang/polylang-stubs/). -### Requirements +## Requirements -- PHP >=7.1 +- PHP 8+ -### Installation +## Installation Require this package as a development dependency with Composer. +> [!TIP] +> `polylang/polylang-stubs` is optional but strongly recommended. + ```bash composer require --dev wpsyntex/polylang-phpstan composer require --dev wpsyntex/polylang-stubs ``` -### Configuration +## Configuration + +### Adding the extension Include the extension and stubs in the PHPStan configuration file. +> [!IMPORTANT] +> Prior to version 2.1 (included), `polylang/polylang-stubs` is automatically loaded. +> Starting from version 2.2, it must be configured manually. + ```yaml includes: - vendor/wpsyntex/polylang-phpstan/extension.neon parameters: - bootstrapFiles: + stubFiles: - vendor/wpsyntex/polylang-stubs/polylang-stubs.php ``` -Opt-in for WordPress stubs override. +### Opt in to WordPress stubs overrides + +The `stubs/wordpress-override.php` file provides corrected type definitions for specific WordPress functions that have imprecise or incorrect type hints in the standard WordPress stubs (currently `sanitize_key()`, `maybe_serialize()`, and `sanitize_text_field()`). ```yaml stubFiles: diff --git a/bootstrap.php b/bootstrap.php index ea47878..68ab092 100644 --- a/bootstrap.php +++ b/bootstrap.php @@ -33,7 +33,7 @@ define( 'POLYLANG', 'Polylang' ); define( 'POLYLANG_BASENAME', 'polylang/polylang.php' ); define( 'POLYLANG_DIR', './' ); -define( 'POLYLANG_VERSION', '3.0' ); // Must also be defined as dynamic in config file. +define( 'POLYLANG_VERSION', '3.8' ); // Must also be defined as dynamic in config file. define( 'PLL_COOKIE', 'pll_language' ); define( 'PLL_LOCAL_DIR', './wp-content/polylang' ); define( 'PLL_ADMIN', false ); // Must also be defined as dynamic in config file. diff --git a/extension.neon b/extension.neon index 2e5f69a..76f4fcc 100644 --- a/extension.neon +++ b/extension.neon @@ -27,9 +27,9 @@ includes: - ../../szepeviktor/phpstan-wordpress/extension.neon parameters: bootstrapFiles: - - %rootDir%/../../php-stubs/wordpress-stubs/wordpress-stubs.php - - %rootDir%/../../wpsyntex/polylang-stubs/polylang-stubs.php - bootstrap.php + stubFiles: + - %rootDir%/../../php-stubs/wordpress-stubs/wordpress-stubs.php dynamicConstantNames: - POLYLANG_VERSION - PLL_ADMIN diff --git a/tests/DynamicReturnTypeExtensionTest.php b/tests/DynamicReturnTypeExtensionTest.php index 74def12..6984e8c 100644 --- a/tests/DynamicReturnTypeExtensionTest.php +++ b/tests/DynamicReturnTypeExtensionTest.php @@ -30,6 +30,9 @@ public function testFileAsserts(string $assertType, string $file, ...$args): voi public static function getAdditionalConfigFiles(): array { // phpstan.neon or extension.neon use relative paths, so we need to use a fake vendor directory regarding szepeviktor/phpstan-wordpress dependency. - return [dirname(__DIR__) . '/vendor/wpsyntex/polylang-phpstan/extension.neon']; + return [ + dirname(__DIR__) . '/vendor/wpsyntex/polylang-phpstan/extension.neon', + dirname(__DIR__) . '/vendor/wpsyntex/polylang-phpstan/test-extension.neon', + ]; } } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index dab0cc5..81b56d3 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,6 +14,7 @@ // Copy package to a fake vendor directory. copy(dirname(__DIR__) . '/extension.neon', $helperDirectory . '/extension.neon'); +copy(dirname(__DIR__) . '/tests/test-extension.neon', $helperDirectory . '/test-extension.neon'); copy(dirname(__DIR__) . '/bootstrap.php', $helperDirectory . '/bootstrap.php'); require_once dirname(__DIR__) . '/vendor/autoload.php'; diff --git a/tests/test-extension.neon b/tests/test-extension.neon new file mode 100644 index 0000000..2e72431 --- /dev/null +++ b/tests/test-extension.neon @@ -0,0 +1,3 @@ +parameters: + bootstrapFiles: + - %rootDir%/../../wpsyntex/polylang-stubs/polylang-stubs.php