PHPackages                             onepix/wordpress-stubs-generator - 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. onepix/wordpress-stubs-generator

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

onepix/wordpress-stubs-generator
================================

Generate stubs from any PHP code for IDE completion and static analysis.

v1.2.0(1y ago)16018MITPHPPHP ^8.1

Since Nov 27Pushed 1y agoCompare

[ Source](https://github.com/0zd0/wordpress-stubs-generator)[ Packagist](https://packagist.org/packages/onepix/wordpress-stubs-generator)[ Docs](https://github.com/0zd0/wordpress-stubs-generator)[ RSS](/packages/onepix-wordpress-stubs-generator/feed)WikiDiscussions dev Synced 1mo ago

READMEChangelogDependencies (6)Versions (11)Used By (8)

Wordpress Stubs Generator
=========================

[](#wordpress-stubs-generator)

Use this tool to generate stub declarations for functions, classes, interfaces, and global variables defined in any PHP code. The stubs can subsequently be used to facilitate IDE completion or static analysis via Psalm, [PHPStan](https://phpstan.org) or potentially other tools. Stub generation is particularly useful for code which mixes definitions with side-effects.

### Install

[](#install)

```
composer require --dev onepix/wordpress-stubs-generator
```

Command Line Usage
------------------

[](#command-line-usage)

To write the stubs to a file (and see a few statistics in the stdout):

```
generate-stubs /path/to/my-library --out=/path/to/output.php
```

For the complete set of command line options:

```
generate-stubs --help
```

### Example

[](#example)

The idea is to turn this:

```
// source-file-1.php
/**
 * @param string $bar
 * @return int
 */
function foo($bar)
{
    return (int) $bar;
}

/** @var string */
$something = '123abc';

if ($something) {
    echo foo($something);
}

// source-file-2.php
namespace MyNamespace;

class MyClass extends MyParentClass
{
    public function method(): string
    {
        return '';
    }
}
```

Into this:

```
// stubs.php
namespace {
    /**
     * @param string $bar
     * @return int
     */
    function foo($bar)
    {
    }

    /** @var string */
    $something = '123abc';
}

namespace MyNamespace {
    class MyClass extends MyParentClass
    {
        public function method(): string
        {
        }
    }
}
```

### Simple Example

[](#simple-example)

```
// You'll need the Composer Autoloader.
require 'vendor/autoload.php';

// You may alias the classnames for convenience.
use StubsGenerator\{StubsGenerator, Finder};

// First, instantiate a `StubsGenerator\StubsGenerator`.
$generator = new StubsGenerator();

// Then, create a `StubsGenerator\Finder` which contains
// the set of files you wish to generate stubs for.
$finder = Finder::create()->in('/path/to/my-library/');

// Now you may use the `StubsGenerator::generate()` method,
// which will return a `StubsGenerator\Result` instance.
$result = $generator->generate($finder);

// You can use the `Result` instance to pretty-print the stubs.
echo $result->prettyPrint();

// You can also use it to retrieve the PHP-Parser nodes
// that represent the generated stub declarations.
$stmts = $result->getStubStmts();
```

### Additional Features

[](#additional-features)

You can restrict the set of symbol types for which stubs are generated:

```
// This will only generate stubs for function declarations.
$generator = new StubsGenerator(StubsGenerator::FUNCTIONS);

// This will only generate stubs for class or interface declarations.
$generator = new StubsGenerator(StubsGenerator::CLASSES | StubsGenerator::INTERFACES);
```

The set of symbol types are:

- `StubsGenerator::FUNCTIONS`: Function declarations.
- `StubsGenerator::CLASSES`: Class declarations.
- `StubsGenerator::TRAITS`: Trait declarations.
- `StubsGenerator::INTERFACES`: Interface declarations.
- `StubsGenerator::DOCUMENTED_GLOBALS`: Global variables, but only those with a doc comment.
- `StubsGenerator::UNDOCUMENTED_GLOBALS`: Global variable, but only those without a doc comment.
- `StubsGenerator::GLOBALS`: Shortcut to include both documented and undocumented global variables.
- `StubsGenerator::CONSTANTS`: Constant declarations.
- `StubsGenerator::DEFAULT`: Shortcut to include everything *except* undocumented global variables.
- `StubsGenerator::ALL`: Shortcut to include everything.

###  Health Score

34

—

LowBetter than 77% of packages

Maintenance41

Moderate activity, may be stable

Popularity15

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

9

Last Release

492d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/380c3a3697647ffa6dacfa3f41ef2d8ea43a40a12a823d380b843b57ac14750c?d=identicon)[onepix](/maintainers/onepix)

![](https://www.gravatar.com/avatar/7f618d5c06c711c1eada5b9569aad7cee6d81e830566775e7734dd87828e8fdc?d=identicon)[0zd0](/maintainers/0zd0)

---

Top Contributors

[![GiacoCorsiglia](https://avatars.githubusercontent.com/u/15148404?v=4)](https://github.com/GiacoCorsiglia "GiacoCorsiglia (37 commits)")[![0zd0](https://avatars.githubusercontent.com/u/67220210?v=4)](https://github.com/0zd0 "0zd0 (21 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (18 commits)")[![simonhammes](https://avatars.githubusercontent.com/u/10352679?v=4)](https://github.com/simonhammes "simonhammes (8 commits)")[![machitgarha](https://avatars.githubusercontent.com/u/14151550?v=4)](https://github.com/machitgarha "machitgarha (7 commits)")[![johnbillion](https://avatars.githubusercontent.com/u/208434?v=4)](https://github.com/johnbillion "johnbillion (4 commits)")[![herndlm](https://avatars.githubusercontent.com/u/5738896?v=4)](https://github.com/herndlm "herndlm (2 commits)")[![kkmuffme](https://avatars.githubusercontent.com/u/11071985?v=4)](https://github.com/kkmuffme "kkmuffme (1 commits)")[![criskell](https://avatars.githubusercontent.com/u/96352451?v=4)](https://github.com/criskell "criskell (1 commits)")

---

Tags

idestatic analysis

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/onepix-wordpress-stubs-generator/health.svg)

```
[![Health](https://phpackages.com/badges/onepix-wordpress-stubs-generator/health.svg)](https://phpackages.com/packages/onepix-wordpress-stubs-generator)
```

###  Alternatives

[symfony/maker-bundle

Symfony Maker helps you create empty commands, controllers, form classes, tests and more so you can forget about writing boilerplate code.

3.4k111.1M565](/packages/symfony-maker-bundle)[friendsofphp/php-cs-fixer

A tool to automatically fix PHP code style

13.5k234.7M20.6k](/packages/friendsofphp-php-cs-fixer)[vimeo/psalm

A static analysis tool for finding errors in PHP applications

5.8k77.5M6.7k](/packages/vimeo-psalm)[symplify/monorepo-builder

Not only Composer tools to build a Monorepo.

5205.3M82](/packages/symplify-monorepo-builder)[php-stubs/generator

Generate stubs from any PHP code for IDE completion and static analysis.

79291.0k45](/packages/php-stubs-generator)[friendsoftypo3/content-blocks

TYPO3 CMS Content Blocks - Content Types API | Define reusable components via YAML

96374.6k23](/packages/friendsoftypo3-content-blocks)

PHPackages © 2026

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