php-stubs / wordpress-stubs

Up-to-date WordPress function and class declaration stubs for static analysis by PHPStan
https://packagist.org/packages/php-stubs/wordpress-stubs
MIT License
136 stars 18 forks source link

function wp_remote_retrieve_header expects array|WP_Error, httpReturnType given. #150

Closed MocioF closed 6 months ago

MocioF commented 6 months ago

Hi, I'm using wordpress-stubs with PHPStan for a plugin. One of my methods returns the result of wp_remote_get()so I wrote in its phpdoc's comment: @return httpReturnType|WP_Error

Now when I use the returned value in another method calling wp_remote_retrieve_header PHPStan says Parameter #1 $response of function wp_remote_retrieve_header expects array|WP_Error, httpReturnType given.

Why httpReturnType is not seen as an array?

szepeviktor commented 6 months ago

Hello @MocioF!

Thank you for your report.

There is no httpReturnType type. That variable holds an array shape. Please write that array shape into your method. https://github.com/php-stubs/wordpress-stubs/blob/5b0b62320bf41013db4cea68426ab2b959abaa28/functionMap.php#L5

MocioF commented 6 months ago

Thanks @szepeviktor , this is what I'm doing now. Not sure if this can help, but now PHPStan says: Class WP_Http_Cookie referenced with incorrect case: WP_HTTP_Cookie.

szepeviktor commented 6 months ago

Class WP_Http_Cookie referenced with incorrect case: WP_HTTP_Cookie.

That is an error.

https://github.com/php-stubs/wordpress-stubs/blob/5b0b62320bf41013db4cea68426ab2b959abaa28/functionMap.php#L5-L9

Would you like to send a PR?