Make WordPress Core

Changeset 64694


Ignore:
Timestamp:
10/24/2026 10:55:37 PM (7 hours ago)
Author:
SergeyBiryukov
Message:

Code Quality: Remove a redundant is_wp_error() check after uploading a plugin or theme.

After a plugin or theme is installed from an uploaded ZIP file in wp-admin/update.php, the upload is cleaned up when $result || is_wp_error( $result ). A WP_Error is an object and therefore always truthy, so the first operand already covers it and the is_wp_error() call can never return true. PHPStan reports this as function.impossibleType.

The condition is reduced to if ( $result ), which behaves identically: a failed installation still cleans up the upload, and only false, which WP_Upgrader::run() returns when filesystem credentials are requested, keeps the upload so it is still there once the credentials are entered.

This empties the function.impossibleType baseline, so the file and its entry in phpstan.neon.dist are removed.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/14778.

Props Soean.
See #65817.

Location:
trunk
Files:
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/phpstan.neon.dist

    r64673 r64694  
    3838        - tests/phpstan/baselines/empty.variable.neon
    3939        - tests/phpstan/baselines/function.alreadyNarrowedType.neon
    40         - tests/phpstan/baselines/function.impossibleType.neon
    4140        - tests/phpstan/baselines/function.resultUnused.neon
    4241        - tests/phpstan/baselines/identical.alwaysFalse.neon
  • trunk/src/wp-admin/update.php

    r64352 r64694  
    180180                $result   = $upgrader->install( $file_upload->package, array( 'overwrite_package' => $overwrite ) );
    181181
    182                 if ( $result || is_wp_error( $result ) ) {
     182                if ( $result ) {
    183183                        $file_upload->cleanup();
    184184                }
    … …  
    332332                $result   = $upgrader->install( $file_upload->package, array( 'overwrite_package' => $overwrite ) );
    333333
    334                 if ( $result || is_wp_error( $result ) ) {
     334                if ( $result ) {
    335335                        $file_upload->cleanup();
    336336                }
Note: See TracChangeset for help on using the changeset viewer.