Skip to content

Commit 26543f2

Browse files
committed
Cron: Add type definitions to private cron functions.
This addresses PHPStan rule level 10 errors with these functions: * `_get_cron_array()` * `_set_cron_array()` * `_upgrade_cron_array()` See #64898. git-svn-id: https://develop.svn.wordpress.org/trunk@62488 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 41c7489 commit 26543f2

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

src/wp-includes/cron.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,20 +1254,25 @@ function wp_get_ready_cron_jobs() {
12541254
* @since 6.1.0 Return type modified to consistently return an array.
12551255
* @access private
12561256
*
1257-
* @return array[] Array of cron events.
1257+
* @return array<int, array<string, array<string, array{ schedule: string|false, args: array<mixed>, interval?: non-negative-int }>>>|array{} Array of cron events.
12581258
*/
12591259
function _get_cron_array() {
12601260
$cron = get_option( 'cron' );
12611261
if ( ! is_array( $cron ) ) {
12621262
return array();
12631263
}
12641264

1265+
/**
1266+
* @var array{ version: int, ...<int, array<string, array<string, array{ schedule: string|false, args: array<mixed>, interval?: non-negative-int }>>> }
1267+
* |array<int, array<string, array{ schedule: string|false, args: array<mixed>, interval?: non-negative-int }>> $cron
1268+
*/
12651269
if ( ! isset( $cron['version'] ) ) {
12661270
$cron = _upgrade_cron_array( $cron );
12671271
}
12681272

12691273
unset( $cron['version'] );
12701274

1275+
/** @var array<int, array<string, array<string, array{ schedule: string|false, args: array<mixed>, interval?: non-negative-int }>>> $cron */
12711276
return $cron;
12721277
}
12731278

@@ -1283,6 +1288,9 @@ function _get_cron_array() {
12831288
* @param array[] $cron Array of cron info arrays from _get_cron_array().
12841289
* @param bool $wp_error Optional. Whether to return a WP_Error on failure. Default false.
12851290
* @return bool|WP_Error True if cron array updated. False or WP_Error on failure.
1291+
*
1292+
* @phpstan-param array<int, array<string, array<string, array{ schedule: string|false, args: array<mixed>, interval?: non-negative-int }>>> $cron
1293+
* @phpstan-return ( $wp_error is true ? true|WP_Error : bool )
12861294
*/
12871295
function _set_cron_array( $cron, $wp_error = false ) {
12881296
if ( ! is_array( $cron ) ) {
@@ -1313,6 +1321,10 @@ function _set_cron_array( $cron, $wp_error = false ) {
13131321
*
13141322
* @param array $cron Cron info array from _get_cron_array().
13151323
* @return array An upgraded cron info array.
1324+
*
1325+
* @phpstan-param array{ version: int, ...<int, array<string, array<string, array{ schedule: string|false, args: array<mixed>, interval?: non-negative-int }>>> }
1326+
* |array<int, array<string, array{ schedule: string|false, args: array<mixed>, interval?: non-negative-int }>> $cron
1327+
* @phpstan-return array{ version: 2, ...<int, array<string, array<string, array{ schedule: string|false, args: array<mixed>, interval?: non-negative-int }>>> }
13161328
*/
13171329
function _upgrade_cron_array( $cron ) {
13181330
if ( isset( $cron['version'] ) && 2 === $cron['version'] ) {
@@ -1323,7 +1335,7 @@ function _upgrade_cron_array( $cron ) {
13231335

13241336
foreach ( (array) $cron as $timestamp => $hooks ) {
13251337
foreach ( (array) $hooks as $hook => $args ) {
1326-
$key = md5( serialize( $args['args'] ) );
1338+
$key = md5( serialize( $args['args'] ?? array() ) );
13271339

13281340
$new_cron[ $timestamp ][ $hook ][ $key ] = $args;
13291341
}

0 commit comments

Comments
 (0)