Skip to content

Commit 5be81f3

Browse files
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 #14778. Props Soean. See #65817. git-svn-id: https://develop.svn.wordpress.org/trunk@64694 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 5d48d51 commit 5be81f3

3 files changed

Lines changed: 2 additions & 28 deletions

File tree

‎phpstan.neon.dist‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ includes:
3737
- tests/phpstan/baselines/empty.property.neon
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
4342
- tests/phpstan/baselines/identical.alwaysTrue.neon

‎src/wp-admin/update.php‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@
179179
$upgrader = new Plugin_Upgrader( new Plugin_Installer_Skin( compact( 'type', 'title', 'nonce', 'url', 'overwrite' ) ) );
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
}
185185

@@ -331,7 +331,7 @@
331331
$upgrader = new Theme_Upgrader( new Theme_Installer_Skin( compact( 'type', 'title', 'nonce', 'url', 'overwrite' ) ) );
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
}
337337

‎tests/phpstan/baselines/function.impossibleType.neon‎

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)