szepeviktor / phpstan-wordpress

WordPress extensions for PHPStan ⛏️
https://packagist.org/packages/szepeviktor/phpstan-wordpress
MIT License
261 stars 26 forks source link

We are not perfect: stubs problems #219

Closed szepeviktor closed 5 days ago

szepeviktor commented 3 months ago

Please help!

many errors ``` 530 Property WP_Upgrader::$result (array{source: string, source_files: string, destination: string, destination_name: string, local_destination: string, remote_destination: string, clear_destination: bool}|WP_Error) does not accept default value of type array{}. πŸ’‘ Array does not have offset 'source'. 963 Default value of the parameter #1 $admin_header_callback ('') of method Custom_Background::__construct() is incompatible with type callable(): mixed. 963 Default value of the parameter #2 $admin_image_div_callback ('') of method Custom_Background::__construct() is incompatible with type callable(): mixed. 1094 Default value of the parameter #2 $admin_image_div_callback ('') of method Custom_Image_Header::__construct() is incompatible with type callable(): mixed. 1541 Constant FTP_AUTOASCII not found. 1889 PHPDoc type array|WP_Error of property Language_Pack_Upgrader::$result is not covariant with PHPDoc type array{source: string, source_files: string, destination: string, destination_name: string, local_destination: string, remote_destination: string, clear_destination: bool}|WP_Error of overridden property WP_Upgrader::$result. 2946 PHPDoc type array|WP_Error of property Plugin_Upgrader::$result is not covariant with PHPDoc type array{source: string, source_files: string, destination: string, destination_name: string, local_destination: string, remote_destination: string, clear_destination: bool}|WP_Error of overridden property WP_Upgrader::$result. 3265 PHPDoc type array|WP_Error of property Theme_Upgrader::$result is not covariant with PHPDoc type array{source: string, source_files: string, destination: string, destination_name: string, local_destination: string, remote_destination: string, clear_destination: bool}|WP_Error of overridden property WP_Upgrader::$result. 3823 Property Walker_Nav_Menu::$tree_type (string) does not accept default value of type array. 3845 Parameter #3 $args (stdClass) of method Walker_Nav_Menu::start_lvl() should be compatible with parameter $args (array) of method Walker::start_lvl() 3859 Parameter #3 $args (stdClass) of method Walker_Nav_Menu::end_lvl() should be compatible with parameter $args (array) of method Walker::end_lvl() 3878 Parameter #4 $args (stdClass) of method Walker_Nav_Menu::start_el() should be compatible with parameter $args (array) of method Walker::start_el() 3894 Parameter #4 $args (stdClass) of method Walker_Nav_Menu::end_el() should be compatible with parameter $args (array) of method Walker::end_el() 4476 Default value of the parameter #1 $which ('') of method WP_List_Table::bulk_actions() is incompatible with type 'bottom'|'top'. 6694 Default value of the parameter #1 $opt (string) of method WP_Filesystem_FTPext::__construct() is incompatible with type array. 7129 Default value of the parameter #1 $opt (string) of method WP_Filesystem_ftpsockets::__construct() is incompatible with type array. 7538 Property WP_Filesystem_SSH2::$link (resource) does not accept default value of type false. 7557 Default value of the parameter #1 $opt (string) of method WP_Filesystem_SSH2::__construct() is incompatible with type array. 9730 Parameter #1 $comment_status (bool) of method WP_Post_Comments_List_Table::get_per_page() should be compatible with parameter $comment_status (string) of method WP_Comments_List_Table::get_per_page() 12492 Default value of the parameter #2 $page (string) of method WP_User_Search::__construct() is incompatible with type int. 12505 Default value of the parameter #2 $page (string) of method WP_User_Search::WP_User_Search() is incompatible with type int. 13545 Constant GETID3_TEMP_DIR not found. 18867 Parameter $handle of method WpOrg\Requests\Auth\Basic::curl_before_send() has invalid type CurlHandle. 19854 Parameter $hostname of method WpOrg\Requests\IdnaEncoder::encode() has invalid type WpOrg\Requests\Stringable. 19977 Parameter $ip of method WpOrg\Requests\Ipv6::uncompress() has invalid type WpOrg\Requests\Stringable. 20169 Parameter $iri of method WpOrg\Requests\Iri::__construct() has invalid type WpOrg\Requests\Stringable. 20517 Parameter $handle of method WpOrg\Requests\Proxy\Http::curl_before_send() has invalid type CurlHandle. 20850 Parameter $url of method WpOrg\Requests\Requests::request() has invalid type WpOrg\Requests\Stringable. 20925 Parameter $path of method WpOrg\Requests\Requests::set_certificate_path() has invalid type WpOrg\Requests\Stringable. 21065 Property WpOrg\Requests\Response::$headers (WpOrg\Requests\Response\Headers) does not accept default value of type array. 21107 Property WpOrg\Requests\Response::$cookies (WpOrg\Requests\Cookie\Jar) does not accept default value of type array. 21375 Parameter $url of method WpOrg\Requests\Session::__construct() has invalid type WpOrg\Requests\Stringable. 21542 Parameter $host of method WpOrg\Requests\Ssl::verify_certificate() has invalid type WpOrg\Requests\Stringable. 21562 Parameter $reference of method WpOrg\Requests\Ssl::verify_reference_name() has invalid type WpOrg\Requests\Stringable. 21573 Parameter $host of method WpOrg\Requests\Ssl::match_domain() has invalid type WpOrg\Requests\Stringable. 21573 Parameter $reference of method WpOrg\Requests\Ssl::match_domain() has invalid type WpOrg\Requests\Stringable. 21674 Parameter $url of method WpOrg\Requests\Transport\Curl::request() has invalid type WpOrg\Requests\Transport\Stringable. 21699 Method WpOrg\Requests\Transport\Curl::get_subrequest_handle() has invalid return type CurlHandle. 21720 Parameter $handle of method WpOrg\Requests\Transport\Curl::stream_headers() has invalid type CurlHandle. 21732 Parameter $handle of method WpOrg\Requests\Transport\Curl::stream_body() has invalid type CurlHandle. 21789 Parameter $url of method WpOrg\Requests\Transport\Fsockopen::request() has invalid type WpOrg\Requests\Transport\Stringable. 22912 Property SimplePie_Cache_Redis::$data has unknown class type as its type. 22920 PHPDoc tag @param references unknown parameter: $type 23503 Constant SIMPLEPIE_USERAGENT not found. 23610 Constant SIMPLEPIE_LOCATOR_ALL not found. 23876 Default value of the parameter #1 $encoding (false) of method SimplePie::set_input_encoding() is incompatible with type string. 23891 Constant SIMPLEPIE_LOCATOR_ALL not found. 24014 Constant SIMPLEPIE_USERAGENT not found. 24106 PHPDoc tag @param has invalid value (array List of HTTPS domains. Example array('biz', 'example.com', 'example.org', 'www.example.net').): Unexpected token "List", expected variable at offset 145 24115 Default value of the parameter #1 $page (false) of method SimplePie::set_image_handler() is incompatible with type string. 25691 Constant SIMPLEPIE_FILE_SOURCE_NONE not found. 26104 Method SimplePie_IRI::absolutize() has invalid return type IRI. 26104 Parameter $base of method SimplePie_IRI::absolutize() has invalid type IRI. 26104 Parameter $relative of method SimplePie_IRI::absolutize() has invalid type IRI. 26845 Constant SIMPLEPIE_LOCATOR_ALL not found. 27043 PHPDoc tag @param references unknown parameter: $data 27414 Array has 2 duplicate keys with value 'jan' ('jan', 'jan'). 27416 Array has 2 duplicate keys with value 'feb' ('feb', 'feb'). 27420 Array has 2 duplicate keys with value 'apr' ('apr', 'apr'). 27421 Array has 3 duplicate keys with value 'april' ('april', 'april', 'april'). 27424 Array has 2 duplicate keys with value 'jun' ('jun', 'jun'). 27426 Array has 2 duplicate keys with value 'jul' ('jul', 'jul'). 27428 Array has 2 duplicate keys with value 'aug' ('aug', 'aug'). 27429 Array has 2 duplicate keys with value 'august' ('august', 'august'). 27430 Array has 2 duplicate keys with value 'sep' ('sep', 'sep'). 27431 Array has 3 duplicate keys with value 'september' ('september', 'september', 'september'). 27434 Array has 2 duplicate keys with value 'nov' ('nov', 'nov'). 27435 Array has 4 duplicate keys with value 'november' ('november', 'november', 'november', 'november'). 27437 Array has 3 duplicate keys with value 'december' ('december', 'december', 'december'). 27444 Array has 2 duplicate keys with value 'juni' ('juni', 'juni'). 27445 Array has 2 duplicate keys with value 'juli' ('juli', 'juli'). 27448 Array has 2 duplicate keys with value 'oktober' ('oktober', 'oktober'). 27456 Array has 2 duplicate keys with value 'mai' ('mai', 'mai'). 27462 Array has 2 duplicate keys with value 'novembre' ('novembre', 'novembre'). 27492 Array has 2 duplicate keys with value 'marzo' ('marzo', 'marzo'). 27497 Array has 2 duplicate keys with value 'agosto' ('agosto', 'agosto'). 27593 Array has 2 duplicate keys with value 'GST' ('GST', 'GST'). 27657 Parameter $callback of method SimplePie_Parse_Date::add_callback() has invalid type callback. 27678 PHPDoc tag @param references unknown parameter: $data 29256 Default value of the parameter #3 $end (false) of method Text_Diff_Engine_shell::_getLines() is incompatible with type int. 29637 Parameter $p of method AtomParser::map_xmlns() has invalid type indexish. 29738 Constant UNDEFINED not found. 29740 Constant UNDEFINED not found. 29742 Constant UNDEFINED not found. 29744 Constant UNDEFINED not found. 29758 Method Avifinfo\Features::get_primary_item_features() has invalid return type Avifinfo\Status. 29783 Constant MAX_SIZE not found. 29783 Method Avifinfo\Box::parse() has invalid return type Avifinfo\Status. 29783 Parameter $handle of method Avifinfo\Box::parse() has invalid type Avifinfo\stream. 30993 Default value of the parameter #1 $args ('') of method WP_Ajax_Response::add() is incompatible with type array{what?: string, action?: string|false, id?: int|WP_Error, old_id?: int|false, position?: string, data?: string|WP_Error, supplemental?: array}. 31293 Parameter $source_properties of method WP_Block_Bindings_Registry::register() has invalid type callback. 33180 Property WP_Block::$inner_blocks (WP_Block_List) does not accept default value of type array. 33320 Property WP_Comment_Query::$meta_query (WP_Meta_Query) does not accept default value of type false. 33350 Property WP_Comment_Query::$date_query (WP_Date_Query) does not accept default value of type false. 33587 Default value of the parameter #1 $query ('') of method WP_Comment_Query::__construct() is incompatible with type array{author_email?: string, author_url?: string, author__in?: array, author__not_in?: array, comment__in?: array, comment__not_in?: array, count?: bool, date_query?: array, ...}. 33646 Default value of the parameter #1 $query ('') of method WP_Comment_Query::parse_query() is incompatible with type array{author_email?: string, author_url?: string, author__in?: array, author__not_in?: array, comment__in?: array, comment__not_in?: array, count?: bool, date_query?: array, ...}. 33774 Property WP_Comment::$comment_post_ID (string) does not accept default value of type int. 33832 Property WP_Comment::$comment_karma (string) does not accept default value of type int. 33863 Property WP_Comment::$comment_parent (string) does not accept default value of type int. 33872 Property WP_Comment::$user_id (string) does not accept default value of type int. 34161 Property WP_Customize_Control::$active_callback (callable(): mixed) does not accept default value of type ''. 36341 Property WP_Customize_Panel::$theme_supports (array) does not accept default value of type string. 36389 Property WP_Customize_Panel::$active_callback (callable(): mixed) does not accept default value of type ''. 36666 Property WP_Customize_Section::$active_callback (callable(): mixed) does not accept default value of type ''. 36897 Property WP_Customize_Setting::$validate_callback (callable(): mixed) does not accept default value of type ''. 36904 Property WP_Customize_Setting::$sanitize_callback (callable(): mixed) does not accept default value of type ''. 36911 Property WP_Customize_Setting::$sanitize_js_callback (callable(): mixed) does not accept default value of type ''. 40943 Return type (WpOrg\Requests\Utility\CaseInsensitiveDictionary) of method WP_HTTP_Requests_Response::get_headers() should be compatible with return type (array) of method WP_HTTP_Response::get_headers() 41016 Class WP_Http_Cookie referenced with incorrect case: WP_HTTP_Cookie. 41895 Property WP_Image_Editor_GD::$image has unknown class GdImage as its type. 41940 Default value of the parameter #1 $width (false) of method WP_Image_Editor_GD::update_size() is incompatible with type int. 41940 Default value of the parameter #2 $height (false) of method WP_Image_Editor_GD::update_size() is incompatible with type int. 41989 Method WP_Image_Editor_GD::_resize() has invalid return type GdImage. 42152 Parameter $image of method WP_Image_Editor_GD::_save() has invalid type GdImage. 43296 Default value of the parameter #1 $meta_query (false) of method WP_Meta_Query::__construct() is incompatible with type array. 43796 Default value of the parameter #1 $query ('') of method WP_Network_Query::__construct() is incompatible with type array{network__in?: array, network__not_in?: array, count?: bool, fields?: string, number?: int, offset?: int, no_found_rows?: bool, orderby?: array|string, ...}. 43825 Default value of the parameter #1 $query ('') of method WP_Network_Query::parse_query() is incompatible with type array{network__in?: array, network__not_in?: array, count?: bool, fields?: string, number?: int, offset?: int, no_found_rows?: bool, orderby?: array|string, ...}. 44550 Default value of the parameter #2 $args ('') of method WP_oEmbed::get_provider() is incompatible with type array{discover?: bool}. 44609 Default value of the parameter #2 $args ('') of method WP_oEmbed::get_data() is incompatible with type array{width?: int|string, height?: int|string, discover?: bool}. 44631 Default value of the parameter #2 $args ('') of method WP_oEmbed::get_html() is incompatible with type array{width?: int|string, height?: int|string, discover?: bool}. 44661 Default value of the parameter #3 $args ('') of method WP_oEmbed::fetch() is incompatible with type array{width?: int|string, height?: int|string, discover?: bool}. 45841 Property WP_Post::$post_author (string) does not accept default value of type int. 45990 Property WP_Post::$comment_count (string) does not accept default value of type int. 46112 Property WP_Query::$meta_query (WP_Meta_Query) does not accept default value of type false. 46119 Property WP_Query::$date_query (WP_Date_Query) does not accept default value of type false. 46721 Default value of the parameter #1 $query ('') of method WP_Query::parse_query() is incompatible with type array{attachment_id?: int, author?: int|string, author_name?: string, author__in?: array, author__not_in?: array, cache_results?: bool, cat?: int|string, category__and?: array, ...}. 48556 Constant EP_NONE not found. 50061 Property WP_Site_Query::$meta_query (WP_Meta_Query) does not accept default value of type false. 50075 Property WP_Site_Query::$date_query (WP_Date_Query) does not accept default value of type false. 50233 Default value of the parameter #1 $query ('') of method WP_Site_Query::__construct() is incompatible with type array{site__in?: array, site__not_in?: array, count?: bool, date_query?: array, fields?: string, ID?: int, number?: int, offset?: int, ...}. 50286 Default value of the parameter #1 $query ('') of method WP_Site_Query::parse_query() is incompatible with type array{site__in?: array, site__not_in?: array, count?: bool, date_query?: array, fields?: string, ID?: int, number?: int, offset?: int, ...}. 51456 Property WP_Term_Query::$meta_query (WP_Meta_Query) does not accept default value of type false. 51643 Default value of the parameter #1 $query ('') of method WP_Term_Query::__construct() is incompatible with type array{taxonomy?: array|string, object_ids?: array|int, orderby?: string, order?: string, hide_empty?: bool|int, include?: array|string, exclude?: array|string, exclude_tree?: array|string, ...}. 51689 Default value of the parameter #1 $query ('') of method WP_Term_Query::parse_query() is incompatible with type array{taxonomy?: array|string, object_ids?: array|int, orderby?: string, order?: string, hide_empty?: bool|int, include?: array|string, exclude?: array|string, exclude_tree?: array|string, ...}. 51879 Property WP_Term::$term_group (int) does not accept default value of type string. 52081 Property WP_Text_Diff_Renderer_Table::$_show_split_view (string) does not accept default value of type true. 54832 Property WP_User_Query::$meta_query (WP_Meta_Query) does not accept default value of type false. 55448 Default value of the parameter #3 $site_id (string) of method WP_User::__construct() is incompatible with type int. 55459 Default value of the parameter #2 $site_id (string) of method WP_User::init() is incompatible with type int. 55774 Default value of the parameter #1 $blog_id (string) of method WP_User::for_blog() is incompatible with type int. 55786 Default value of the parameter #1 $site_id (string) of method WP_User::for_site() is incompatible with type int. 61950 PHPDoc type array of property WP_Customize_Nav_Menu_Item_Setting::$default is not covariant with PHPDoc type string of overridden property WP_Customize_Setting::$default. 62216 Return type (void) of method WP_Customize_Nav_Menu_Item_Setting::update() should be compatible with return type (bool) of method WP_Customize_Setting::update() 62439 PHPDoc type array of property WP_Customize_Nav_Menu_Setting::$default is not covariant with PHPDoc type string of overridden property WP_Customize_Setting::$default. 62670 Return type (void) of method WP_Customize_Nav_Menu_Setting::update() should be compatible with return type (bool) of method WP_Customize_Setting::update() 62914 Property WP_Customize_Partial::$id_data (array{base: string, keys: array}) does not accept default value of type array{}. πŸ’‘ Array does not have offset 'base'. 64727 PHPDoc tag @var has invalid value ([string, array]|null): Unexpected token "]", expected '(' at offset 251 67175 PHPDoc tag @phpstan-param has invalid value (array{0: string, 1: string}{ 0: string, 1: string, } $plurals): Unexpected token "{", expected variable at offset 995 68046 Return type (string) of method MO::select_plural_form() should be compatible with return type (int) of method Translations::select_plural_form() 69240 PHPDoc tag @phpstan-param has invalid value (@param key-of $offset): Unexpected token "@param", expected type at offset 220 71204 PHPDoc type false of property WP_REST_Attachments_Controller::$allow_batch is not covariant with PHPDoc type array of overridden property WP_REST_Posts_Controller::$allow_batch. 72902 PHPDoc type false of property WP_REST_Font_Faces_Controller::$allow_batch is not covariant with PHPDoc type array of overridden property WP_REST_Posts_Controller::$allow_batch. 73174 PHPDoc type false of property WP_REST_Font_Families_Controller::$allow_batch is not covariant with PHPDoc type array of overridden property WP_REST_Posts_Controller::$allow_batch. 81352 PHPDoc tag @param has invalid value (binary string $input Must be at least $num_bytes-long.): Unexpected token "string", expected variable at offset 99 81362 Function Avifinfo\read() has invalid return type Avifinfo\binary. 81362 Parameter $handle of function Avifinfo\read() has invalid type Avifinfo\stream. 81373 Parameter $handle of function Avifinfo\skip() has invalid type Avifinfo\stream. 96859 PHPDoc tag @throws with type WP_Error is not subtype of Throwable 97171 PHPDoc tag @throws with type WP_Error is not subtype of Throwable 97215 PHPDoc tag @throws with type WP_Error is not subtype of Throwable 97360 PHPDoc tag @throws with type WP_Error is not subtype of Throwable ```

Strange things like docblock for translate_plural and WP_REST_Request::offsetExists.

Config for generating these errors.

parameters:
    paths:
        - wordpress-stubs.php
    level: 5
    ignoreErrors:
        - '#but return statement is missing\.$#'
        - '#has an unused parameter#'
        - '#^(Property|Static property|Method|Static method) \S+ is unused\.$#'
        - '#is never read, only written\.$#'
        - '#has invalid (return )?type (WP_Error|WP_Customize_Manager)\.#'
        - '#should always throw an exception or terminate script execution but doesn.t do that\.$#'
swissspidy commented 3 months ago

Many of those can probably be easily fixed in core. cc @johnbillion

herndlm commented 3 months ago

I don't fully understand. You're scanning the stubs file in the extension repo? Or should this go to the stubs repo? Why even scanning them with PHPStan? πŸ˜…

szepeviktor commented 3 months ago

Why even scanning them with PHPStan? πŸ˜…

Please see the results!

herndlm commented 3 months ago

πŸ™ˆ

IanDelMar commented 3 months ago

Can we have a list of those errors to check off the ones we won't address and those we have addressed once a fix is merged?

szepeviktor commented 3 months ago

Can we have a list of those errors

a PHPStan baseline file??

IanDelMar commented 3 months ago

Something like this

herndlm commented 3 months ago

But I think the baseline approach might be an interesting idea to look into. Maybe with a dedicated phpstan config just for stub checks as you have it here?

johnbillion commented 3 months ago

I think this is best addressed in WordPress core. A few of these have been reported already across a few tickets. See https://core.trac.wordpress.org/search?ticket=on&q=phpstan .

szepeviktor commented 3 months ago

To please Ian

IanDelMar commented 3 months ago

Someone has smuggled in an array shape for WP_Translation_Controller::translate_plural(). Unfortunately, the shape is accompanied by the WordPress @type notation. https://github.com/WordPress/WordPress/blob/9702c2e265bd3aff0522f55063d97ca21cc70099/wp-includes/l10n/class-wp-translation-controller.php#L285-L290

I guess this should be fixed in core as well.

szepeviktor commented 3 months ago

@swissspidy Could you evaluate this? Someone === Pascal? πŸ™ƒ

swissspidy commented 3 months ago

Sure! WP_Translation_Controller::translate_plural is fixed in https://core.trac.wordpress.org/changeset/58155

swissspidy commented 5 days ago

Whatβ€˜s left to be done here? Anything weβ€˜d need to fix in core? :)

szepeviktor commented 5 days ago

Nothing.