From 8239adc10a72fa34eb937f332fdce35e78aa4460 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Fri, 4 Dec 2026 12:16:16 +0000 Subject: [PATCH] Fix PHPStan 2.4 error in Core_Command::check_update() PHPStan 2.4 no longer sees that the version check error property can be set by the HTTP API hooks that run during get_updates(), and reports the elseif branch as always false. Read the property through a getter. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01UWTd5ovnS4Susin8tXeDDr --- src/Core_Command.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Core_Command.php b/src/Core_Command.php index e35f342d..a558e3c5 100644 --- a/src/Core_Command.php +++ b/src/Core_Command.php @@ -95,6 +95,9 @@ public function check_update( $args, $assoc_args ) { $updates = $this->get_updates( $assoc_args ); + // Set by the HTTP API hooks that run during the version check. + $version_check_error = $this->get_version_check_error(); + if ( $updates || 'table' !== $format ) { $updates = array_reverse( $updates ); $formatter = new Formatter( @@ -102,12 +105,12 @@ public function check_update( $args, $assoc_args ) { [ 'version', 'update_type', 'package_url' ] ); $formatter->display_items( $updates ); - } elseif ( $this->version_check_error ) { + } elseif ( $version_check_error ) { // If there was an HTTP error during version check, show a warning WP_CLI::warning( sprintf( 'Failed to check for updates: %s', - $this->version_check_error->get_error_message() + $version_check_error->get_error_message() ) ); } else { @@ -1870,6 +1873,15 @@ private function get_updates( $assoc_args ) { return array_values( $updates ); } + /** + * Returns the HTTP API error encountered during the last version check, if any. + * + * @return \WP_Error|null + */ + private function get_version_check_error() { + return $this->version_check_error; + } + /** * Sets or clears the version check error property based on an HTTP response. *