Skip to content

Commit

Permalink
Phan: Fix errant extra params in function calls (#41263)
Browse files Browse the repository at this point in the history
* Remove extra param on remove_filter/remove_action

There's no arg count when removing.

* Remove extra param from rest_ensure_response

That function doesn't allow a status code to be passed. Presumably we could override the WP_REST_Response status and force 200, but passing it through has worked so far, so keeping it that way.

* Remove other stray args

In most cases, these appear to be due to refactors.

* Another stray arg

* Suppress things that confuse Phan

* Fix get_avatar_url calls

* arrayHasKey → assertArrayHasKey

* Fix misplaced parentheses

* Tighten types

We're using `WP_Option`, which allows an extra param in its `get()`.

* Add missing sprintf

* Add unused param to allow dynamic method call

* Add changelogs

* Use same behaviour as trunk

* Fix assertion

* Add param to Storage::get and use that type as before

* Inform Phan of type rather than suppressing error

* Update errant types

* Update Phan baselines

* More changelogs

Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/13079055733

Upstream-Ref: Automattic/jetpack@4b2a4a9
  • Loading branch information
tbradsha authored and matticbot committed Jan 31, 2025
1 parent f7c50fe commit 7b3b765
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This is an alpha version! The changes listed here are not final.

### Fixed
- AI: avoid using relative URLs in admin URLs, to support sites where WordPress is installed in a subdirectory.
- Code: Remove extra params on function calls.

## [5.4.0] - 2025-01-23
### Added
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"automattic/jetpack-redirect": "^3.0.1",
"automattic/jetpack-constants": "^3.0.1",
"automattic/jetpack-plans": "^0.5.2-alpha",
"automattic/jetpack-status": "^5.0.2",
"automattic/jetpack-status": "^5.0.3-alpha",
"automattic/jetpack-sync": "^4.6.0-alpha",
"automattic/jetpack-protect-status": "^0.4.3-alpha"
},
Expand Down
10 changes: 5 additions & 5 deletions src/class-rest-products.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ public static function get_products( $request ) {
$product_slugs = ! empty( $slugs ) ? array_map( 'trim', explode( ',', $slugs ) ) : array();

$response = Products::get_products( $product_slugs );
return rest_ensure_response( $response, 200 );
return rest_ensure_response( $response );
}

/**
Expand All @@ -217,7 +217,7 @@ public static function get_products_by_ownership() {
'unownedProducts' => Products::get_products_by_ownership( 'unowned' ),
'ownedProducts' => Products::get_products_by_ownership( 'owned' ),
);
return rest_ensure_response( $response, 200 );
return rest_ensure_response( $response );
}

/**
Expand Down Expand Up @@ -266,7 +266,7 @@ public static function activate_products( $request ) {
}
set_transient( 'my_jetpack_product_activated', implode( ',', $products_array ), 10 );

return rest_ensure_response( Products::get_products( $products_array ), 200 );
return rest_ensure_response( Products::get_products( $products_array ) );
}

/**
Expand Down Expand Up @@ -299,7 +299,7 @@ public static function deactivate_products( $request ) {
}
}

return rest_ensure_response( Products::get_products( $products_array ), 200 );
return rest_ensure_response( Products::get_products( $products_array ) );
}

/**
Expand Down Expand Up @@ -332,6 +332,6 @@ public static function install_plugins( $request ) {
}
}

return rest_ensure_response( Products::get_products( $products_array ), 200 );
return rest_ensure_response( Products::get_products( $products_array ) );
}
}
2 changes: 1 addition & 1 deletion src/class-rest-purchases.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ public static function get_site_current_purchases() {
return new WP_Error( 'site_data_fetch_failed', 'Site data fetch failed', array( 'status' => $response_code ? $response_code : 400 ) );
}

return rest_ensure_response( $body, 200 );
return rest_ensure_response( $body );
}
}
6 changes: 3 additions & 3 deletions src/class-rest-zendesk-chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static function chat_authentication_permissions_callback() {
public static function get_chat_authentication() {
$authentication = get_transient( self::ZENDESK_AUTH_TOKEN );
if ( $authentication ) {
return rest_ensure_response( $authentication, 200 );
return rest_ensure_response( $authentication );
}

$proxied = function_exists( 'wpcom_is_proxied_request' ) ? wpcom_is_proxied_request() : false;
Expand All @@ -97,7 +97,7 @@ public static function get_chat_authentication() {
}

set_transient( self::ZENDESK_AUTH_TOKEN, $body, self::TRANSIENT_EXPIRY );
return rest_ensure_response( $body, 200 );
return rest_ensure_response( $body );
}

/**
Expand All @@ -117,6 +117,6 @@ public static function get_chat_availability() {
return new WP_Error( 'chat_config_data_fetch_failed', 'Chat config data fetch failed', array( 'status' => $response_code ) );
}

return rest_ensure_response( $body, 200 );
return rest_ensure_response( $body );
}
}

0 comments on commit 7b3b765

Please sign in to comment.