Make WordPress Core

Changeset 62179 for trunk


Ignore:
Timestamp:
03/30/2026 06:01:58 AM (7 months ago)
Author:
westonruter
Message:

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 ​https://github.com/WordPress/wordpress-develop/pull/11008

Follow-up to r62178, r62177, r61766, r61719.

Props apermo, xate, westonruter, mukesh27, desrosj.
Fixes #64702.

Location:
trunk/src/wp-admin/includes
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-importer.php

    r61657 r62179  
    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 ) {
    … …  
    178184        /**
    179185         * @param int $user_id
    180          * @return int|void
     186         * @return int
    181187         */
    182188        public function set_user( $user_id ) {
  • trunk/src/wp-admin/includes/class-wp-privacy-requests-table.php

    r60891 r62179  
    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         */
    … …  
    466466
    467467                echo '</span>';
     468                return null;
    468469        }
    469470
  • trunk/src/wp-admin/includes/class-wp-site-health.php

    r61711 r62179  
    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 ) {
  • trunk/src/wp-admin/includes/dashboard.php

    r61799 r62179  
    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 */
    16531653function wp_dashboard_quota() {
    … …  
    17101710        </div>
    17111711        <?php
     1712        return null;
    17121713}
    17131714
  • trunk/src/wp-admin/includes/file.php

    r61946 r62179  
    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 */
    739739function validate_file_to_edit( $file, $allowed_files = array() ) {
    … …  
    754754                        wp_die( __( 'Sorry, that file cannot be edited.' ) );
    755755        }
     756        return null;
    756757}
    757758
  • trunk/src/wp-admin/includes/media.php

    r61841 r62179  
    270270 *
    271271 * @param string $html
     272 * @return never
    272273 */
    273274function media_send_to_editor( $html ) {
    … …  
    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 */
    758759function media_upload_form_handler() {
    … …  
    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
    … …  
    977978                }
    978979
    979                 return media_send_to_editor( $html );
     980                media_send_to_editor( $html );
    980981        }
    981982
  • trunk/src/wp-admin/includes/plugin.php

    r61716 r62179  
    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 */
    13021302function uninstall_plugin( $plugin ) {
    … …  
    13511351                do_action( "uninstall_{$file}" );
    13521352        }
     1353        return null;
    13531354}
    13541355
  • trunk/src/wp-admin/includes/post.php

    r62040 r62179  
    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 */
    987987function write_post() {
    … …  
    989989        if ( is_wp_error( $result ) ) {
    990990                wp_die( $result->get_error_message() );
    991         } else {
    992                 return $result;
    993         }
     991        }
     992
     993        return $result;
    994994}
    995995
Note: See TracChangeset for help on using the changeset viewer.