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

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

giacocorsiglia/stubs-generator
==============================

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

v0.5(8y ago)25123.0k—1.8%3[4 issues](https://github.com/GiacoCorsiglia/php-stubs-generator/issues)[2 PRs](https://github.com/GiacoCorsiglia/php-stubs-generator/pulls)12MITPHPPHP &gt;=7.1

Since Feb 12Pushed 4y ago3 watchersCompare

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

READMEChangelogDependencies (7)Versions (6)Used By (12)

‼️ This project is not maintained ‼️
====================================

[](#️-this-project-is-not-maintained-️)

You should use the fork at [php-stubs/generator](https://github.com/php-stubs/generator), which is thanks to [@szepeviktor](https://github.com/szepeviktor).

---

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

[](#php-stubs-generator)

[![Build Status](https://camo.githubusercontent.com/dc6dfc47eefcaac64b89139c6cf2b7febd83910dcc8c40ce93d639b20b949640/68747470733a2f2f7472617669732d63692e6f72672f476961636f436f727369676c69612f7068702d73747562732d67656e657261746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/GiacoCorsiglia/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 [Psalm](https://getpsalm.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 issue reports 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 giacocorsiglia/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 giacocorsiglia/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::DEFAULT`: Shortcut to include everything *except* undocumented global variables.
- `StubsGenerator::ALL`: Shortcut to include everything.

TODO
----

[](#todo)

- Add support for constants declared with `const`.
- Add support for constants declared with `define()`.
    - Consider parsing function and method bodies for these declarations.

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 97.4% 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 ~15 days

Total

5

Last Release

2956d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15148404?v=4)[Giaco Corsiglia](/maintainers/GiacoCorsiglia)[@GiacoCorsiglia](https://github.com/GiacoCorsiglia)

---

Top Contributors

[![GiacoCorsiglia](https://avatars.githubusercontent.com/u/15148404?v=4)](https://github.com/GiacoCorsiglia "GiacoCorsiglia (38 commits)")[![szepeviktor](https://avatars.githubusercontent.com/u/952007?v=4)](https://github.com/szepeviktor "szepeviktor (1 commits)")

---

Tags

idestatic analysis

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/giacocorsiglia-stubs-generator/health.svg)](https://phpackages.com/packages/giacocorsiglia-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.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)[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)
