Opened 7 months ago
Last modified 7 weeks ago
#63268 accepted task (blessed)
PHPStan code quality improvements for 6.9
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 6.9 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | General | Keywords: | has-patch |
| Focuses: | coding-standards | Cc: |
Description (last modified by )
Change History (182)
This ticket was mentioned in PR #8680 on WordPress/wordpress-develop by @justlevine.
7 months ago
#2
- Keywords has-patch added
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This PR fixes the parameter doc-type on WP_REST_Server::get_index()'s $request param to be a WP_REST_Request instead of an array.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
This ticket was mentioned in PR #8681 on WordPress/wordpress-develop by @justlevine.
7 months ago
#3
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This PR updates _wp_filter_build_unique_id() to explicitly return null if the function isn't passed a valid $callback. This is instead of the current behavior where the function can return void, but is typed as only returning a string.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
#4
@
7 months ago
- Description modified (diff)
- Focuses coding-standards added
- Milestone changed from Awaiting Review to 6.9
- Owner set to SergeyBiryukov
- Status changed from new to accepted
This ticket was mentioned in PR #8384 on WordPress/wordpress-develop by @justlevine.
7 months ago
#5
This PR fixes the default $post ID param values used in several functions in wp-includes/link-template.php, to bring them in line with their int doctypes (and the doctypes of their internal function calls).
More specifically,
get_page_link():$post = falsechanged to$post = 0_get_page_link():$post = falsechanged to$post = 0post_comments_feed_link():$post_id = ''changed to$post_id = 0
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8385 on WordPress/wordpress-develop by @justlevine.
7 months ago
#6
This PR updates the @param types on get_comments_number_text() to correctly reflect the default false parameter.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8386 on WordPress/wordpress-develop by @justlevine.
7 months ago
#7
This PR fixes the doc-block for rest_menu_read_access, where the third param name is incorrectly named $this, which is an illegal parameter name.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8387 on WordPress/wordpress-develop by @justlevine.
7 months ago
#8
This PR fixes the default $site_id parameter value used throughout WP_User to correctly match the (int) doctypes, and the doctypes of the functions they use internally.
Specifically:
__construct():$site_id = ''is now$site_id = 0init():$site_id = ''is now$site_id = 0for_blog():$blog_id = ''is now$blog_id = 0for_site():$site_id= ''is now$site_id = 0
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8388 on WordPress/wordpress-develop by @justlevine.
7 months ago
#9
This PR fixes an issue in wp_xmlrpc_server::wp_deleteTerm() doesn't correctly return the WP_Error message from the wp_delete_term() attempt.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8389 on WordPress/wordpress-develop by @justlevine.
7 months ago
#10
This PR fixes the WP_Meta_Query constructor arg, to take a default value of array(), as specified by the doc-block @param .
Since the function is gated with a loose, falsy ! $meta_query check, there is no difference to function behavior.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8390 on WordPress/wordpress-develop by @justlevine.
7 months ago
#11
This PR updates the @return type for _wp_get_current_user() to correctly reflect that it can return a null value if no user is logged in.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #7720 on WordPress/wordpress-develop by @justlevine.
7 months ago
#12
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This PR fixes an issue in get_taxonomy_labels(), where the template_name was accessed as an object property on $tax->labels instead of as an array property.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
@SergeyBiryukov commented on PR #8384:
7 months ago
#14
Thanks for the PR! Merged in r60152.
This ticket was mentioned in PR #8682 on WordPress/wordpress-develop by @justlevine.
7 months ago
#15
This PR fixes a bug in WP_Debug_Data::get_wp_themes_inactive(), where the update_themes site $transient was not defined before being checked in several isset() checks later on in the function (L1359).
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8683 on WordPress/wordpress-develop by @justlevine.
7 months ago
#16
This PR updates wp_get_nav_menu_to_edit() to explicitly return null and adds null to the function's return type. This is instead of the existing behavior where the implict void return is not typehinted.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
@SergeyBiryukov commented on PR #8385:
7 months ago
#18
Thanks for the PR! Merged in r60166.
@SergeyBiryukov commented on PR #8386:
7 months ago
#20
Thanks for the PR! Merged in r60172.
@SergeyBiryukov commented on PR #8387:
7 months ago
#22
Thanks for the PR! Merged in r60174.
@SergeyBiryukov commented on PR #8388:
7 months ago
#24
Thanks for the PR! Merged in r60175.
@SergeyBiryukov commented on PR #8389:
7 months ago
#26
Thanks for the PR! Merged in r60176.
@SergeyBiryukov commented on PR #8680:
7 months ago
#28
Thanks for the PR! Merged in r60177.
@SergeyBiryukov commented on PR #8681:
7 months ago
#30
Thanks for the PR! Merged in r60179.
@SergeyBiryukov commented on PR #8683:
6 months ago
#32
Thanks for the PR! Merged in r60180.
@SergeyBiryukov commented on PR #8682:
6 months ago
#34
Thanks for the PR! Merged in r60181.
@justlevine commented on PR #7720:
6 months ago
#35
On further investigation, this is invalid, and labels is indeed reconverted back to an object.
@johnbillion commented on PR #8390:
6 months ago
#37
@justlevine Are you sure this function can return null? When a user isn't logged in, this function calls wp_set_current_user(0) which sets the $current_user global to an instance of WP_User with an ID of 0. This is what gets returned by _wp_set_current_user().
@justlevine commented on PR #8390:
6 months ago
#38
@justlevine Are you sure this function can return
null? When a user isn't logged in, this function callswp_set_current_user(0)which sets the$current_userglobal to an instance ofWP_Userwith an ID of0. This is what gets returned by_wp_set_current_user().
Nope, you're right 😅 Thanks for catching that @johnbillion !
This ticket was mentioned in PR #8859 on WordPress/wordpress-develop by @justlevine.
5 months ago
#39
This PR removes a needless empty( $object_terms ) check from inside is_object_in_term(). If $object_terms is empty, the immediately-preceding code-block causes the function to return early.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8860 on WordPress/wordpress-develop by @justlevine.
5 months ago
#40
This PR improves the type safety around WP_Screen in the following ways:
- Correctly hint that
WP_Screen::$_show_screen_optionsis null before instantiated. - Correctly hint that
::get_option(),get_help_tab()andget_screen_reader_text()can return null. - Ensure
$this->columnsis anint, by casting$this->get_option( 'layout_columns', 'default' )from its numeric string.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8861 on WordPress/wordpress-develop by @justlevine.
5 months ago
#41
This is needed because category_exists() returns a numeric string
This PR fixes wp_create_category() to return an int as defined in the DocBlock, instead of the numeric-string returned by category_exists().
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8862 on WordPress/wordpress-develop by @justlevine.
5 months ago
#42
This PR updates the PHPDoc type for WP_List_Table::$_column_headers to correctly indicate it's null until ::get_column_info() is called.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8863 on WordPress/wordpress-develop by @justlevine.
5 months ago
#43
This PR fixes the casing of the get_current_user_id() call in script-loader.php. Previously it was being incorrectly referenced as get_current_user_ID() (last letters uppercased).
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8864 on WordPress/wordpress-develop by @justlevine.
5 months ago
#44
$old_user_data is set if ! update on L2213
This PR removes an unnecessary empty( $old_user_data ) check from wp_insert_user(). The $old_user_data variable is defined alongside $update, so by checking for one, we've already narrowed the type for the other.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8865 on WordPress/wordpress-develop by @justlevine.
5 months ago
#45
This PR fixes an issue in WP_REST_Attachments_Controller::update_item(), where the $schema['properties'] are checked for featured media, but is only defined in the parent method and not where it is currently used.
Follow up to: https://core.trac.wordpress.org/ticket/41692
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8866 on WordPress/wordpress-develop by @justlevine.
5 months ago
#46
This PR removes an unnecessary empty( $modes_str ) check from wpdb::set_sql_mode(), as the previous code block already checks and returns early:
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8867 on WordPress/wordpress-develop by @justlevine.
5 months ago
#47
This PR removes an unncessary empty( $status_clauses ) from WP_Comment_Query::get_comment_ids(). The preceeding foreach loop ensures that $status_clauses is a non-empty array.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
@justlevine commented on PR #8865:
5 months ago
#48
Im not sure I understand the failing test case . _Shouldnt_ a fake attachment with an ID of 0 throw a 400?
This ticket was mentioned in PR #8868 on WordPress/wordpress-develop by @justlevine.
5 months ago
#49
This PR removes two unnecessary empty( $object_subtype ) checks from map_meta_cap(), as it causes the currently case to break in the conditional preceding this one:
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8869 on WordPress/wordpress-develop by @justlevine.
5 months ago
#50
This PR fixes two calls to WP_Theme::get() that were previously incorrectly called as ::Get() (with a capital G).
In:
- WP_Language_Pack_Upgrader::get_name_for_update()
- WP_Automatic_Updater::update()
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8870 on WordPress/wordpress-develop by @justlevine.
5 months ago
#51
This PR fixes two calls to ftp_base::SetTimeout() that were incorrectly called as ::setTimeout() (lowercase s), in WP_Filesystem_ftpsockets::connect()
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8871 on WordPress/wordpress-develop by @justlevine.
5 months ago
#52
This PR fixes the casing of calls to PHPMailer::addCC (from ::addCc - lowercase c ) and PHPMailer::addBCC (from ::addBcc, - lowercase cc ) in wp_mail().
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8872 on WordPress/wordpress-develop by @justlevine.
5 months ago
#53
This PR fixes two attempts to use the results of base_convert() in a binaryOp without first converting the results to an integer.
In
add_menu_page()WP_Duotone::colord_parse_hex()
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8873 on WordPress/wordpress-develop by @justlevine.
5 months ago
#54
This PR updates WP_REST_Comments_Controller::get_items() to cast the values of $total_comments and $max_pages to string types before they are set on the response headers.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8874 on WordPress/wordpress-develop by @justlevine.
5 months ago
#55
This PR fixes the @return annotation for the get_registered() methods in the following classes to correctly indicate they can return null if no item is registered:
WP_Block_Pattern_Categories_Registry::get_registered()WP_Block_Patterns_Registry::get_registered()WP_Block_Styles_Registry::get_registered()
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8875 on WordPress/wordpress-develop by @justlevine.
5 months ago
#56
This PR updates get_the_block_template_html() to return an empty string ('') if no template is found and the user is not logged in. This is instead of the current behavior of returning void (coerced to null ).
This is inline with both the function DocBlock and how the function is used throughout the codebase, and thus less disruptive than explicitly returning null and then casting the results back to an empty string wherever it's used.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8876 on WordPress/wordpress-develop by @justlevine.
5 months ago
#57
This PR updates default_topic_count_scale() to return an int (per documentation and usage) instead of the type float returned by `round()`
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8878 on WordPress/wordpress-develop by @justlevine.
5 months ago
#58
…gories()`
This PR updates the $post_id param's default value in wp_create_categories from an empty string to a 0 - inline with both the expected doc-type and how it's used.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8879 on WordPress/wordpress-develop by @justlevine.
5 months ago
#59
This PR updates the $post_id param default value in redirect_post() from an empty string to 0, inline with both the doc-type and the usage of that default value internally.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8880 on WordPress/wordpress-develop by @justlevine.
5 months ago
#60
This PR fixes the doc-block on wp_update_attachment_metadata() to correctly return type bool.
The type seems to have been accidentally narrowed in https://github.com/WordPress/wordpress-develop/commit/679ccc35e63e62a90c768afcc16f46bd154dfb65, but both update_post_meta() and delete_post_meta() return true|false in this case.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8881 on WordPress/wordpress-develop by @justlevine.
5 months ago
#61
This PR fixes get_the_author_posts() so it correctly returns an int instead of a numeric string, per its doc-block and how it's used.
Additional the doc-block for the get_usernumposts filter has been updated to correctly indicate that $count is indeed a string.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
@johnbillion commented on PR #8880:
5 months ago
#62
update_post_meta() returns an int if the meta key didn't previously exist. So I think the return type needs to be bool|int.
@johnbillion commented on PR #8869:
5 months ago
#64
@johnbillion commented on PR #8870:
5 months ago
#65
@johnbillion commented on PR #8871:
5 months ago
#66
@johnbillion commented on PR #8874:
5 months ago
#67
@johnbillion commented on PR #8875:
5 months ago
#68
@johnbillion commented on PR #8876:
5 months ago
#69
@johnbillion commented on PR #8878:
5 months ago
#70
@johnbillion commented on PR #8879:
5 months ago
#71
@johnbillion commented on PR #8880:
5 months ago
#72
update_post_meta() returns an int if the meta key didn't previously exist. So I think the return type needs to be bool|int.
@SergeyBiryukov commented on PR #8859:
5 months ago
#74
Thanks for the PR! Merged in r60282.
@SergeyBiryukov commented on PR #8863:
5 months ago
#75
Thanks for the PR! This was merged in r60275.
@SergeyBiryukov commented on PR #8867:
5 months ago
#77
Thanks for the PR! Merged in r60291.
@SergeyBiryukov commented on PR #8862:
5 months ago
#79
Thanks for the PR! Merged in r60292.
@SergeyBiryukov commented on PR #8868:
5 months ago
#81
Thanks for the PR! Merged in r60294.
@justlevine commented on PR #8880:
5 months ago
#82
Thanks @johnbillion ! Updated the type and the description so it's clear just how unhelpful the return value is
This ticket was mentioned in PR #8944 on WordPress/wordpress-develop by @justlevine.
5 months ago
#84
This PR adds a doc-block to the _() function in compat.php.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8945 on WordPress/wordpress-develop by @justlevine.
5 months ago
#85
This PR fixes the return type on WP_HTML_Decoder::read_character_reference() to correctly indicate that it returns a _nullable_ string, and not string|false.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8946 on WordPress/wordpress-develop by @justlevine.
5 months ago
#86
This PR fixes the return type on WP_Speculation_Rules::jsonSerialize() to show that it returns an array<string, mixed[]> instead of the internal array having a string key. This is due to the method's use of array_values() to intentionally strip any keys.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
@justlevine commented on PR #8946:
5 months ago
#87
Not sure if this warrants a 6.8.x commit, but I definitely don't think it's worth bothering to create a Trac ticket just to make that happen.
This ticket was mentioned in PR #8947 on WordPress/wordpress-develop by @justlevine.
5 months ago
#88
This PR fixes the PHPDoc property type of WP_Tax_Query::$no_results to correctly indicate that it's an array, not a string.
As a private property, changing this doc-type should cause no doctype conflicts with classes extending WP_Tax_Query.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8948 on WordPress/wordpress-develop by @justlevine.
5 months ago
#89
This PR updates WP_Term_Query::get_terms() to return a numeric-string '0' instead of an in 0 when a 'count' is requested in $args['fields'] and no terms exist.
This aligns the behavior with the existing PHPDoc return type (and what's used by phpstub's map), and also aligns better with expectations. The risk of somebody "building around the quirk" and strict-checking 0 === WP_Term_Query::get_terms() in their code should be minimal.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8949 on WordPress/wordpress-develop by @justlevine.
5 months ago
#90
This PR fixes some param/return type issues in comment.php concerning arrays. More specifically:
separate_comments()now correctly indicates that it returns an array ofWP_Commentarrays, keyed by theirstringtypes._close_comments_for_old_postsnow correctly indicates that it takes an array ofWP_Post, and returns an array ofWP_Post.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8950 on WordPress/wordpress-develop by @justlevine.
5 months ago
#91
This PR updates the docs for wp_filter_oembed_result() to correctly indicate that it both take and return a string|false $result. The $result param hint for the oembed_dataparse filter has been similarly corrected.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8951 on WordPress/wordpress-develop by @justlevine.
5 months ago
#92
…eprecated`
This PR updated WP_Image_Editor_Imagick::set_imagick_time_limit() to use the @deprecated tag, instead of hiding it in a @since tag. This allows tooling and IDEs to warn developers if they are using the deprecated method.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8952 on WordPress/wordpress-develop by @justlevine.
5 months ago
#93
This PR removes several unnecessary isset() calls from the codebase:
- In
_get_block_template_files():$areais proven set by the left side of the conditional. - In
Custom_Image_Header::step_2(): The only path where$oitarisnt set, returns early on L898 https://github.com/justlevine/wordpress-develop/blob/c043bcf2bb34a4e16ac8021a3de0f27de4670f91/src/wp-admin/includes/class-custom-image-header.php#L898 - In
get_calendar():$newrowis defined right before thefor()loop, and the loop only toggles its value between true|false. - In
wp-admin/post.php:wp_die()is called if the$post_type_objectis falsy on https://github.com/justlevine/wordpress-develop/blob/c043bcf2bb34a4e16ac8021a3de0f27de4670f91/src/wp-admin/post.php#L131 - In
wp_delete_term(): the top of theforeach()loop alreadycontinues early if$defaultisnt set on https://github.com/justlevine/wordpress-develop/blob/c043bcf2bb34a4e16ac8021a3de0f27de4670f91/src/wp-includes/taxonomy.php#L2132-L2135
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8953 on WordPress/wordpress-develop by @justlevine.
5 months ago
#94
This PR updates various @var tags on class properties to correctly indicate that they props may be null|unset:
WP_Dependencies::$all_queued_depsis nullable by both::enqueue()and::dequeue.WP_Duotone::$global_styles_presetsand::$global_styles_block_namesstart off unset and are only initialized by static classes.WP_Query::init()andWP_Rewrite::init()are public methods thatunset()s many class props.WP_Theme::cache_delete()sets many props tonull.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8955 on WordPress/wordpress-develop by @justlevine.
5 months ago
#95
This PR updates several functions to explicitly return null in accordance to their existing doc-types, instead of using a void return;.
Affected functions:
get_comment_reply_link()get_page_of_comment()get_edit_term_link()get_preview_post_link()get_edit_post_link()wp_set_all_user_settings()get_page_by_path()save_mod_rewrite_rules()
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8956 on WordPress/wordpress-develop by @justlevine.
5 months ago
#96
This PR removes an unreachable break; from the 'allblogs' -> 'delete' case in wp-admin/network/sites.php, as the line before exits entirely.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8957 on WordPress/wordpress-develop by @justlevine.
5 months ago
#97
This PR updates to remove an unreachable return $new_template_item; statement from _get_block_template_file(), as $template_type will bail at the top of the function( https://github.com/justlevine/wordpress-develop/blob/ae2dd43b83c6a985ebd7ecf07ba03d3a19c53ca0/src/wp-includes/block-template-utils.php#L324-L326) if it's not a wp_template or wp_template_part.
For the same reasons, the second if() was also redundant and able to be removed.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8958 on WordPress/wordpress-develop by @justlevine.
5 months ago
#98
This PR removes an unnecessary empty( $connection_type ) from inside request_filesystem_credentials(), as the left-side of the same conditional ( 'ssh' !== $connection_type ) will already catch a possibly empty value.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8959 on WordPress/wordpress-develop by @justlevine.
5 months ago
#99
This PR removes an unnecessary is_wp_error() check from wp_authenticate_application_password(), as the \WP_Error instance is created earlier in the method, and the only mutability are whether the instance actually ->has_errors().
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
@SergeyBiryukov commented on PR #8881:
5 months ago
#101
This ticket was mentioned in Slack in #core by justlevine. View the logs.
5 months ago
@johnbillion commented on PR #8880:
5 months ago
#104
@johnbillion commented on PR #8956:
5 months ago
#106
I believe this is a stylistic choice, so every case always has a break unless it intends to fall through. Whether or not that's documented or enforced in the coding standards I am not sure.
@justlevine commented on PR #8956:
5 months ago
#107
Whether or not that's documented or enforced in the coding standards I am not sure.
It's a PHPStan level-4 violation, so while there's there's no tooling-related urge to merge this, whoever is advocating the stylistic argument should keep in mind that once we hit that level this will look like:
...
require_once ABSPATH . 'wp-admin/admin-footer.php';
exit;
break; // @phpstan-ignore deadCode.unreachable (Optional comment about how this was a stylistic choice )
case 'spam':
...
PS: there are _other_ parts of the codebase where a custom $this->exits(); will need a break; to prevent WPCS from reformatting the subsequent case statements. That's not the case here and won't be needed elsewhere either once PHPStan (annotations) are merged, and we can start using the @never type to indicate an exit.
@SergeyBiryukov commented on PR #8951:
5 months ago
#108
Thanks for the PR! Merged in r60303.
@SergeyBiryukov commented on PR #8950:
5 months ago
#110
Thanks for the PR! Merged in r60307.
@SergeyBiryukov commented on PR #8958:
5 months ago
#112
Thanks for the PR! Merged in r60309.
@SergeyBiryukov commented on PR #8959:
5 months ago
#114
Thanks for the PR! Merged in r60310.
This ticket was mentioned in Slack in #core by justlevine. View the logs.
5 months ago
#116
@
5 months ago
If you need more inspiration for some functions that could use some improved types: https://github.com/szepeviktor/phpstan-wordpress/issues/274
@SergeyBiryukov commented on PR #8947:
5 months ago
#118
Thanks for the PR! Merged in r60311.
@SergeyBiryukov commented on PR #8944:
5 months ago
#120
Thanks for the PR! Merged in r60312.
@SergeyBiryukov commented on PR #8957:
5 months ago
#122
Thanks for the PR! Merged in r60328.
@SergeyBiryukov commented on PR #8949:
5 months ago
#124
Thanks for the PR! Merged in r60330.
@SergeyBiryukov commented on PR #8952:
4 months ago
#130
This ticket was mentioned in PR #9109 on WordPress/wordpress-develop by @justlevine.
4 months ago
#133
This PR fixes the DocBlock return type for _oembed_rest_pre_serve_request() to correctly indicate that it can return _any_ bool value and not just true.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9110 on WordPress/wordpress-develop by @justlevine.
4 months ago
#134
This PR removes an unnecessary conditional from inside do_trackbacks(), as a falsey $to_ping causes the function to return early when the variable is defined (L3053 as of writing)ץ
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9111 on WordPress/wordpress-develop by @justlevine.
4 months ago
#135
It's the entrypoint into this codeblock two lines above
This PR removes unnecessary checks for $cpage inside get_comment_link(), where its truthiness is a pre-requisite for entering the code block (L835)
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9112 on WordPress/wordpress-develop by @justlevine.
4 months ago
#136
This PR removes an unreachable early continue from WP_Theme_JSON::get_block_nodes(). The $include_node_paths_only` variable is used to early-continue on L2784, preventing this one from ever being reached.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9113 on WordPress/wordpress-develop by @justlevine.
4 months ago
#137
This PR removes an always-true conditional check from WP_Customize_Manager::handle_changeset_trash_request(). $changeset_post_id early-returns if false right before this codeblock on L3165
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9114 on WordPress/wordpress-develop by @justlevine.
4 months ago
#138
This PR removes an unnecessary check for ! $enable inside WP_Upgrader:maintenance_mode(). The first part of the block checks if $enable is truthy, so it is always false in the elseif()`.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9115 on WordPress/wordpress-develop by @justlevine.
4 months ago
#139
This PR removes a needless if ( ! $add_new_screen ){} conditional wrapper from inside wp-admin/nav-menus.php. That variable is already checked and falsey on L1107 and is a prerequisite for reaching this code.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9116 on WordPress/wordpress-develop by @justlevine.
4 months ago
#140
This PR removes an unnecessary null !== $args['taxonomy] check inside get_terms(), as the same conditional already calls isset( $args['taxonomy'] ), which checks for explicit nulls.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9117 on WordPress/wordpress-develop by @justlevine.
4 months ago
#141
This PR removes two unnecessary conditional checks from within wp_resolve_numeric_slug_conflicts():
- a truthy check for
$compare, when a falsey$comparecauses an earlier return on the preceeding codeblock (L409) - A check to ensure
$maybe_pageisn't an empty string, when$maybe_pageis already cast to anint(L448).
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9118 on WordPress/wordpress-develop by @justlevine.
4 months ago
#142
This PR removes an always-true check for elseif ( is_multisite() ...) within delete_expired_transients(), where the preceding if() is for ! is_multisite().
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9120 on WordPress/wordpress-develop by @justlevine.
4 months ago
#143
…
This PR removes an unnecessary is_object( $user ) call from inside wpmu_validate_blog_signup() (the condition before the || is that it is ! is_object() ), and instead replaces it with a property_exists( 'user_login' ) check before an attempt is made to access that property.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9121 on WordPress/wordpress-develop by @justlevine.
4 months ago
#144
This PR removes an always-true check for false === $metadata from inside wp_get_theme_data_template_parts(), as a non-false value causes an early-return right before. To clarify this behavior the needless priming of $metadata = false; was removed as well, as there is no scenario where it will not be immediately overwritten.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9122 on WordPress/wordpress-develop by @justlevine.
4 months ago
#145
This PR removes an always-true check for $exif_description inside wp_read_image_metadata(). This logical branch is only reachable if $exif_description is truthy, above on L960.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #9123 on WordPress/wordpress-develop by @justlevine.
4 months ago
#146
This PR removes a needless check for $found_marker in insert_with_markers() from an elseif() that is preceeded by an if ( ! $found_marker ) check.
While this issue was surfaced via PHPStan in https://github.com/WordPress/wordpress-develop/pull/7619 (trac: https://core.trac.wordpress.org/ticket/61175 ), it can be remediated independently of that ticket.
Trac ticket: https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in Slack in #core by justlevine. View the logs.
4 months ago
@SergeyBiryukov commented on PR #9109:
4 months ago
#151
Thanks for the PR! Merged in r60401.
This ticket was mentioned in Slack in #core by audrasjb. View the logs.
4 months ago
@SergeyBiryukov commented on PR #9110:
4 months ago
#154
Thanks for the PR! Merged in r60406.
@SergeyBiryukov commented on PR #9111:
4 months ago
#156
Thanks for the PR! Merged in r60408.
@SergeyBiryukov commented on PR #9112:
4 months ago
#158
Thanks for the PR! Merged in r60409.
@SergeyBiryukov commented on PR #9113:
4 months ago
#160
Thanks for the PR! Merged in r60414.
@SergeyBiryukov commented on PR #9114:
4 months ago
#162
Thanks for the PR! Merged in r60417.
@SergeyBiryukov commented on PR #9115:
4 months ago
#164
Thanks for the PR! Merged in r60440.
@SergeyBiryukov commented on PR #9116:
4 months ago
#166
Thanks for the PR! Merged in r60445.
@SergeyBiryukov commented on PR #9117:
4 months ago
#167
Thanks for the PR! Merged in r60447.
@SergeyBiryukov commented on PR #9118:
4 months ago
#169
Thanks for the PR! Merged in r60448.
@SergeyBiryukov commented on PR #9120:
4 months ago
#171
Thanks for the PR! Merged in r60450.
For reference, it appears that the user_login property does not actually exist on the WP_User object, but is retrieved dynamically via ::__get(), so the property_exists() check didn't work as expected:
There was 1 failure:
1) Tests_Multisite_wpmuValidateBlogSignup::test_validate_blogname with data set #7 ('existinguserfoo', 'Site names must not collide w...login.')
Site names must not collide with an existing user login.
Failed asserting that an array contains 'blogname'.
I've adjusted the check to $user instanceof WP_User instead.
@SergeyBiryukov commented on PR #9121:
4 months ago
#173
Thanks for the PR! Merged in r60459.
@SergeyBiryukov commented on PR #9122:
4 months ago
#175
Thanks for the PR! Merged in r60475.
@SergeyBiryukov commented on PR #9123:
4 months ago
#177
Thanks for the PR! Merged in r60480.
@justlevine commented on PR #8873:
3 months ago
#178
Tests updated so they're comparing to a numeric-string instead of an int count.
#179
@
7 weeks ago
Can we edit the title of this (and future release tasks)
To: Static Analysis code quality improvements for X.Y ?
(Or whatever is more generalistic, not only improvements that come from PHPStan, but that could come from any static analysis tool, or any static analysis in general).
I know that PHPCS is also technically an Static Analysis tool, but we already have a Code Standards improvements for X.Y.
I think users will find it easier to write here than if this is exclusively dedicated to anything that comes from PHPStan specifically.
cc @SergeyBiryukov @westonruter @justlevine
#180
follow-up:
↓ 181
@
7 weeks ago
@SirLouen the original intention for this ticket was specifically to remediate PHPStan violations, in order to reduce the friction (via errors/baselines) needed to adopt PHPStan (https://core.trac.wordpress.org/ticket/61175), as well as track progress and the impact of using that tool to bolster the justifications in favor of adopting it.
As a contributor and not a committer, I'd love for there to *also* be "Code Quality" catch-all (versus a ticket to explicitly justify each change) that may anecdotally remove errors from the PHPStan baseline, but I'm hesitant to repurpose this one.
IMO "Code Quality" is a very subjective term if it's not tied to a specific tool. This ticket is AFAIK what's enabling @SergeyBiryukov , @johnbillion , et. al. to review and make iterative progress without needing to spend additional time/cognitive energy on triage. ("No unnecessary refactors" still applies, but since we're starting from a clear and defined list the scope of potential changes is limited. Nobody's gonna randomly go Liskoff or unnecessarily OOP a bunch of legacy code). Ultimately, I defer to both of them and whatever makes things easiest for them 🙇
I know that PHPCS is also technically an Static Analysis tool, but we already have a Code Standards improvements for X.Y.
To be unnecessarily pedantic, PHPCS is a _linting_ tool and not static analysis 😅 but still I think there too, it's the virtue of it being a tool with a specific ruleset + violation list that allows for relatively efficient triage.
- "Is PHPCS complaining?" > "Do we care that PHPCS is complaining?" > "How much do we care that PHPCS is complaining vs the effort/cost of a refactor"
is a lot easier than
- "is this subjective code pattern measurably better than that also subjective one?"
I think users will find it easier to write here than if this is exclusively dedicated to anything that comes from PHPStan specifically.
I would love to see other contributors take the | PHPStan baseline and start triaging/patching with me.
That baseline is the perfect list of good first issues: small, scoped, requiring minimal if any new Unit tests. Just need enough know-how to know what's "worth doing" and what's testing noise (e.g. the PHPCS equivalent of an invalid comment end char vs not sanitizing a var).
But maybe I'm being too optimistic?
#181
in reply to:
↑ 180
@
7 weeks ago
Replying to justlevine:
@SirLouen the original intention for this ticket was specifically to remediate PHPStan violations, in order to reduce the friction (via errors/baselines) needed to adopt PHPStan (https://core.trac.wordpress.org/ticket/61175), as well as track progress and the impact of using that tool to bolster the justifications in favor of adopting it.
Maybe a specific task should be set for this purpose. I have not fully set up the PHPStan with the baseline you added yet for my regular triage. But as I commented the other day, I don't even know if with this level, errors that are being spotted in the wild, would have been also spotted by PHPStan.
But we cannot restrict this to PHPStan violations, because they are strictly of the same nature. I don't agree that PHPStan violations are easier to triage (in fact we can be introducing bugs if we triage them too optimistically). They have to be triaged with the same carefulness as any other. Because PHPStan can miss more than a funfair shotgun.
To be unnecessarily pedantic, PHPCS is a _linting_ tool and not static analysis 😅 but still I think there too, it's the virtue of it being a tool with a specific ruleset + violation list that allows for relatively efficient triage.
PS: It appears that they don't agree. 🙊
#182
@
7 weeks ago
Maybe a specific task should be set for this purpose... But we cannot restrict this to PHPStan violations,
@SirLouen not sure I follow.
This ticket is the specific task set for triaging PHPStan issues. It was birthed as a request from https://core.trac.wordpress.org/ticket/52217#comment:112 which was also specific to PHPStan. (If I understood) you're suggesting that we rename and repurpose this ticket instead of opening up a new one to address broader "Code Quality" concerns. I'm suggesting a separate ticket can be created alongside this one (or after closing this one if that's what Sergey prefers, but until the PHPStan proposal is officially accepted there's value in keeping the history on this ticket specific and relevant).
don't agree that PHPStan violations are easier to triage
Easier to triage than what?
My argument wasn't specific to PHPStan, it's "having a scoped list of errors that need evaluation". We already agree that 1) PHPStan is a helpful tool and 2) just because PHPStan flags an error doesn't mean we should listen to it. Having that scope filters out any other (possibly justifiable, but still irrelevant here) topics so it's focused on answering "is this PHPStan error worth remediating or just noise", then as with any core workflow there's obviously still independent context and code review or the proposed remediation.
don't even know if with this level, errors that are being spotted in the wild
IIRC both on this ticket and on #52217 we caught some 6.8 regressions. If 6.9 is similar we'll see a good number from GB and new features once we hit beta1.
There's also the bugs that are hidden by less important PHPStan errors. For example, it can't alert you that about str_starts_with( $not_a_string, $also_not_a_string ) throwing a fatal error, if it's warning you that "The PHPDoc for $not_a_string says string|null, but it's actually a WP_Post|WP_Error.
If there's something I can document better or otherwise do to assist here, please let me know. The errors in the baseline are pretty self-documenting, and I tried to be as detailed about usage in the [PR description](https://github.com/WordPress/wordpress-develop/pull/7619). All you should really need to do is
- Checkout the PR and
composer installto get the deps. - Comment out one of the errors from one of the baselines (or an entire level from the root
phpstan.neon.distif you're feeling frisky) - Run
composer run analyse -- -vv(the first time will take a bit, but future runs are cached) - Hop over to the location of the error shown and decide if/how to remediate it.
You can also take a look at my remediation branch on https://github.com/WordPress/wordpress-develop/compare/trunk...justlevine:wordpress-develop:chore/phpstan/level-0 . I've been working there holistically (to help make sure that the remediations make sense in a larger context) and then cherry-pick out to a clean PR against truck the ones that are least likely to disrupt work-in-progress but are still independently justifiable changes.
PS: It appears that they don't agree. 🙊
Heh, I was unnecessarily pedantic and wrong 💀 thanks for the catch!
I'm rereading and have no idea why I said that, I think I was trying to highlight the difference between linting by line and linting by following the executing flow but thats very clearly not what I wrote and I'm also not sure why I thought that was tangentially relevant so 🥴 ?

Crossposted stats from #61175 using https://github.com/WordPress/wordpress-develop/pull/7619, so there's a quick reference for comparison when this ticket gets closed for WP7.0
(even if today's
trunkisn't 100% synonymous with 6.9)