php-stubs / wp-cli-stubs

WP-CLI function and class declaration stubs for static analysis.
https://packagist.org/packages/php-stubs/wp-cli-stubs
MIT License
23 stars 2 forks source link

Include the CLI Tools in the wp-cli-stubs #14

Closed lipemat closed 1 year ago

lipemat commented 1 year ago

The WP_CLI namespaces contains a number of utilities which are stored in the wp-cli/php-cli-tools package.

For example the Progress Bar. (taken from the docs)

$count = 500;
$progress = \WP_CLI\Utils\make_progress_bar( 'Generating users', $count );
for ( $i = 0; $i < $count; $i++ ) {
    // uses wp_insert_user() to insert the user
    $progress->tick();
}
$progress->finish();

Without the 'php-cli-tools' being included, using these utilities will always fail PHPStan scans.

This change includes the 'php-cli-tools' in the finder and definition file for wp-cli-stubs.php

szepeviktor commented 1 year ago

Hello @lipemat!

Stubs are as small as they can be. php-cli-tools is a small package and has a nice autoloader and has no dependencies. https://github.com/wp-cli/php-cli-tools/blob/d788a2c79e02f2f735fbb2b9a53db94d0e1bca4f/composer.json#L34-L41 Just require it with Composer.

szepeviktor commented 1 year ago

WAIT! It is already included. https://github.com/search?q=repo%3Aphp-stubs%2Fwp-cli-stubs%20make_progress_bar&type=code

lipemat commented 1 year ago

It is already included. https://github.com/search?q=repo%3Aphp-stubs%2Fwp-cli-stubs%20make_progress_bar&type=code

The make_progress_bar function is included but the definitions for the returned Bar are not.

lipemat commented 1 year ago

Maybe the php-cli-utils stubs could be included as a separate file the way "commands-stubs" and "i18n-stubs" currently are. That would keep the main stubs lean without requiring a separate composer install.

Let me know if this a a viable option and I'll update the pull request. :-)

szepeviktor commented 1 year ago

The make_progress_bar function is included but the definitions for the returned Bar are not.

You are right.

@return \cli\progress\Bar|\WP_CLI\NoOp

Now I remember. I usually generate stubs from php-cli-tools https://github.com/szepeviktor/phpstan-wordpress/blob/master/stub-generators/php-cli-tools-generate-stubs.sh and include that file in my project's tests directory.

I am sorry. This was never requested and publishing a separate stubs package is something I cannot maintain.

szepeviktor commented 1 year ago

Adding php-cli-tools to wp-cli-stubs makes it 48924 bytes bigger.

@lipemat I promise you I will add it by the third request!

lipemat commented 1 year ago

In case anyone else is looking for this, I used the generate-stubs.sh script mentioned above to run off a stub and have included it here. https://github.com/lipemat/phpstan-wordpress/blob/master/stubs/wp-cli/php-cli-tools-0.11.11.php

srtfisher commented 2 months ago

I agree with the others here that it would make sense to include it in this package.

szepeviktor commented 2 months ago

Maybe the php-cli-utils stubs could be included as a separate file the way "commands-stubs" and "i18n-stubs" currently are.

@lipemat All right. I merge a PR for a separate stubs file. The request from @srtfisher changed my mind.

lipemat commented 2 months ago

@lipemat All right. I merge a PR for a separate stubs file. The request from @srtfisher changed my mind.

Great! I'll put together a pull request which generates the stubs separately.