From dfc174202046fcebc8c4512a7845824f75abb74b Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 10 Feb 2026 14:24:23 +0100 Subject: [PATCH 1/2] Fix newly reported PHPStan issues --- src/Plugin_Command.php | 4 ++++ src/WP_CLI/CommandWithUpgrade.php | 13 ++++++++++++- src/WP_CLI/ExtensionUpgraderSkin.php | 4 ++++ src/WP_CLI/ParseThemeNameInput.php | 4 ++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Plugin_Command.php b/src/Plugin_Command.php index 9a82fcccc..5ce246aca 100644 --- a/src/Plugin_Command.php +++ b/src/Plugin_Command.php @@ -1216,6 +1216,10 @@ private function get_plugin_dependencies( $slug ) { return []; } + /** + * @var object{requires_plugins?: array} $api + */ + // Check if requires_plugins field exists and is not empty if ( ! empty( $api->requires_plugins ) && is_array( $api->requires_plugins ) ) { return $api->requires_plugins; diff --git a/src/WP_CLI/CommandWithUpgrade.php b/src/WP_CLI/CommandWithUpgrade.php index 63c7776e9..8326c168d 100755 --- a/src/WP_CLI/CommandWithUpgrade.php +++ b/src/WP_CLI/CommandWithUpgrade.php @@ -81,6 +81,9 @@ abstract protected function get_item_list(); */ abstract protected function filter_item_list( $items, $args ); + /** + * @return array + */ abstract protected function get_all_items(); /** @@ -237,6 +240,11 @@ public function install( $args, $assoc_args ) { && ! preg_match( '#github\.com/[^/]+/[^/]+/(?:releases/download|raw)/#', $slug ) ) { $filter = function ( $source ) use ( $slug ) { + /** + * @var \WP_Filesystem_Base $wp_filesystem + */ + global $wp_filesystem; + /** * @var string $path */ @@ -255,7 +263,7 @@ public function install( $args, $assoc_args ) { } $new_path = substr_replace( $source, $slug_dir, (int) strrpos( $source, $source_dir ), strlen( $source_dir ) ); - if ( $GLOBALS['wp_filesystem']->move( $source, $new_path ) ) { + if ( $wp_filesystem->move( $source, $new_path ) ) { WP_CLI::log( sprintf( "Renamed Github-based project from '%s' to '%s'.", $source_dir, $slug_dir ) ); return $new_path; } @@ -874,6 +882,9 @@ protected function _search( $args, $assoc_args ) { // In older WP versions these used to be objects. foreach ( $items as $index => $item_object ) { if ( is_array( $item_object ) ) { + /** + * @var array{slug: string} $item_object + */ $items[ $index ]['url'] = "https://wordpress.org/{$plural}/{$item_object['slug']}/"; } elseif ( $item_object instanceof \stdClass ) { $item_object->url = "https://wordpress.org/{$plural}/{$item_object->slug}/"; diff --git a/src/WP_CLI/ExtensionUpgraderSkin.php b/src/WP_CLI/ExtensionUpgraderSkin.php index 3c9db76ea..3fda4f50d 100644 --- a/src/WP_CLI/ExtensionUpgraderSkin.php +++ b/src/WP_CLI/ExtensionUpgraderSkin.php @@ -15,8 +15,12 @@ class ExtensionUpgraderSkin extends UpgraderSkin { * Called before an update is performed. */ public function before() { + // These properties are defined in `Bulk_Plugin_Upgrader_Skin`/`Bulk_Theme_Upgrader_Skin` + // @phpstan-ignore property.notFound if ( isset( $this->plugin_info ) && is_array( $this->plugin_info ) && isset( $this->plugin_info['Name'] ) ) { + // @phpstan-ignore argument.type WP_CLI::log( sprintf( 'Updating %s...', html_entity_decode( $this->plugin_info['Name'], ENT_QUOTES, get_bloginfo( 'charset' ) ) ) ); + // @phpstan-ignore property.notFound } elseif ( isset( $this->theme_info ) && is_object( $this->theme_info ) && method_exists( $this->theme_info, 'get' ) ) { WP_CLI::log( sprintf( 'Updating %s...', html_entity_decode( $this->theme_info->get( 'Name' ), ENT_QUOTES, get_bloginfo( 'charset' ) ) ) ); } diff --git a/src/WP_CLI/ParseThemeNameInput.php b/src/WP_CLI/ParseThemeNameInput.php index 5a4def568..2c177f2fd 100644 --- a/src/WP_CLI/ParseThemeNameInput.php +++ b/src/WP_CLI/ParseThemeNameInput.php @@ -58,7 +58,7 @@ private function get_all_themes() { if ( is_multisite() ) { /** - * @var array} $site_enabled + * @var array $site_enabled */ $site_enabled = get_option( 'allowedthemes' ); if ( empty( $site_enabled ) ) { @@ -66,7 +66,7 @@ private function get_all_themes() { } /** - * @var array} $network_enabled + * @var array $network_enabled */ $network_enabled = get_site_option( 'allowedthemes' ); if ( empty( $network_enabled ) ) { From 4b13d6cb7e7ae3840cf2271ca1723f0847261118 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 10 Feb 2026 18:04:14 +0100 Subject: [PATCH 2/2] Apply suggestions --- src/WP_CLI/ExtensionUpgraderSkin.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/WP_CLI/ExtensionUpgraderSkin.php b/src/WP_CLI/ExtensionUpgraderSkin.php index 3fda4f50d..cef43ad27 100644 --- a/src/WP_CLI/ExtensionUpgraderSkin.php +++ b/src/WP_CLI/ExtensionUpgraderSkin.php @@ -8,6 +8,9 @@ * An Upgrader Skin for extensions (plugins/themes) that displays which item is being updated * * @package wp-cli + * + * @property-read array{Name?: string}|null $plugin_info + * @property-read \WP_Theme|null $theme_info */ class ExtensionUpgraderSkin extends UpgraderSkin { @@ -16,11 +19,8 @@ class ExtensionUpgraderSkin extends UpgraderSkin { */ public function before() { // These properties are defined in `Bulk_Plugin_Upgrader_Skin`/`Bulk_Theme_Upgrader_Skin` - // @phpstan-ignore property.notFound if ( isset( $this->plugin_info ) && is_array( $this->plugin_info ) && isset( $this->plugin_info['Name'] ) ) { - // @phpstan-ignore argument.type WP_CLI::log( sprintf( 'Updating %s...', html_entity_decode( $this->plugin_info['Name'], ENT_QUOTES, get_bloginfo( 'charset' ) ) ) ); - // @phpstan-ignore property.notFound } elseif ( isset( $this->theme_info ) && is_object( $this->theme_info ) && method_exists( $this->theme_info, 'get' ) ) { WP_CLI::log( sprintf( 'Updating %s...', html_entity_decode( $this->theme_info->get( 'Name' ), ENT_QUOTES, get_bloginfo( 'charset' ) ) ) ); }