From 744ac04a394398cafcbc11a9203a91955178c7d9 Mon Sep 17 00:00:00 2001 From: Hug0-Drelon Date: Fri, 30 Jan 2026 11:21:51 +0100 Subject: [PATCH 1/6] Remove polylang-stubs from extension.neon and use correct parameter `stubFiles` for wordpress-stubs. --- extension.neon | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From c55fa82effdce13cc97e7781b53efdf957f6f7ee Mon Sep 17 00:00:00 2001 From: Hug0-Drelon Date: Fri, 30 Jan 2026 11:22:15 +0100 Subject: [PATCH 2/6] Update Polylang version in bootstrap.php. --- bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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. From 260bba683c22d0bc442185eee828627e6c183faa Mon Sep 17 00:00:00 2001 From: Hug0-Drelon Date: Fri, 30 Jan 2026 11:22:23 +0100 Subject: [PATCH 3/6] Update README. --- README.md | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 52b728f..47536a5 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 inclusive, `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: From e0cfe9456c406288de98253e388088a77058ea9c Mon Sep 17 00:00:00 2001 From: Hug0-Drelon Date: Fri, 30 Jan 2026 11:27:37 +0100 Subject: [PATCH 4/6] Create `test-extension.neon` to load Polylang stubs in PHPUnit tests. --- tests/bootstrap.php | 1 + tests/test-extension.neon | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 tests/test-extension.neon diff --git a/tests/bootstrap.php b/tests/bootstrap.php index dab0cc5..29c724e 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__) . '/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..ccc78f2 --- /dev/null +++ b/tests/test-extension.neon @@ -0,0 +1,3 @@ +parameters: + stubFiles: + - %rootDir%/../../wpsyntex/polylang-stubs/polylang-stubs.php From 882bbac0325e4cb998109379c0f9c17f22516b35 Mon Sep 17 00:00:00 2001 From: Hug0-Drelon Date: Fri, 30 Jan 2026 12:17:32 +0100 Subject: [PATCH 5/6] Create tests/test-extension.neon and load it in tests only. --- tests/DynamicReturnTypeExtensionTest.php | 5 ++++- tests/bootstrap.php | 2 +- tests/test-extension.neon | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) 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 29c724e..81b56d3 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -14,7 +14,7 @@ // Copy package to a fake vendor directory. copy(dirname(__DIR__) . '/extension.neon', $helperDirectory . '/extension.neon'); -copy(dirname(__DIR__) . '/test-extension.neon', $helperDirectory . '/test-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 index ccc78f2..2e72431 100644 --- a/tests/test-extension.neon +++ b/tests/test-extension.neon @@ -1,3 +1,3 @@ parameters: - stubFiles: + bootstrapFiles: - %rootDir%/../../wpsyntex/polylang-stubs/polylang-stubs.php From 696401e16833611a382b8d68374d710104437837 Mon Sep 17 00:00:00 2001 From: Hugo Drelon <69580439+Hug0-Drelon@users.noreply.github.com> Date: Fri, 30 Jan 2026 15:35:32 +0100 Subject: [PATCH 6/6] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Grégory Viguier --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 47536a5..014bbd2 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,12 @@ composer require --dev wpsyntex/polylang-stubs ## Configuration -#### Adding the extension +### Adding the extension Include the extension and stubs in the PHPStan configuration file. > [!IMPORTANT] -> Prior to version 2.1 inclusive, `polylang/polylang-stubs` is automatically loaded. +> Prior to version 2.1 (included), `polylang/polylang-stubs` is automatically loaded. > Starting from version 2.2, it must be configured manually. ```yaml @@ -37,7 +37,7 @@ parameters: - vendor/wpsyntex/polylang-stubs/polylang-stubs.php ``` -#### Opt in to WordPress stubs overrides +### 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()`).