Opened 4 months ago
Last modified 21 minutes ago
#64238 new task (blessed)
PHPStan code quality improvements for 7.0
| Reported by: |
|
Owned by: | |
|---|---|---|---|
| Milestone: | 7.0 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | General | Keywords: | has-patch has-unit-tests |
| Focuses: | coding-standards | Cc: |
Change History (98)
This ticket was mentioned in PR #7720 on WordPress/wordpress-develop by @justlevine.
4 months ago
#1
- Keywords has-patch added
This ticket was mentioned in PR #8860 on WordPress/wordpress-develop by @justlevine.
4 months ago
#2
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/64238
https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8861 on WordPress/wordpress-develop by @justlevine.
4 months ago
#3
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/64238
https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8864 on WordPress/wordpress-develop by @justlevine.
4 months ago
#4
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/64238
https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8865 on WordPress/wordpress-develop by @justlevine.
4 months ago
#5
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/64238
https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8866 on WordPress/wordpress-develop by @justlevine.
4 months ago
#6
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/64238
https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8872 on WordPress/wordpress-develop by @justlevine.
4 months ago
#7
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/64238
https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8873 on WordPress/wordpress-develop by @justlevine.
4 months ago
#8
- Keywords has-unit-tests added
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/64238
https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8945 on WordPress/wordpress-develop by @justlevine.
4 months ago
#9
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/64238
https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8946 on WordPress/wordpress-develop by @justlevine.
4 months ago
#10
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/64238
https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8953 on WordPress/wordpress-develop by @justlevine.
4 months ago
#11
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/64238
https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8955 on WordPress/wordpress-develop by @justlevine.
4 months ago
#12
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/64238
https://core.trac.wordpress.org/ticket/63268
This ticket was mentioned in PR #8956 on WordPress/wordpress-develop by @justlevine.
4 months ago
#13
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/64238
https://core.trac.wordpress.org/ticket/63268
@SergeyBiryukov commented on PR #8866:
4 months ago
#15
Thanks for the PR! Merged in r61243.
@SergeyBiryukov commented on PR #8872:
4 months ago
#17
Thanks for the PR! Merged in r61247.
@westonruter commented on PR #8946:
3 months ago
#19
Committed in r61280 (9e2d045)
@westonruter commented on PR #8955:
3 months ago
#21
Committed in r61281 (c9c6518)
@westonruter commented on PR #8873:
3 months ago
#23
@westonruter commented on PR #8945:
3 months ago
#25
Committed in r61283 (e870c4a)
@westonruter commented on PR #8861:
3 months ago
#26
@justlevine I found that wp_create_category() was incorrectly saying that it could return WP_Error, when in fact it is supposed to always return an integer. In the case of failure, it returns zero, since wp_insert_category() isn't called with the $wp_error arg.
@westonruter commented on PR #8860:
3 months ago
#27
In trunk when I run:
phpstan analyze --memory-limit=2G --level=3 src/wp-admin/includes/class-wp-screen.php
I get:
Note: Using configuration file /Users/westonruter/repos/wordpress-develop/phpstan.neon.
1/1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
------ -----------------------------------------------------------------------------------
Line class-wp-screen.php
------ -----------------------------------------------------------------------------------
306 Variable $post_id might not be defined.
🪪 variable.undefined
at src/wp-admin/includes/class-wp-screen.php:306
552 Method WP_Screen::get_option() should return string but returns null.
🪪 return.type
at src/wp-admin/includes/class-wp-screen.php:552
558 Method WP_Screen::get_option() should return string but returns null.
🪪 return.type
at src/wp-admin/includes/class-wp-screen.php:558
605 Method WP_Screen::get_help_tab() should return array but returns null.
🪪 return.type
at src/wp-admin/includes/class-wp-screen.php:605
740 Method WP_Screen::get_screen_reader_text() should return string but returns null.
🪪 return.type
at src/wp-admin/includes/class-wp-screen.php:740
953 Property WP_Screen::$columns (int) does not accept string.
🪪 assign.propertyType
at src/wp-admin/includes/class-wp-screen.php:953
In this branch, the last five are eliminated.
@westonruter commented on PR #8865:
3 months ago
#28
I guess the bug here has never been noticed before because no where in core is the REST API used to set the featured image for an attachment?
We should add a unit test for this.
@westonruter commented on PR #8865:
3 months ago
#29
@justlevine ok, I found the issue, and I've fixed it in 720512a. The issue is that with fixing the $schema here, it's allowing handle_featured_media() to be called by \WP_REST_Attachments_Controller::update_item() when the this method is also calling parent::update_item() in which case it calls \WP_REST_Posts_Controller::update_item() which _also_ calls the handle_featured_media() method. The handle_featured_media() method wasn't accounting for the case where an attempt is made to update a featured media to be the same as the featured media currently set.
This appears to have been introduced in r57603 (54d72c5deee2c5cfa2dadef4409b7beb1cefea38) to fix Core-41692 (as noted above).
The idempotency issue is only noticed for updating attachments because it short-circuits with an error when handle_featured_media() returns false:
This doesn't happen when updating posts:
So while the tests have been fixed, it's clear that test coverage is not complete, because this code is never run:
So we need to make sure that the error scenario is tested.
@westonruter commented on PR #8865:
3 months ago
#30
So we need to make sure that the error scenario is tested.
OK, added in e6c6c68
@westonruter commented on PR #8865:
3 months ago
#31
Summarized in comment on original ticket: https://core.trac.wordpress.org/ticket/41692#comment:44
@westonruter commented on PR #8861:
3 months ago
#33
Committed in r61298 (2cf0f3d)
@westonruter commented on PR #8953:
3 months ago
#35
Committed in r61299 (0d33b5c)
@westonruter commented on PR #8860:
3 months ago
#37
Committed in r61300 (2898ab5).
@westonruter commented on PR #8956:
3 months ago
#39
Committed in r61303 (6bea530)
This ticket was mentioned in PR #10607 on WordPress/wordpress-develop by @westonruter.
3 months ago
#40
Trac ticket: https://core.trac.wordpress.org/ticket/64238
Running this PHPStan command:
phpstan analyze --memory-limit=4G --level=8 src/wp-includes/class-wp-scripts.php src/wp-includes/class-wp-styles.php src/wp-includes/class-wp-dependencies.php src/wp-includes/class-wp-dependency.php
Results in the following report for trunk:
------ ------------------------------------------------------------------------------------------------------------
Line class-wp-dependencies.php
------ ------------------------------------------------------------------------------------------------------------
65 Property WP_Dependencies::$args type has no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/class-wp-dependencies.php:65
105 Property WP_Dependencies::$queued_before_register type has no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/class-wp-dependencies.php:105
------ ------------------------------------------------------------------------------------------------------------
------ --------------------------------------------------------------------------------------------
Line class-wp-dependency.php
------ --------------------------------------------------------------------------------------------
71 Property _WP_Dependency::$extra type has no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/class-wp-dependency.php:71
------ --------------------------------------------------------------------------------------------
------ --------------------------------------------------------------------------------------------------------
Line class-wp-scripts.php
------ --------------------------------------------------------------------------------------------------------
51 Property WP_Scripts::$in_footer type has no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/class-wp-scripts.php:51
123 Property WP_Scripts::$default_dirs type has no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/class-wp-scripts.php:123
597 Method WP_Scripts::localize() has parameter $l10n with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/class-wp-scripts.php:597
724 Property _WP_Dependency::$translations_path (string) in isset() is not nullable.
🪪 isset.property
at src/wp-includes/class-wp-scripts.php:724
------ --------------------------------------------------------------------------------------------------------
------ ---------------------------------------------------------------------------------------------
Line class-wp-styles.php
------ ---------------------------------------------------------------------------------------------
101 Property WP_Styles::$default_dirs type has no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/class-wp-styles.php:101
186 Parameter #1 $src of method WP_Styles::in_default_dir() expects string, string|false given.
🪪 argument.type
at src/wp-includes/class-wp-styles.php:186
------ ---------------------------------------------------------------------------------------------
[ERROR] Found 9 errors
With this PR, the issues are fixed.
@westonruter commented on PR #10607:
3 months ago
#42
Committed in r61358.
This ticket was mentioned in PR #10614 on WordPress/wordpress-develop by @westonruter.
3 months ago
#43
This addresses the following PHPStan level 6 issues:
------ ---------------------------------------------------------------------------------------------------------------
Line class-wp-script-modules.php
------ ---------------------------------------------------------------------------------------------------------------
122 Method WP_Script_Modules::register() has parameter $args with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/class-wp-script-modules.php:122
294 Method WP_Script_Modules::enqueue() has parameter $args with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/class-wp-script-modules.php:294
540 Method WP_Script_Modules::get_import_map() return type has no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/class-wp-script-modules.php:540
561 Method WP_Script_Modules::get_marked_for_enqueue() return type has no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/class-wp-script-modules.php:561
582 Method WP_Script_Modules::get_dependencies() return type has no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/class-wp-script-modules.php:582
Trac ticket: https://core.trac.wordpress.org/ticket/64238
@westonruter commented on PR #10614:
3 months ago
#45
Committed in r61362.
This ticket was mentioned in PR #10627 on WordPress/wordpress-develop by @westonruter.
3 months ago
#46
Trac ticket: https://core.trac.wordpress.org/ticket/64238
This fixes the following PHPStan issues:
------ --------------------------------------------------------------------------------------------------------
Line functions.wp-scripts.php
------ --------------------------------------------------------------------------------------------------------
144 Parameter #1 $string of function trim expects string, string|null given.
🪪 argument.type
at src/wp-includes/functions.wp-scripts.php:144
181 Function wp_register_script() has parameter $args with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/functions.wp-scripts.php:181
230 Function wp_localize_script() has parameter $l10n with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/functions.wp-scripts.php:230
366 Function wp_enqueue_script() has parameter $args with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/functions.wp-scripts.php:366
------ --------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------
Line functions.wp-styles.php
------ ------------------------------------------------------------------------------------------------------------------------------------
44 Function wp_print_styles() has parameter $handles with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/functions.wp-styles.php:44
68 Parameter #1 $handles of method WP_Dependencies::do_items() expects array<string>|string|false, array|bool|non-empty-string given.
🪪 argument.type
at src/wp-includes/functions.wp-styles.php:68
101 Parameter #1 $string of function trim expects string, string|null given.
🪪 argument.type
at src/wp-includes/functions.wp-styles.php:101
------ ------------------------------------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Line script-loader.php
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
133 Offset
0|1|2|3|4|5|6|7|8|9|10|11|12|'lodash'|'moment'|'react'|'react-dom'|'react-jsx-runtime'|'regenerator-runtime'|'wp-polyfill'|'wp-polyfill-dom-rect'|'wp-polyfill-element…'|'wp
-polyfill-fetch'|'wp-polyfill-formdata'|'wp-polyfill-inert'|'wp-polyfill-node…'|'wp-polyfill-object…'|'wp-polyfill-url' might not exist on array{react: '18.3.1.1',
react-dom: '18.3.1.1', react-jsx-runtime: '18.3.1', regenerator-runtime: '0.14.1', moment: '2.30.1', lodash: '4.17.21', wp-polyfill-fetch: '3.6.20', wp-polyfill-formdata:
'4.0.10', ...}.
🪪 offsetAccess.notFound
at src/wp-includes/script-loader.php:133
135 Parameter #1 $handle of method WP_Dependencies::add() expects string, int|string given.
🪪 argument.type
at src/wp-includes/script-loader.php:135
191 Parameter #1 $haystack of function str_starts_with expects string, string|false given.
🪪 argument.type
at src/wp-includes/script-loader.php:191
191 Parameter #2 $subject of function preg_match expects string, string|false given.
🪪 argument.type
at src/wp-includes/script-loader.php:191
700 Variable $wp_version might not be defined.
🪪 variable.undefined
at src/wp-includes/script-loader.php:700
1089 Parameter #1 $string of function strtolower expects string, string|false given.
🪪 argument.type
at src/wp-includes/script-loader.php:1089
1564 Variable $wp_version might not be defined.
🪪 variable.undefined
at src/wp-includes/script-loader.php:1564
1608 Parameter #2 $src of method WP_Dependencies::add() expects string|false, true given.
🪪 argument.type
at src/wp-includes/script-loader.php:1608
1907 Parameter #2 $offset of function array_splice expects int, int|string given.
🪪 argument.type
at src/wp-includes/script-loader.php:1907
2083 Function wp_style_loader_src() should return string|false but returns string|null.
🪪 return.type
at src/wp-includes/script-loader.php:2083
2357 Function print_late_styles() return type has no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/script-loader.php:2357
2514 Function wp_filter_out_block_nodes() has parameter $nodes with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/script-loader.php:2514
2514 Function wp_filter_out_block_nodes() return type has no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/script-loader.php:2514
2875 Function wp_sanitize_script_attributes() has parameter $attributes with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/script-loader.php:2875
2907 Function wp_get_script_tag() has parameter $attributes with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/script-loader.php:2907
2939 Function wp_print_script_tag() has parameter $attributes with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/script-loader.php:2939
2955 Function wp_get_inline_script_tag() has parameter $attributes with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/script-loader.php:2955
3043 Function wp_print_inline_script_tag() has parameter $attributes with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/script-loader.php:3043
3081 Call to an undefined method object::get_data().
🪪 method.notFound
at src/wp-includes/script-loader.php:3081
3099 Parameter #1 $array of function usort contains unresolvable type.
🪪 argument.unresolvableType
at src/wp-includes/script-loader.php:3099
3100 Parameter #2 $callback of function usort contains unresolvable type.
🪪 argument.unresolvableType
at src/wp-includes/script-loader.php:3100
3128 Parameter #1 $css of function _wp_normalize_relative_css_links expects string, string|false given.
🪪 argument.type
at src/wp-includes/script-loader.php:3128
3158 Function _wp_normalize_relative_css_links() should return string but returns string|null.
🪪 return.type
at src/wp-includes/script-loader.php:3158
3244 Function wp_enqueue_stored_styles() has parameter $options with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/script-loader.php:3244
3318 Function wp_enqueue_block_style() has parameter $args with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
at src/wp-includes/script-loader.php:3318
3756 Parameter #3 $priority of function remove_action expects int, int|true given.
🪪 argument.type
at src/wp-includes/script-loader.php:3756
3763 Parameter #3 $priority of function add_action expects int, int|true given.
🪪 argument.type
at src/wp-includes/script-loader.php:3763
3846 Parameter #1 $text of method WP_HTML_Tag_Processor@anonymous/script-loader.php:3773::insert_after() expects string, string|false given.
🪪 argument.type
at src/wp-includes/script-loader.php:3846
------ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[ERROR] Found 35 errors
This ticket was mentioned in PR #10652 on WordPress/wordpress-develop by @westonruter.
2 months ago
#48
This PR addresses the following issues PHPStan level 8 issues:
phpstan analyze --memory-limit=4G --level=8 src/wp-includes/functions.wp-styles.php src/wp-includes/functions.wp-scripts.php
Before:
Note: Using configuration file /Users/westonruter/repos/wordpress-develop/phpstan.neon.
2/2 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
------ --------------------------------------------------------------------------------------------------------
Line functions.wp-scripts.php
------ --------------------------------------------------------------------------------------------------------
144 Parameter #1 $string of function trim expects string, string|null given.
🪪 argument.type
181 Function wp_register_script() has parameter $args with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
230 Function wp_localize_script() has parameter $l10n with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
366 Function wp_enqueue_script() has parameter $args with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
------ --------------------------------------------------------------------------------------------------------
------ ------------------------------------------------------------------------------------------------------------------------------------
Line functions.wp-styles.php
------ ------------------------------------------------------------------------------------------------------------------------------------
44 Function wp_print_styles() has parameter $handles with no value type specified in iterable type array.
🪪 missingType.iterableValue
💡 See: https://phpstan.org/blog/solving-phpstan-no-value-type-specified-in-iterable-type
68 Parameter #1 $handles of method WP_Dependencies::do_items() expects array<string>|string|false, array|bool|non-empty-string given.
🪪 argument.type
101 Parameter #1 $string of function trim expects string, string|null given.
🪪 argument.type
------ ------------------------------------------------------------------------------------------------------------------------------------
After:
[OK] No errors
Trac ticket: https://core.trac.wordpress.org/ticket/64238
@westonruter commented on PR #10652:
2 months ago
#50
Committed in r61402
This ticket was mentioned in Slack in #core by mukeshpanchal27. View the logs.
3 weeks ago
This ticket was mentioned in PR #10951 on WordPress/wordpress-develop by @westonruter.
2 weeks ago
#55
The commits in this PR were cherry-picked from https://github.com/WordPress/wordpress-develop/pull/10419 for Core-61175.
Trac ticket: https://core.trac.wordpress.org/ticket/64238
## Use of AI Tools
n/a
@westonruter commented on PR #10951:
2 weeks ago
#56
@sabernhardt Would you review when you get a chance?
This ticket was mentioned in PR #10952 on WordPress/wordpress-develop by @westonruter.
2 weeks ago
#57
The changes in this PR were cherry-picked (e.g. 2f724070eca10d8503c6453732cbc9131d7da010 and 22370b6a9783ed0bd56c9b1b731617b8b9cedcbf) from https://github.com/WordPress/wordpress-develop/pull/10419 for Core-61175.
Trac ticket: https://core.trac.wordpress.org/ticket/64238
## Use of AI Tools
n/a
This ticket was mentioned in PR #10953 on WordPress/wordpress-develop by @westonruter.
2 weeks ago
#58
The commits in this PR were cherry-picked from https://github.com/WordPress/wordpress-develop/pull/10419 for Core-61175.
See https://github.com/WordPress/wordpress-develop/pull/10419#issuecomment-3911582777:
I also got to the bottom of the issue with
wp_insert_user()causing PHPStan to hang. Or at least, I think I did. The issue is that PHPStan couldn't figure out what$userdata's type was. So in 77d9403...512e368 I've ensured that$userdataalways is a string, and I went the extra mile to ensure back-compat for passing in unexpected values to that function.
Trac ticket: https://core.trac.wordpress.org/ticket/64238
## Use of AI Tools
n/a
@westonruter commented on PR #10953:
2 weeks ago
#59
@peterwilsoncc Hey! I'm requesting your review because this appears to have been related to your commit in r60650.
@westonruter commented on PR #10953:
2 weeks ago
#60
@peterwilsoncc thank you. My guess is that 99.99999% of the time, a array|stdClass|WP_User is passed in. But I can imagine someone wanting to pass in an array-like object for the sake of lazy-loading. So I wanted to be sure this didn't break anything.
It's also true that PHPStan probably shouldn't be struggling so hard here. But I still think this is an overall improvement since it improves type safety, ensuring that down the road the function is guaranteed to always be working with an array as it expects to be.
@westonruter commented on PR #10952:
2 weeks ago
#61
@justlevine Would you give this a review for me?
@westonruter commented on PR #10953:
2 weeks ago
#63
Committed in r61656 (297771e887699386de70ed087147c2bf3b42bd28).
@westonruter commented on PR #10951:
2 weeks ago
#64
@sabernhardt anything else you'd like revised?
@westonruter commented on PR #10952:
2 weeks ago
#66
Committed in r61670 (ff7564a)
#67
@
2 weeks ago
Once #61175 is closed with PHPStan support in core, we should follow up with the following change for is_wp_error():
-
src/wp-includes/load.php
a b function wp_doing_cron() { 1796 1796 * 1797 1797 * @since 2.1.0 1798 1798 * 1799 * @phpstan-assert-if-true WP_Error $thing 1800 * 1799 1801 * @param mixed $thing The variable to check. 1800 1802 * @return bool Whether the variable is an instance of WP_Error. 1801 1803 */
This ensures conditionals are understood correctly by PHPStan. For example, it fixes an error in this function:
<?php function wp_remote_retrieve_headers( $response ) { if ( is_wp_error( $response ) || ! isset( $response['headers'] ) ) { return array(); } return $response['headers']; }
phpstan: Cannot access offset 'headers' on array|WP_Error.
@sabernhardt commented on PR #10951:
2 weeks ago
#68
I have nothing further.
@westonruter commented on PR #10951:
2 weeks ago
#70
Committed in r61676 (265fbb4c71e5d07ce26ae051d55601e94626cc1f)
#71
@
2 weeks ago
Another patch we should land to improve static analysis:
-
src/wp-includes/comment.php
diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php index 70d78ed33c..5951b1906c 100644
a b function get_approved_comments( $post_id, $args = array() ) { 217 217 * correspond to a WP_Comment object, an associative array, or a numeric array, 218 218 * respectively. Default OBJECT. 219 219 * @return WP_Comment|array|null Depends on $output value. 220 * @phpstan-return ( 221 * $output is 'ARRAY_A' ? non-empty-array<string, mixed> 222 * : ( $output is 'ARRAY_N' ? non-empty-array<int, mixed> 223 * : WP_Comment|null ) ) 220 224 */ 221 225 function get_comment( $comment = null, $output = OBJECT ) { 222 226 if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) { -
src/wp-includes/post.php
diff --git a/src/wp-includes/post.php b/src/wp-includes/post.php index 1b36ad58fc..50130770a3 100644
a b function get_post_type_object( $post_type ) { 1640 1640 * element from the array needs to match; 'and' means all elements 1641 1641 * must match; 'not' means no elements may match. Default 'and'. 1642 1642 * @return string[]|WP_Post_Type[] An array of post type names or objects. 1643 * @phpstan-return ( $output is 'names' ? string[] : WP_Post_Type[] ) 1643 1644 */ 1644 1645 function get_post_types( $args = array(), $output = 'names', $operator = 'and' ) { 1645 1646 global $wp_post_types;
That first change is for get_comment() and a similar change could be made for get_post().
@westonruter commented on PR #8864:
2 weeks ago
#73
This was _not_ committed yet.
@westonruter commented on PR #8865:
2 weeks ago
#74
This was _not_ committed yet.
This ticket was mentioned in PR #10995 on WordPress/wordpress-develop by @huzaifaalmesbah.
13 days ago
#75
The @return tags for these functions indicate they may return null.
This fixes "Missing return argument" warnings that PHPStan (level 1) and IDEs report when a bare return; is used in a function documented to return a typed value including null.
## Affected Functions and Files
WP_Filesystem()inwp-admin/includes/file.phpdelete_plugins()inwp-admin/includes/plugin.php(2 occurrences)delete_theme()inwp-admin/includes/theme.php(2 occurrences)get_category_by_path()inwp-includes/category.php
## Details
In each case, the function's @return tag already documents null as a possible return value (e.g. @return bool|null|WP_Error), but the early exit paths used a bare return;, which implicitly returns void.
Related: Trac #64238
@westonruter commented on PR #10995:
12 days ago
#76
@noruzzaman commented on PR #10995:
11 days ago
#77
LGTM
@westonruter commented on PR #10995:
11 days ago
#78
Note: These fix PHPStan rule level 3 issues.
@westonruter commented on PR #10995:
11 days ago
#80
Committed in r61716 (954c187)
This ticket was mentioned in PR #11014 on WordPress/wordpress-develop by @huzaifaalmesbah.
10 days ago
#82
This fixes a few PHPStan "variable might not be defined" warnings..
Changes:
src/wp-admin/includes/menu.php: Added theglobaldeclaration for$menu,$submenu, and$compat.src/wp-admin/includes/network.php: Initialized the$messageand$message_classvariables to prevent them from being undefined when the condition isn't met.
This ticket was mentioned in PR #11017 on WordPress/wordpress-develop by @huzaifaalmesbah.
10 days ago
#83
This PR addresses strict type return.empty violations reported by PHPStan, ensuring methods return their declared or documented types rather than relying on an empty return;.
Details
src/wp-includes/class-wp-query.php(WP_Query::setup_postdata):- Updated the PHPDoc to reflect that the method can return both
true(success) andfalse(failure). - Replaced the early empty
return;bail-outs withreturn false;when the post object is invalid or whengenerate_postdata()fails.
- Updated the PHPDoc to reflect that the method can return both
src/wp-includes/theme.php(_remove_theme_support):- Replaced an empty
return;inside thecustom-header-uploadsbackward compatibility fallback withreturn true;. This matches the documentedboolreturn type to indicate the feature support was successfully removed.
- Replaced an empty
Using empty return; statements in methods/functions that have a declared or documented non-void return type causes static analysis tooling (like PHPStan) to flag them as errors. Returning explicit boolean values improves strict typing constraints and code clarity.
Trac ticket: https://core.trac.wordpress.org/ticket/64238
## Use of AI Tools
Use For PR Content.
@SergeyBiryukov commented on PR #11017:
9 days ago
#86
This ticket was mentioned in PR #11095 on WordPress/wordpress-develop by @westonruter.
5 days ago
#91
This reduces the number of PHPStan errors at level 7 from 14,271 to 13,233 (-1,038 or -7.27%). See error report diff.
Trac ticket: https://core.trac.wordpress.org/ticket/64238
## Use of AI Tools
n/a
@westonruter commented on PR #11095:
5 days ago
#93
Committed in r61774 (b00dde1)
This ticket was mentioned in PR #11096 on WordPress/wordpress-develop by @westonruter.
5 days ago
#94
#95
@
4 days ago
Reviewed ticket #64238 — PHPStan code quality improvements for WP 7.0 (March 2026).
This is a tracked aggregate ticket for PHPStan-surfaced issues. It has 30+ commits already merged. Reviewed scope of remaining work:
- The ticket targets various type safety issues, null handling, and union type corrections across Core files
- PHPStan analysis surfaced issues in: taxonomy, screen handling, REST API, and general WordPress functions
- Unit tests are included with each fix (has-unit-tests keyword)
Latest PR: https://github.com/WordPress/wordpress-develop/pull/11096
PR scope:
Code quality improvements of this kind reduce PHP 8.x deprecation notices and improve static analysis confidence. The pattern of changes (fixing void return types, null coalescing, and union return types) is consistent across all sub-fixes.
This approach aligns with the PHP 8.5 compatibility goals also tracked for 7.0. Confirming the pattern of fixes is sound and follows WordPress coding standards.
@westonruter commented on PR #11096:
3 days ago
#97
Committed in r61789 (f997e86)
#98
@
21 minutes ago
In 61853:
Trac ticket:
https://core.trac.wordpress.org/ticket/64238
https://core.trac.wordpress.org/ticket/63268
This PR fixes an issue in
get_taxonomy_labels(), where thetemplate_namewas accessed as an object property on$tax->labelsinstead 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.