Skip to content

Commit c8fd1ed

Browse files
authored
Merge pull request #308 from wp-cli/fix-phpstan
2 parents 793d117 + c7b1c85 commit c8fd1ed

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"require": {
1515
"composer/semver": "^1.4 || ^2 || ^3",
16-
"wp-cli/wp-cli": "^2.12"
16+
"wp-cli/wp-cli": "^2.13"
1717
},
1818
"require-dev": {
1919
"wp-cli/checksum-command": "^1 || ^2",

src/Core_Command.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
* 4.5.2
2929
*
3030
* @package wp-cli
31+
*
32+
* @phpstan-type HTTP_Response array{headers: array<string, string>, body: string, response: array{code:false|int, message: false|string}, cookies: array<string, string>, http_response: mixed}
3133
*/
3234
class Core_Command extends WP_CLI_Command {
3335

@@ -659,6 +661,10 @@ private static function set_multisite_defaults( $assoc_args ) {
659661
}
660662

661663
private function do_install( $assoc_args ) {
664+
/**
665+
* @var \wpdb $wpdb
666+
*/
667+
global $wpdb;
662668
if ( is_blog_installed() ) {
663669
return false;
664670
}
@@ -710,7 +716,7 @@ function wp_new_blog_notification() {
710716
$args['locale']
711717
);
712718

713-
if ( ! empty( $GLOBALS['wpdb']->last_error ) ) {
719+
if ( ! empty( $wpdb->last_error ) ) {
714720
WP_CLI::error( 'Installation produced database errors, and may have partially or completely failed.' );
715721
}
716722

@@ -1502,6 +1508,10 @@ private function get_updates( $assoc_args ) {
15021508
return [];
15031509
}
15041510

1511+
/**
1512+
* @var array{wp_version: string} $GLOBALS
1513+
*/
1514+
15051515
$compare_version = str_replace( '-src', '', $GLOBALS['wp_version'] );
15061516

15071517
$updates = [
@@ -1552,7 +1562,9 @@ private function get_updates( $assoc_args ) {
15521562
/**
15531563
* Sets or clears the version check error property based on an HTTP response.
15541564
*
1555-
* @param mixed $response The HTTP response (WP_Error, array, or other).
1565+
* @param mixed|\WP_Error $response The HTTP response (WP_Error, array, or other).
1566+
*
1567+
* @phpstan-param HTTP_Response|WP_Error $response
15561568
*/
15571569
private function set_version_check_error( $response ) {
15581570
if ( is_wp_error( $response ) ) {
@@ -1583,6 +1595,8 @@ private function set_version_check_error( $response ) {
15831595
* @param array $args HTTP request arguments.
15841596
* @param string $url The request URL.
15851597
* @return false|array|WP_Error The response, unmodified.
1598+
*
1599+
* @phpstan-param HTTP_Response|WP_Error|false $response
15861600
*/
15871601
public function capture_version_check_error( $response, $args, $url ) {
15881602
if ( false === strpos( $url, 'api.wordpress.org/core/version-check' ) ) {
@@ -1610,6 +1624,8 @@ public function capture_version_check_error( $response, $args, $url ) {
16101624
* @param string $_class HTTP transport class name (unused).
16111625
* @param array $_args HTTP request arguments (unused).
16121626
* @param string $url URL being requested.
1627+
*
1628+
* @phpstan-param HTTP_Response|WP_Error $response
16131629
*/
16141630
public function capture_version_check_error_from_response( $response, $context, $_class, $_args, $url ) {
16151631
if ( false === strpos( $url, 'api.wordpress.org/core/version-check' ) ) {

src/WP_CLI/Core/CoreUpgrader.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,8 @@ public function download_package( $package, $check_signatures = false, $hook_ext
6767
$hook_extra
6868
);
6969

70-
/**
71-
* @var false|string|\WP_Error $reply
72-
*/
73-
7470
if ( false !== $reply ) {
71+
// @phpstan-ignore return.type
7572
return $reply;
7673
}
7774

@@ -96,7 +93,11 @@ function () use ( $temp ) {
9693
}
9794
);
9895

99-
$cache = WP_CLI::get_cache();
96+
$cache = WP_CLI::get_cache();
97+
98+
/**
99+
* @var object{locale: string} $update
100+
*/
100101
$update = $GLOBALS['wpcli_core_update_obj'];
101102
$cache_key = "core/{$filename}-{$update->locale}.{$extension}";
102103

0 commit comments

Comments
 (0)