This package provides a PHPStan extension for Polylang and Polylang Pro. It should be used in combination with Polylang Stubs.
- PHP 8+
Require this package as a development dependency with Composer.
Tip
polylang/polylang-stubs is optional but strongly recommended.
composer require --dev wpsyntex/polylang-phpstan
composer require --dev wpsyntex/polylang-stubsInclude 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.
includes:
- vendor/wpsyntex/polylang-phpstan/extension.neon
parameters:
scanFiles:
- vendor/wpsyntex/polylang-stubs/polylang-stubs.phpThe 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()).
stubFiles:
- vendor/wpsyntex/polylang-phpstan/stubs/wordpress-override.phpPolylang 3.9 replaced PLL_Switcher::the_languages() with pll_the_languages() and the internal WP_Syntex\Polylang\Switcher\Switcher class.
This extension provides dynamic return types for pll_the_languages():
$args |
Return type |
|---|---|
raw => true |
array<string, mixed> |
echo => false |
string |
default (echo => true) |
void |
Direct usage of WP_Syntex\Polylang\Switcher\Switcher is typed from Polylang stubs or from Polylang source when you analyze the plugin itself.
PLL_Switcher was removed in Polylang 3.9. When this extension is enabled, PHPStan reports:
polylang.deprecatedSwitcheronnew PLL_Switcher()polylang.deprecatedSwitcherMethodonPLL_Switcher::the_languages()
Migrate to pll_the_languages() or to WP_Syntex\Polylang\Switcher\Switcher.