[wp-trac] [WordPress Trac] #64238: PHPStan code quality improvements for 7.0
WordPress Trac
noreply at wordpress.org
Wed Feb 18 06:44:44 UTC 2026
#64238: PHPStan code quality improvements for 7.0
--------------------------------------+-------------------------------
Reporter: SergeyBiryukov | Owner: (none)
Type: task (blessed) | Status: new
Priority: normal | Milestone: 7.0
Component: General | Version:
Severity: normal | Resolution:
Keywords: has-patch has-unit-tests | Focuses: coding-standards
--------------------------------------+-------------------------------
Comment (by westonruter):
Once #61175 is closed with PHPStan support in core, we should follow up
with the following change for `is_wp_error()`:
{{{#!diff
--- a/src/wp-includes/load.php
+++ b/src/wp-includes/load.php
@@ -1796,6 +1796,8 @@ function wp_doing_cron() {
*
* @since 2.1.0
*
+ * @phpstan-assert-if-true WP_Error $thing
+ *
* @param mixed $thing The variable to check.
* @return bool Whether the variable is an instance of WP_Error.
*/
}}}
This ensures conditionals are understood correctly by PHPStan. For
example, it fixes an error in this function:
{{{#!php
<?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.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/64238#comment:67>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list