PHPackages                             lucasbustamante/stubz - 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. [CLI &amp; Console](/categories/cli)
4. /
5. lucasbustamante/stubz

ActiveLibrary[CLI &amp; Console](/categories/cli)

lucasbustamante/stubz
=====================

A command-line PHP stub generator using BetterReflection.

0.2(8mo ago)01.6kMITPHPPHP ^8.2CI passing

Since Mar 1Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/Luc45/stubz)[ Packagist](https://packagist.org/packages/lucasbustamante/stubz)[ RSS](/packages/lucasbustamante-stubz/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (3)Versions (3)Used By (0)

[![PHPStan - Level 10](https://github.com/Luc45/stubz/actions/workflows/phpstan.yml/badge.svg)](https://github.com/Luc45/stubz/actions/workflows/phpstan.yml)[![PHPUnit](https://github.com/Luc45/stubz/actions/workflows/phpunit.yml/badge.svg)](https://github.com/Luc45/stubz/actions/workflows/phpunit.yml)

Stubz for WordPress Plugins
===========================

[](#stubz-for-wordpress-plugins)

**Stubz** is a command-line utility designed to generate **PHP stub files** specifically tailored for WordPress plugins, although it supports any PHP codebase. PHP stubs simplify static analysis by providing a lightweight representation of your plugin's classes, traits, interfaces, functions, and constants, excluding implementation logic.

Stubz was initially developed to support the **Quality Insights Toolkit (QIT)** at **Automattic**, helping to enhance the reliability and accuracy of static code analysis within WordPress plugin ecosystems.

WordPress operates as an **event-driven framework**, meaning many plugins define classes and functions within event callbacks (hooks). A common pattern in WordPress plugins that trips static code analysis involves defining classes inside action callbacks. For example:

```
add_action('plugins_loaded', function() {
    class MyPluginMainClass {
        // class logic
    }
});
```

In static analysis tools like PHPStan, there's no guarantee the `plugins_loaded` action will ever be invoked. As a result, the tool fails to recognize dynamically defined classes, producing false positives or "class not found" errors.

Stubz resolves this issue by **"flattening" the code definitions**. It moves class, function, and constant definitions out of callbacks, making them readily discoverable for static analysis.

Recommended Usage
-----------------

[](#recommended-usage)

### Using QIT (WooCommerce Marketplace Extensions)

[](#using-qit-woocommerce-marketplace-extensions)

For WooCommerce extensions distributed via the WooCommerce.com Marketplace, the recommended approach is to use the [PHPStan Managed Tests provided by QIT](https://qit.woo.com/docs/managed-tests/phpstan). QIT's managed PHPStan tests automatically leverage Stubz, greatly simplifying your workflow.

### Using PHPStan Directly (General Plugins)

[](#using-phpstan-directly-general-plugins)

If you're working with general WordPress plugins, you can manually configure PHPStan to work with Stubz as follows:

PHPStan differentiates between two important concepts:

- **Scan:** PHPStan scans files to discover classes, functions, constants, and other code structures.
- **Analyse:** PHPStan analyses the scanned files for potential errors, type mismatches, incorrect method calls, and other code quality issues.

Configure PHPStan manually by:

- **Analysing** your plugin's actual source code for code quality:

```
./vendor/bin/phpstan analyse ./src
```

- **Scanning** the generated stubs to ensure dynamically defined entities are recognized:

```
parameters:
    scanDirectories:
        - ./src-stubs
```

This configuration ensures accurate static analysis while eliminating common WordPress-specific false positives.

Features
--------

[](#features)

- **Generates stubs** for classes, interfaces, traits, enums, functions, and constants.
- Supports complex, nested WordPress-specific patterns.
- Handles modern PHP features including:
    - Final &amp; abstract classes and methods
    - Readonly properties (PHP 8.1+)
    - Enums (PHP 8.1+), including `case`s
    - Attributes (PHP 8+), with reflection on arguments
    - Intersection &amp; union types, typed properties, constructor promotion
- **Exclude** specific directories/files using `--exclude `.
- **Custom Finder mode** (`--finder `) for advanced queries.

Requirements
------------

[](#requirements)

- **PHP 8.2** or later
- Composer dependencies (`roave/better-reflection`, `symfony/finder`)

Quick Start Guide
-----------------

[](#quick-start-guide)

1. Install Stubz using Composer:

    ```
    composer require lucasbustamante/stubz --dev
    ```
2. Generate stubs for your plugin:

    ```
    ./vendor/bin/stubz ./src ./src-stubs
    ```

### Excluding Directories

[](#excluding-directories)

Exclude directories like vendor, tests, or build artifacts:

```
./vendor/bin/stubz --exclude vendor --exclude tests ./src ./src-stubs
```

### Using a Custom Finder

[](#using-a-custom-finder)

For more complex inclusion/exclusion logic, create a `finder.php`:

```
use Symfony\Component\Finder\Finder;

$finder = Finder::create()
    ->files()
    ->in(__DIR__ . '/src')
    ->name('*.php')
    ->exclude('tests');

return $finder;
```

Then run Stubz:

```
./vendor/bin/stubz --finder finder.php ./src-stubs
```

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance59

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 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 ~230 days

Total

2

Last Release

261d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/83326082?v=4)[Lucas Bustamante](/maintainers/lucasbustamante)[@lucasbustamante](https://github.com/lucasbustamante)

---

Top Contributors

[![Luc45](https://avatars.githubusercontent.com/u/9341686?v=4)](https://github.com/Luc45 "Luc45 (78 commits)")

### Embed Badge

![Health badge](/badges/lucasbustamante-stubz/health.svg)

```
[![Health](https://phpackages.com/badges/lucasbustamante-stubz/health.svg)](https://phpackages.com/packages/lucasbustamante-stubz)
```

###  Alternatives

[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k251.2M25.3k](/packages/friendsofphp-php-cs-fixer)[infection/infection

Infection is a Mutation Testing framework for PHP. The mutation adequacy score can be used to measure the effectiveness of a test set in terms of its ability to detect faults.

2.2k28.9M2.4k](/packages/infection-infection)[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k251.7M11.6k](/packages/symfony-framework-bundle)[drush/drush

Drush is a command line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those of us who spend some of our working hours hacking away at the command prompt.

2.4k60.6M804](/packages/drush-drush)[jolicode/castor

A lightweight and modern task runner. Automate everything. In PHP.

54743.1k4](/packages/jolicode-castor)[api-platform/symfony

Symfony API Platform integration

384.5M129](/packages/api-platform-symfony)

PHPackages © 2026

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