Skip to content

Commit a906b96

Browse files
committed
Code Quality: Replace void with proper return types in Administration PHPDoc annotations.
Replace `void` in union return types with `null` or remove it where the function always returns a value or dies, across 8 files in `wp-admin/includes`. Adds explicit `return null;` statements where functions previously fell through without a return value. Additionally: * Adds `@return never` for `media_send_to_editor()` and removes misleading `return` from its callers. * Removes `void` from return types where the function always returns a value or exits: `write_post()`, `WP_Importer::set_blog()`, `WP_Importer::set_user()`. * Replaces `mixed|void` with a specific array shape for `WP_Site_Health::perform_test()`. Developed in #11008 Follow-up to r62178, r62177, r61766, r61719. Props apermo, xate, westonruter, mukesh27, desrosj. Fixes #64702. git-svn-id: https://develop.svn.wordpress.org/trunk@62179 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 317adff commit a906b96

File tree

8 files changed

+36
-15
lines changed

8 files changed

+36
-15
lines changed

src/wp-admin/includes/class-wp-importer.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,14 @@ public function get_imported_comments( $blog_id ) {
135135
}
136136

137137
/**
138-
* @param int $blog_id
139-
* @return int|void
138+
* Sets the blog to import to.
139+
*
140+
* Accepts a numeric blog ID or a URL string. When given a URL,
141+
* the blog is looked up by domain and path. On multisite, switches
142+
* to the resolved blog. Exits with an error if the blog cannot be found.
143+
*
144+
* @param int|string $blog_id Blog ID or URL.
145+
* @return int Blog ID on success. Exits on failure.
140146
*/
141147
public function set_blog( $blog_id ) {
142148
if ( is_numeric( $blog_id ) ) {
@@ -177,7 +183,7 @@ public function set_blog( $blog_id ) {
177183

178184
/**
179185
* @param int $user_id
180-
* @return int|void
186+
* @return int
181187
*/
182188
public function set_user( $user_id ) {
183189
if ( is_numeric( $user_id ) ) {

src/wp-admin/includes/class-wp-privacy-requests-table.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ public function column_cb( $item ) {
435435
* @since 4.9.6
436436
*
437437
* @param WP_User_Request $item Item being shown.
438-
* @return string|void Status column markup. Returns a string if no status is found,
438+
* @return string|null Status column markup. Returns a string if no status is found,
439439
* otherwise it displays the markup.
440440
*/
441441
public function column_status( $item ) {
@@ -465,6 +465,7 @@ public function column_status( $item ) {
465465
}
466466

467467
echo '</span>';
468+
return null;
468469
}
469470

470471
/**

src/wp-admin/includes/class-wp-site-health.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,17 @@ public function enqueue_scripts() {
167167
* @since 5.4.0
168168
*
169169
* @param callable $callback
170-
* @return mixed|void
170+
* @return array{
171+
* label: string,
172+
* status: 'good'|'recommended'|'critical',
173+
* badge: array{
174+
* label: string,
175+
* color: string,
176+
* },
177+
* description: string,
178+
* actions: string,
179+
* test: string,
180+
* }
171181
*/
172182
private function perform_test( $callback ) {
173183
/**

src/wp-admin/includes/dashboard.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1648,7 +1648,7 @@ function wp_dashboard_primary_output( $widget_id, $feeds ) {
16481648
*
16491649
* @since 3.0.0
16501650
*
1651-
* @return true|void True if not multisite, user can't upload files, or the space check option is disabled.
1651+
* @return true|null True if not multisite, user can't upload files, or the space check option is disabled.
16521652
*/
16531653
function wp_dashboard_quota() {
16541654
if ( ! is_multisite() || ! current_user_can( 'upload_files' )
@@ -1709,6 +1709,7 @@ function wp_dashboard_quota() {
17091709
</ul>
17101710
</div>
17111711
<?php
1712+
return null;
17121713
}
17131714

17141715
/**

src/wp-admin/includes/file.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ function wp_tempnam( $filename = '', $dir = '' ) {
734734
* @param string $file File the user is attempting to edit.
735735
* @param string[] $allowed_files Optional. Array of allowed files to edit.
736736
* `$file` must match an entry exactly.
737-
* @return string|void Returns the file name on success, dies on failure.
737+
* @return string|null Returns the file name on success, null in case of absolute Windows drive paths, and dies on failure.
738738
*/
739739
function validate_file_to_edit( $file, $allowed_files = array() ) {
740740
$code = validate_file( $file, $allowed_files );
@@ -753,6 +753,7 @@ function validate_file_to_edit( $file, $allowed_files = array() ) {
753753
case 3:
754754
wp_die( __( 'Sorry, that file cannot be edited.' ) );
755755
}
756+
return null;
756757
}
757758

758759
/**

src/wp-admin/includes/media.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ function _cleanup_image_add_caption( $matches ) {
269269
* @since 2.5.0
270270
*
271271
* @param string $html
272+
* @return never
272273
*/
273274
function media_send_to_editor( $html ) {
274275
?>
@@ -753,7 +754,7 @@ function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) {
753754
*
754755
* @since 2.5.0
755756
*
756-
* @return null|array|void Array of error messages keyed by attachment ID, null or void on success.
757+
* @return null|array Array of error messages keyed by attachment ID, null on success, or exit.
757758
*/
758759
function media_upload_form_handler() {
759760
check_admin_referer( 'media-form' );
@@ -874,7 +875,7 @@ function media_upload_form_handler() {
874875
*/
875876
$html = apply_filters( 'media_send_to_editor', $html, $send_id, $attachment );
876877

877-
return media_send_to_editor( $html );
878+
media_send_to_editor( $html );
878879
}
879880

880881
return $errors;
@@ -976,7 +977,7 @@ function wp_media_upload_handler() {
976977
$html = apply_filters( 'image_send_to_editor_url', $html, sanitize_url( $src ), $alt, $align );
977978
}
978979

979-
return media_send_to_editor( $html );
980+
media_send_to_editor( $html );
980981
}
981982

982983
if ( isset( $_POST['save'] ) ) {

src/wp-admin/includes/plugin.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1296,8 +1296,8 @@ function is_uninstallable_plugin( $plugin ) {
12961296
* @since 2.7.0
12971297
*
12981298
* @param string $plugin Path to the plugin file relative to the plugins directory.
1299-
* @return true|void True if a plugin's uninstall.php file has been found and included.
1300-
* Void otherwise.
1299+
* @return true|null True if a plugin's uninstall.php file has been found and included.
1300+
* Null otherwise.
13011301
*/
13021302
function uninstall_plugin( $plugin ) {
13031303
$file = plugin_basename( $plugin );
@@ -1350,6 +1350,7 @@ function uninstall_plugin( $plugin ) {
13501350
*/
13511351
do_action( "uninstall_{$file}" );
13521352
}
1353+
return null;
13531354
}
13541355

13551356
//

src/wp-admin/includes/post.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -982,15 +982,15 @@ function wp_write_post() {
982982
*
983983
* @since 2.0.0
984984
*
985-
* @return int|void Post ID on success, void on failure.
985+
* @return int Post ID on success. Dies on failure.
986986
*/
987987
function write_post() {
988988
$result = wp_write_post();
989989
if ( is_wp_error( $result ) ) {
990990
wp_die( $result->get_error_message() );
991-
} else {
992-
return $result;
993991
}
992+
993+
return $result;
994994
}
995995

996996
//

0 commit comments

Comments
 (0)