Skip to content

Commit af1682d

Browse files
Coding Standards: Explicitly return null instead of coercing void.
This addresses two instances where a function that is documented as returning `{someType}|null` doesn't explicitly return `null`. Affected functions: * `array_key_first()` * `WP_REST_Posts_Controller::handle_terms()` Follow-up to [38832], [52038]. Props justlevine. See #52217. git-svn-id: https://develop.svn.wordpress.org/trunk@59453 602fd350-edb4-49c9-b593-d223f7449a82
1 parent bdeb21b commit af1682d

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/wp-includes/compat.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ function is_countable( $value ) {
415415
* is not empty; `null` otherwise.
416416
*/
417417
function array_key_first( array $array ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.arrayFound
418+
if ( empty( $array ) ) {
419+
return null;
420+
}
421+
418422
foreach ( $array as $key => $value ) {
419423
return $key;
420424
}

src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1649,6 +1649,8 @@ protected function handle_terms( $post_id, $request ) {
16491649
return $result;
16501650
}
16511651
}
1652+
1653+
return null;
16521654
}
16531655

16541656
/**

0 commit comments

Comments
 (0)