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

Return type of WP_CLI\Iterators\CSV::count() should either be compatible with Countable::count(): int #16

Open m1r0 opened 11 months ago

m1r0 commented 11 months ago

Hey, first, thanks for making this! It makes my life easier.

I've stumbled on the following error when running it with Psalm on PHP 8.1:

Fatal error: During inheritance of Countable: Uncaught RuntimeException: PHP Error: Return type of WP_CLI\Iterators\CSV::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/m1r0/Projects/sensei/vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php:2467 in /Users/m1r0/Projects/sensei/vendor/vimeo/psalm/src/Psalm/Internal/ErrorHandler.php:66

Let me know if you need more info. Thanks. 🙏

szepeviktor commented 11 months ago

Hello @m1r0 👋🏻

In this repo there are so many things against solving your problem.

Anyways, have you seen https://github.com/wp-cli/wp-cli/pull/5743 ? That PR is included in 2.8.0 ... and included in the stubs too! https://github.com/php-stubs/wp-cli-stubs/blob/master/wp-cli-stubs.php#L2593

Are you using 2.8.0?

m1r0 commented 11 months ago

Oh, sorry, I did a few tests using the older version and I've used the wrong error log. Here's the correct one:

Fatal error: During inheritance of Countable: Uncaught RuntimeException: PHP Error: Return type of WP_CLI\Iterators\CSV::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /Users/m1r0/Projects/sensei/vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php:2467 in /Users/m1r0/Projects/sensei/vendor/vimeo/psalm/src/Psalm/Internal/ErrorHandler.php:66

I've updated the issue to reflect the above.

Reading your response, it sounds like this needs to be fixed in the wp-cli/wp-cli repo first. Is that correct?

szepeviktor commented 11 months ago

this needs to be fixed in the wp-cli/wp-cli repo first. Is that correct?

Yes! This repo is generated from that.

Please search for "Iterator" https://github.com/search?q=repo%3Awp-cli%2Fwp-cli%20Iterator&type=code or use PHPStan.

jonathan-dejong commented 3 months ago

👋 @szepeviktor

This seems to be fixed there now but the stubs still throws this error for me 🤔

Using: php-stubs/wp-cli-stubs: 2.10.0 WP-CLI version: 2.10.0

throwing errors:

Deprecated: Return type of WP_CLI\Iterators\CSV::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php on line 2475
Deprecated: Return type of WP_CLI\Iterators\CSV::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php on line 2466
Deprecated: Return type of WP_CLI\Iterators\CSV::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php on line 2472
Deprecated: Return type of WP_CLI\Iterators\CSV::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php on line 2469
Deprecated: Return type of WP_CLI\Iterators\CSV::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php on line 2478
Deprecated: Return type of WP_CLI\Iterators\CSV::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/php-stubs/wp-cli-stubs/wp-cli-stubs.php on line 2463
Deprecated: Return type of WP_Map_Iterator::current() should either be compatible with IteratorIterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php on line 10776
Deprecated: Return type of WP_Post_IDs_Iterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php on line 10789
Deprecated: Return type of WP_Post_IDs_Iterator::next() should either be compatible with Iterator::next(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php on line 10795
Deprecated: Return type of WP_Post_IDs_Iterator::key() should either be compatible with Iterator::key(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php on line 10792
Deprecated: Return type of WP_Post_IDs_Iterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php on line 10801
Deprecated: Return type of WP_Post_IDs_Iterator::rewind() should either be compatible with Iterator::rewind(): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in vendor/php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php on line 10798
Error thrown in vendor/php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php on line 15078 while loading bootstrap file vendor/phpstan/phpstan/../../php-stubs/wp-cli-stubs/wp-cli-commands-stubs.php: Class "Composer\IO\NullIO" not found

Edit: Not sure if it is relevant or not but this is running PHP 8.1.

szepeviktor commented 3 months ago

@jonathan-dejong Thank you! Could it be that ReturnTypeWillChange-s are missing from the latest stubs?

jonathan-dejong commented 2 months ago

@szepeviktor Not sure.. I got the error to go away for now by not including the wp-cli-commands-stubs.php stubs specifically. But I think you are right though because if I search for ReturnTypeWillChange in the file(s) it's not present.