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

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

pavsolo/generator
=================

06PHP

Since Jan 29Pushed 3mo agoCompare

[ Source](https://github.com/PavSolo/generator)[ Packagist](https://packagist.org/packages/pavsolo/generator)[ RSS](/packages/pavsolo-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

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

[](#php-stubs-generator)

[![Build Status](https://github.com/php-stubs/generator/actions/workflows/test.yml/badge.svg)](https://github.com/php-stubs/generator/actions/workflows/test.yml)

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

21

—

LowBetter than 19% of packages

Maintenance54

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity12

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/3da5c9ba146d813924c3a95190ec588e9f2a25be99b250db08d8e93cd58c41cc?d=identicon)[PavSolo](/maintainers/PavSolo)

---

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 (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)")[![kkmuffme](https://avatars.githubusercontent.com/u/11071985?v=4)](https://github.com/kkmuffme "kkmuffme (3 commits)")[![PavSolo](https://avatars.githubusercontent.com/u/102298051?v=4)](https://github.com/PavSolo "PavSolo (2 commits)")[![herndlm](https://avatars.githubusercontent.com/u/5738896?v=4)](https://github.com/herndlm "herndlm (2 commits)")[![mikemanger](https://avatars.githubusercontent.com/u/74821?v=4)](https://github.com/mikemanger "mikemanger (2 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")[![criskell](https://avatars.githubusercontent.com/u/96352451?v=4)](https://github.com/criskell "criskell (1 commits)")[![philipjohn](https://avatars.githubusercontent.com/u/136342?v=4)](https://github.com/philipjohn "philipjohn (1 commits)")[![selfiens](https://avatars.githubusercontent.com/u/2247403?v=4)](https://github.com/selfiens "selfiens (1 commits)")[![IanDelMar](https://avatars.githubusercontent.com/u/42134098?v=4)](https://github.com/IanDelMar "IanDelMar (1 commits)")

### Embed Badge

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

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

###  Alternatives

[phpjuice/slopeone

PHP implementation of the Weighted Slope One rating-based collaborative filtering scheme.

868.7k](/packages/phpjuice-slopeone)[thisisbd/silverstripe-fontawesome-iconpickerfield

Font Awesome Icon Picker for SilverStripe 3.1.x based on http://mjolnic.com/fontawesome-iconpicker

143.3k1](/packages/thisisbd-silverstripe-fontawesome-iconpickerfield)

PHPackages © 2026

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