Skip to content

Commit e5aa348

Browse files
authored
Do not load Polylang stubs. (#19)
1 parent 41f6991 commit e5aa348

6 files changed

Lines changed: 29 additions & 11 deletions

File tree

README.md

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,45 @@
11
# Polylang PHPStan
22

33
This package provides a [PHPStan](https://phpstan.org/) extension for [Polylang](https://wordpress.org/plugins/polylang/) and [Polylang Pro](https://polylang.pro).
4-
It's should be used in combination with [Polylang Stubs](https://github.com/polylang/polylang-stubs/).
4+
It should be used in combination with [Polylang Stubs](https://github.com/polylang/polylang-stubs/).
55

6-
### Requirements
6+
## Requirements
77

8-
- PHP >=7.1
8+
- PHP 8+
99

10-
### Installation
10+
## Installation
1111

1212
Require this package as a development dependency with Composer.
1313

14+
> [!TIP]
15+
> `polylang/polylang-stubs` is optional but strongly recommended.
16+
1417
```bash
1518
composer require --dev wpsyntex/polylang-phpstan
1619
composer require --dev wpsyntex/polylang-stubs
1720
```
1821

19-
### Configuration
22+
## Configuration
23+
24+
### Adding the extension
2025

2126
Include the extension and stubs in the PHPStan configuration file.
2227

28+
> [!IMPORTANT]
29+
> Prior to version 2.1 (included), `polylang/polylang-stubs` is automatically loaded.
30+
> Starting from version 2.2, it must be configured manually.
31+
2332
```yaml
2433
includes:
2534
- vendor/wpsyntex/polylang-phpstan/extension.neon
2635
parameters:
27-
bootstrapFiles:
36+
stubFiles:
2837
- vendor/wpsyntex/polylang-stubs/polylang-stubs.php
2938
```
3039
31-
Opt-in for WordPress stubs override.
40+
### Opt in to WordPress stubs overrides
41+
42+
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()`).
3243

3344
```yaml
3445
stubFiles:

bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
define( 'POLYLANG', 'Polylang' );
3434
define( 'POLYLANG_BASENAME', 'polylang/polylang.php' );
3535
define( 'POLYLANG_DIR', './' );
36-
define( 'POLYLANG_VERSION', '3.0' ); // Must also be defined as dynamic in config file.
36+
define( 'POLYLANG_VERSION', '3.8' ); // Must also be defined as dynamic in config file.
3737
define( 'PLL_COOKIE', 'pll_language' );
3838
define( 'PLL_LOCAL_DIR', './wp-content/polylang' );
3939
define( 'PLL_ADMIN', false ); // Must also be defined as dynamic in config file.

extension.neon

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ includes:
2727
- ../../szepeviktor/phpstan-wordpress/extension.neon
2828
parameters:
2929
bootstrapFiles:
30-
- %rootDir%/../../php-stubs/wordpress-stubs/wordpress-stubs.php
31-
- %rootDir%/../../wpsyntex/polylang-stubs/polylang-stubs.php
3230
- bootstrap.php
31+
stubFiles:
32+
- %rootDir%/../../php-stubs/wordpress-stubs/wordpress-stubs.php
3333
dynamicConstantNames:
3434
- POLYLANG_VERSION
3535
- PLL_ADMIN

tests/DynamicReturnTypeExtensionTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public function testFileAsserts(string $assertType, string $file, ...$args): voi
3030
public static function getAdditionalConfigFiles(): array
3131
{
3232
// phpstan.neon or extension.neon use relative paths, so we need to use a fake vendor directory regarding szepeviktor/phpstan-wordpress dependency.
33-
return [dirname(__DIR__) . '/vendor/wpsyntex/polylang-phpstan/extension.neon'];
33+
return [
34+
dirname(__DIR__) . '/vendor/wpsyntex/polylang-phpstan/extension.neon',
35+
dirname(__DIR__) . '/vendor/wpsyntex/polylang-phpstan/test-extension.neon',
36+
];
3437
}
3538
}

tests/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
// Copy package to a fake vendor directory.
1616
copy(dirname(__DIR__) . '/extension.neon', $helperDirectory . '/extension.neon');
17+
copy(dirname(__DIR__) . '/tests/test-extension.neon', $helperDirectory . '/test-extension.neon');
1718
copy(dirname(__DIR__) . '/bootstrap.php', $helperDirectory . '/bootstrap.php');
1819

1920
require_once dirname(__DIR__) . '/vendor/autoload.php';

tests/test-extension.neon

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
bootstrapFiles:
3+
- %rootDir%/../../wpsyntex/polylang-stubs/polylang-stubs.php

0 commit comments

Comments
 (0)