PHPackages                             wp-media/phpstan-wp - 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. wp-media/phpstan-wp

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

wp-media/phpstan-wp
===================

WP Media extensions for PHPStan

v1.0(3mo ago)05771GPL-3.0-or-laterPHPPHP ^7.4 || ^8.0

Since Mar 10Pushed 3mo agoCompare

[ Source](https://github.com/wp-media/phpstan-wp)[ Packagist](https://packagist.org/packages/wp-media/phpstan-wp)[ RSS](/packages/wp-media-phpstan-wp/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (1)

PHPStan WP
==========

[](#phpstan-wp)

A PHPStan extension providing custom rules for WordPress projects, specifically designed for WP Media projects

Overview
--------

[](#overview)

This extension adds static analysis rules to ensure proper implementation of WordPress hooks through subscriber classes. It validates that your event subscribers follow best practices for WordPress actions and filters.

Custom Rules
------------

[](#custom-rules)

### SubscriberCallbackRule

[](#subscribercallbackrule)

Validates `get_subscribed_events()` implementations in classes that implement subscriber interfaces. This rule ensures:

1. **Required Annotations**: All hook registrations must have `@action` or `@filter` PHPDoc annotations
2. **Filter Return Types**: Filter callbacks must return non-void values
3. **Action Return Types**: Action callbacks must return void
4. **Parameter Count Validation**: When `accepted_args` is specified, the callback method must have the correct number of parameters

#### Supported Subscriber Interfaces

[](#supported-subscriber-interfaces)

- `WP_Rocket\Event_Management\Subscriber_Interface`
- `Imagify\EventManagement\SubscriberInterface`
- `WPMedia\EventManager\SubscriberInterface`
- `WPMedia\BackWPup\EventManagement\SubscriberInterface`

Installation
------------

[](#installation)

Install via Composer:

```
composer require --dev wp-media/phpstan-wp
```

If you have [phpstan/extension-installer](https://github.com/phpstan/extension-installer) installed, the extension will be automatically registered.

### Manual Configuration

[](#manual-configuration)

If you don't use the extension installer, add this to your `phpstan.neon` or `phpstan.neon.dist`:

```
includes:
    - vendor/wp-media/phpstan-wp/extension.neon
```

Usage
-----

[](#usage)

### Valid Subscriber Example

[](#valid-subscriber-example)

```
