PHPackages                             lipemat/phpstan-wordpress - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. lipemat/phpstan-wordpress

ActivePhpstan-extension[Utility &amp; Helpers](/categories/utility)

lipemat/phpstan-wordpress
=========================

Phpstan extension for working with WordPress

4.3.0(6mo ago)1256.3k—8.6%1MITPHPPHP &gt;=8.2CI passing

Since Dec 10Pushed 2mo ago2 watchersCompare

[ Source](https://github.com/lipemat/phpstan-wordpress)[ Packagist](https://packagist.org/packages/lipemat/phpstan-wordpress)[ GitHub Sponsors](https://github.com/lipemat)[ RSS](/packages/lipemat-phpstan-wordpress/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (7)Versions (60)Used By (1)

PHPStan for WordPress
=====================

[](#phpstan-for-wordpress)

[![package version](https://camo.githubusercontent.com/38e571407d09043584626eabcbc82289735c95f131696930af193ade5f2f1c5f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c6970656d61742f7068707374616e2d776f726470726573732e7376673f6c6162656c3d76657273696f6e)](https://github.com/lipemat/phpstan-wordpress/releases) [![php version](https://camo.githubusercontent.com/36f4cb3571eadfd14fdef8c66f0e6a35a512404270b15f5ebffd744ff3dc03db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c6970656d61742f7068707374616e2d776f726470726573732e7376673f636f6c6f723d62726f776e)](https://camo.githubusercontent.com/36f4cb3571eadfd14fdef8c66f0e6a35a512404270b15f5ebffd744ff3dc03db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6c6970656d61742f7068707374616e2d776f726470726573732e7376673f636f6c6f723d62726f776e) [![Packagist](https://camo.githubusercontent.com/626eda78c85106c429cbe5d1337a398d330e7e26d8e20e7d36055b6bf4388e89/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6970656d61742f77702d70687063732e737667)](https://camo.githubusercontent.com/626eda78c85106c429cbe5d1337a398d330e7e26d8e20e7d36055b6bf4388e89/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c6970656d61742f77702d70687063732e737667)

Usage
-----

[](#usage)

Install via composer

```
composer require lipemat/phpstan-wordpress
```

Included Stubs
--------------

[](#included-stubs)

1. The semi-official [phpstan-wordpress](https://github.com/szepeviktor/phpstan-wordpress) stubs.
2. Custom stubs
    1. `wp.php` some additional stubs for WordPress

Optional Stubs
--------------

[](#optional-stubs)

1. [WP-CLI stubs](https://github.com/php-stubs/wp-cli-stubs).
2. WP-CLI Tools Stubs. Included in the [wp-cli-stubs](https://github.com/php-stubs/wp-cli-stubs/blob/master/wp-cli-tools-stubs.php) package since version 2.11.0.
3. [CMB2 stubs](https://github.com/lipemat/phpstan-wordpress/tree/master/stubs/cmb2/)
4. [Genesis stubs](https://github.com/lipemat/phpstan-wordpress/tree/master/stubs/genesis/)
5. [VIP stubs](https://github.com/lipemat/phpstan-wordpress/tree/master/stubs/vip.php) some stubs for WP VIP environments.

These may be selectively added to your `phpstan.neon` or `phpstan.neon.dist` like so:

### When using library as a global install

[](#when-using-library-as-a-global-install)

```
scanFiles:
  - %rootDir%/../../../stubs/cmb2/cmb2-3.10.php
  - %rootDir%/../../../stubs/genesis/genesis-3.4.php
  - %rootDir%/../../../stubs/vip.php
  - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-stubs.php
  - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php
  - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-i18n-stubs.php
  - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-tools-stubs.php
```

### When using library as composer dependency

[](#when-using-library-as-composer-dependency)

```
scanFiles:
  - %rootDir%/../../lipemat/phpstan-wordpress/stubs/cmb2/cmb2-3.10.php
  - %rootDir%/../../lipemat/phpstan-wordpress/stubs/genesis/genesis-3.4.php
  - %rootDir%/../../lipemat/phpstan-wordpress/stubs/vip.php
  - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-stubs.php
  - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php
  - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-i18n-stubs.php
  - %rootDir%/../../php-stubs/wp-cli-stubs/wp-cli-tools-stubs.php
```

Alternatively, you may replace `%rootDir%/../../` with the relative path to your `vendor` directory.

Example `wp-content/plugins/core/vendor/lipemat/phpstan-wordpress/stubs/cmb2/cmb2-3.10.php`

Utility Types
-------------

[](#utility-types)

### `\AtLeast`

[](#atleastt-u)

Mark a set of array shape keys as required while making the rest optional.

```
/**
 * @phpstan-var \AtLeast $array
 *   // results: array{a: string, b?: string}
 */
```

### `\Exclude`

[](#excludet-k)

Exclude the specified keys from an array shape.

```
/**
 * @phpstan-var \Exclude $array
 *   // results: array{b: string}
 */
```

### `\Partial`

[](#partialt)

Mark either all or specified keys in an array shape as optional.

- `\Partial`: Mark all keys as optional.
- `\Partial`: Mark only the specified keys as optional.

```
/**
 * @phpstan-var \Optional $array
 *   // results: array{a?: string, b?: string}
 *
 * @phpstan-var \Optional $array
 *   // results: array{a: string, b?: string}
 */
```

### `\Pick`

[](#pickt-k)

Pick only the specified keys from an array shape.

```
/**
 * @phpstan-var \Pick $array
 *   // results: array{a: string}
 */
```

### `\Required`

[](#requiredt)

Mark either all or specified keys in an array shape as required.

- `\Required`: Mark all keys as required.
- `\Required`: Mark only the specified keys as required.

```
/**
 * @phpstan-var \Required $array
 *   // results: array{a: string, b: string}
 *
 * @phpstan-var \Required $array
 *   // results: array{a?: string, b: string}
 */
```

### `\Sarcastic`

[](#sarcastict)

Mark a type as an unpredictable random value.

*This utility is extremely useful in everyday projects.*

```
/**
 * @phpstan-var \Sarcastic $string
 *   // results: anyone's guess
 */
```

### `\Union`

[](#uniont-u-x)

Combine two or more array shapes as if you were using `array_merge` with the second array overwriting the first.

```
/**
 * @phpstan-var \Union $array
 *   // results: array{a: string, b: string}
 */
```

Optional Included Rules
-----------------------

[](#optional-included-rules)

As we move toward a world where we use composition over inheritance, we need to be more strict about how we write our code. These optional rules do not get us all the way there, but they are a step in the right direction while still being viable for a WordPress project.

Enable in your `phpstan.neon` or `phpstan.neon.dist` like so:

```
includes:
# If you are using this library as a globally installed library.
  - %rootDir%/../../../rules.neon
# If you are using this library as a composer dependency.
  - %rootDir%/../../lipemat/phpstan-wordpress/rules.neon

```

1. Prevent using the `compact` function.
2. Prevent using the `extract` function.
3. Require all classes to be either abstract or final.
4. Require a `declare(strict_types=1)` statement in every non-empty file.
5. Prevent using default values in class constructors.
6. Prevent declaring a method `protected` in a final class in favor of `private`.
    1. Rule is now disabled by default but may be enabled manually.
7. Prevent using the `switch` statement in favor of `match`.
8. Require any concrete methods in abstract classes to be `private` or `final`.
9. Prevent child classes from skipping parent parameter types.
10. Prevent calls to methods on unknown classes.
11. Prefer returning null over false unless boolean is expected.
12. Prohibit using `ArrayAccess` to access class data.
13. Require `instance of` instead of `isset` for object verification.

### Distributed plugins or themes

[](#distributed-plugins-or-themes)

Some rules assume you are working on a private project which will not be distributed to the community. If your project is distributed, you may add the `nonDistributed` parameter to the `lipemat` parameter.

```
parameters:
    lipemat:
      nonDistributed: false
```

The `nonDistributed` set to `false` parameter will disable the following rules:

1. Require all classes to be either abstract or final.
2. Require a `declare(strict_types=1)` statement in every non-empty file.
3. Require any concrete methods in abstract classes to be `private` or `final`.

### Prevent any inheritance

[](#prevent-any-inheritance)

Adding the `noExtends` parameter to the `lipemat` parameter will prevent having or extending any unlisted abstract classes.

```
parameters:
    lipemat:
      allowedToBeExtended:
        - Lipe\Project\SomeAbstractClass
        - Lipe\Project\SomeOtherAbstractClass
      noExtends: true
```

You may omit the `allowedToBeExtended` parameter to prevent extending any abstract classes.

###  Health Score

56

—

FairBetter than 98% of packages

Maintenance79

Regular maintenance activity

Popularity36

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~35 days

Recently: every ~57 days

Total

56

Last Release

60d ago

Major Versions

1.9.0 → 2.0.02022-02-17

2.11.1 → 3.0.02024-02-23

3.4.2 → 4.0.02025-01-30

PHP version history (5 changes)v1.0.0-beta-3PHP &gt;=7.1

2.1.2PHP &gt;=7.2

3.4.0PHP &gt;=7.4

4.2.0PHP &gt;=8.1

4.3.0PHP &gt;=8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/cc40b48cf8242da779608fe27fa97a99eb1304bd8cb153e46950fe9f8ab46a18?d=identicon)[lipemat](/maintainers/lipemat)

---

Top Contributors

[![lipemat](https://avatars.githubusercontent.com/u/1688181?v=4)](https://github.com/lipemat "lipemat (296 commits)")

### Embed Badge

![Health badge](/badges/lipemat-phpstan-wordpress/health.svg)

```
[![Health](https://phpackages.com/badges/lipemat-phpstan-wordpress/health.svg)](https://phpackages.com/packages/lipemat-phpstan-wordpress)
```

###  Alternatives

[wp-cli/wp-cli-tests

WP-CLI testing framework

422.7M87](/packages/wp-cli-wp-cli-tests)[ticketswap/phpstan-error-formatter

A minimalistic error formatter for PHPStan

87578.8k35](/packages/ticketswap-phpstan-error-formatter)[codeigniter4/devkit

Development toolkit for CodeIgniter libraries and projects

68187.1k82](/packages/codeigniter4-devkit)[ramsey/devtools

A Composer plugin to aid PHP library and application development.

7134.7k26](/packages/ramsey-devtools)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
