php-stubs / generator

Generate stubs from any PHP code for IDE completion and static analysis.
https://packagist.org/packages/php-stubs/generator
MIT License
54 stars 12 forks source link

Feature Request: Automate Stub File Generation for Large Codebase with Splitting into Multiple Files #28

Open owaisahmed5300 opened 2 days ago

owaisahmed5300 commented 2 days ago

Currently, the stub generator creates a single file for the entire codebase, which becomes inefficient for larger projects. I request a feature that automatically splits the stub generation into multiple files based on subfolders or another logical structure.

Reason for Request: This request is primarily to improve the performance of static analysis tools such as PHPStan. For projects that rely heavily on stubs, analyzing a single large stub file significantly slows down the analysis process. Splitting the stubs into multiple, smaller files would make it much easier for static analyzers to process and analyze the stubs more efficiently.

Expected Behavior:

The stub generator should automatically detect subfolders and generate separate stub files for each folder (or based on another configurable structure). The generated stubs should be organized into multiple files, making it easier to manage and allowing static analysis tools like PHPStan to analyze them faster. Current Behavior:

The generator currently creates a single stub file for the entire codebase, which causes slowdowns when using static analysis tools.

If there’s any other way to achieve a similar result without splitting files, suggestions would also be appreciated!

szepeviktor commented 2 days ago

Hello @owaisahmed5300 👋🏻

This is the fork of the original and abandoned generator. For php-stubs purposes.

BTW Those separate files would depend on each other!!

owaisahmed5300 commented 2 days ago

Can you suggest a solution for handling large stubs? PHPStan takes too much time to process a large stub file.

PHPStan works faster if we split a large stub file into multiple smaller files. It becomes extremely, slow when processing a single stub file with 100k lines of code.

I’ve seen other stub projects, such as WordPress & WooCommerce stubs, which consist of multiple files. I’d like to know how they were generated.

szepeviktor commented 2 days ago

Can you suggest a solution for handling large stubs?

Create stubs only where necessary. Class-autoloaded code needs no stubs!

I’ve seen other stub projects, such as WordPress & WooCommerce stubs, which consist of multiple files.

WP stubs are in one file, WC stubs for packages are rarely used: they were separated to a second file.