{"id":28662641,"url":"https://github.com/php-stubs/generator","last_synced_at":"2025-06-13T11:12:30.462Z","repository":{"id":40561880,"uuid":"313070442","full_name":"php-stubs/generator","owner":"php-stubs","description":"Generate stubs from any PHP code for IDE completion and static analysis.","archived":false,"fork":false,"pushed_at":"2025-04-22T08:16:29.000Z","size":86,"stargazers_count":62,"open_issues_count":6,"forks_count":18,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-19T06:48:09.571Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://packagist.org/packages/php-stubs/generator","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"GiacoCorsiglia/php-stubs-generator","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/php-stubs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["php-stubs"]}},"created_at":"2020-11-15T16:12:50.000Z","updated_at":"2025-05-19T05:31:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"b0488f99-5212-4345-a461-56d840ea93f2","html_url":"https://github.com/php-stubs/generator","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/php-stubs/generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-stubs%2Fgenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-stubs%2Fgenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-stubs%2Fgenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-stubs%2Fgenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-stubs","download_url":"https://codeload.github.com/php-stubs/generator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-stubs%2Fgenerator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259634489,"owners_count":22887711,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-13T11:12:22.976Z","updated_at":"2025-06-13T11:12:30.454Z","avatar_url":"https://github.com/php-stubs.png","language":"PHP","funding_links":["https://github.com/sponsors/php-stubs"],"categories":[],"sub_categories":[],"readme":"# PHP Stubs Generator\n\n[![Build Status](https://github.com/php-stubs/generator/actions/workflows/test.yml/badge.svg)](https://github.com/php-stubs/generator/actions/workflows/test.yml)\n\nUse 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.\n\nThe 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.\n\nContributions in the form of [issues](https://github.com/php-stubs/generator/issues/new) or Pull Requests are welcome!\n\n## Example\n\nThe idea is to turn this:\n\n```php\n// source-file-1.php\n/**\n * @param string $bar\n * @return int\n */\nfunction foo($bar)\n{\n    return (int) $bar;\n}\n\n/** @var string */\n$something = '123abc';\n\nif ($something) {\n    echo foo($something);\n}\n\n// source-file-2.php\nnamespace MyNamespace;\n\nclass MyClass extends MyParentClass\n{\n    public function method(): string\n    {\n        return '';\n    }\n}\n```\n\nInto this:\n\n```php\n// stubs.php\nnamespace {\n    /**\n     * @param string $bar\n     * @return int\n     */\n    function foo($bar)\n    {\n    }\n\n    /** @var string */\n    $something = '123abc';\n}\n\nnamespace MyNamespace {\n    class MyClass extends MyParentClass\n    {\n        public function method(): string\n        {\n        }\n    }\n}\n```\n\n## Command Line Usage\n\nTo install:\n\n```bash\ncomposer global require php-stubs/generator\n```\n\nTo get the pretty-printed stubs for all the PHP files in a directory:\n\n```bash\ngenerate-stubs /path/to/my-library\n```\n\nYou may also pass multiple directories, or filenames, separated by spaces.  All stubs will be concatenated in the output.\n\nTo write the stubs to a file (and see a few statistics in the stdout):\n\n```bash\ngenerate-stubs /path/to/my-library --out=/path/to/output.php\n```\n\nFor the complete set of command line options:\n\n```bash\ngenerate-stubs --help\n```\n\n## Usage in PHP\n\nTo install:\n\n```bash\ncomposer require php-stubs/generator\n```\n\n### Simple Example\n\n```php\n// You'll need the Composer Autoloader.\nrequire 'vendor/autoload.php';\n\n// You may alias the classnames for convenience.\nuse StubsGenerator\\{StubsGenerator, Finder};\n\n// First, instantiate a `StubsGenerator\\StubsGenerator`.\n$generator = new StubsGenerator();\n\n// Then, create a `StubsGenerator\\Finder` which contains\n// the set of files you wish to generate stubs for.\n$finder = Finder::create()-\u003ein('/path/to/my-library/');\n\n// Now you may use the `StubsGenerator::generate()` method,\n// which will return a `StubsGenerator\\Result` instance.\n$result = $generator-\u003egenerate($finder);\n\n// You can use the `Result` instance to pretty-print the stubs.\necho $result-\u003eprettyPrint();\n\n// You can also use it to retrieve the PHP-Parser nodes\n// that represent the generated stub declarations.\n$stmts = $result-\u003egetStubStmts();\n```\n\n### Additional Features\n\nYou can restrict the set of symbol types for which stubs are generated:\n\n```php\n// This will only generate stubs for function declarations.\n$generator = new StubsGenerator(StubsGenerator::FUNCTIONS);\n\n// This will only generate stubs for class or interface declarations.\n$generator = new StubsGenerator(StubsGenerator::CLASSES | StubsGenerator::INTERFACES);\n```\n\nThe set of symbol types are:\n\n- `StubsGenerator::FUNCTIONS`: Function declarations.\n- `StubsGenerator::CLASSES`: Class declarations.\n- `StubsGenerator::TRAITS`: Trait declarations.\n- `StubsGenerator::INTERFACES`: Interface declarations.\n- `StubsGenerator::DOCUMENTED_GLOBALS`: Global variables, but only those with a doc comment.\n- `StubsGenerator::UNDOCUMENTED_GLOBALS`: Global variable, but only those without a doc comment.\n- `StubsGenerator::GLOBALS`: Shortcut to include both documented and undocumented global variables.\n- `StubsGenerator::CONSTANTS`: Constant declarations.\n- `StubsGenerator::DEFAULT`: Shortcut to include everything _except_ undocumented global variables.\n- `StubsGenerator::ALL`: Shortcut to include everything.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-stubs%2Fgenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-stubs%2Fgenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-stubs%2Fgenerator/lists"}