PHPackages                             shockedplot7560/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. shockedplot7560/generator

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

shockedplot7560/generator
=========================

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

1.0.0(2y ago)04MITPHPPHP ^8.2

Since Sep 13Pushed 2y agoCompare

[ Source](https://github.com/ShockedPlot7560/php-stubs-generator)[ Packagist](https://packagist.org/packages/shockedplot7560/generator)[ Docs](https://github.com/ShockedPlot7560/generator)[ RSS](/packages/shockedplot7560-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

PHP Stubs Generator
===================

[](#php-stubs-generator)

[![Build Status](https://camo.githubusercontent.com/b1c2f434d0637df63ef86ad21c1450f73ffeb166bd871db060103013f4420f64/68747470733a2f2f7472617669732d63692e636f6d2f7068702d73747562732f67656e657261746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/github/php-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 [PHPStan](https://phpstan.org) or potentially other tools. Stub generation is particularly useful for code which mixes definitions with side-effects.

The generator is based on nikic's [PHP-Parser](https://github.com/nikic/PHP-Parser), and the code also relies on several [Symfony](https://symfony.com) components.

Contributions in the form of [issues](https://github.com/php-stubs/generator/issues/new) or Pull Requests are welcome!

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
        {
        }
    }
}
```

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

[](#command-line-usage)

To install:

```
composer global require php-stubs/generator
```

To get the pretty-printed stubs for all the PHP files in a directory:

```
generate-stubs /path/to/my-library
```

You may also pass multiple directories, or filenames, separated by spaces. All stubs will be concatenated in the output.

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
```

Usage in PHP
------------

[](#usage-in-php)

To install:

```
composer require php-stubs/generator
```

### 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

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity55

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

Unknown

Total

1

Last Release

978d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/66992287?v=4)[ShockedPlot7560 ](/maintainers/ShockedPlot7560)[@ShockedPlot7560](https://github.com/ShockedPlot7560)

---

Top Contributors

[![GiacoCorsiglia](https://avatars.githubusercontent.com/u/15148404?v=4)](https://github.com/GiacoCorsiglia "GiacoCorsiglia (37 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (17 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)")[![ShockedPlot7560](https://avatars.githubusercontent.com/u/66992287?v=4)](https://github.com/ShockedPlot7560 "ShockedPlot7560 (1 commits)")

---

Tags

idestatic analysis

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/shockedplot7560-generator/health.svg)

```
[![Health](https://phpackages.com/badges/shockedplot7560-generator/health.svg)](https://phpackages.com/packages/shockedplot7560-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.1M568](/packages/symfony-maker-bundle)[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)[coenjacobs/mozart

Composes all dependencies as a package inside a WordPress plugin

4723.6M20](/packages/coenjacobs-mozart)[php-stubs/generator

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

79291.0k45](/packages/php-stubs-generator)[giacocorsiglia/stubs-generator

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

25123.0k12](/packages/giacocorsiglia-stubs-generator)

PHPackages © 2026

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