Skip to content

Commit

Permalink
fix phpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan committed Jun 27, 2024
1 parent cff2006 commit b6d8497
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ abstract protected function get_api_url();
* Send a GET request.
*
* @param array $params The request parameters.
* @param bool $safe Send safe request WP functions or not, default to not.
*
* @return mixed The response from the API.
*/
public function send_get_request( $params = [], $safe = false ) {
Expand All @@ -42,6 +44,8 @@ public function send_get_request( $params = [], $safe = false ) {
* Send a POST request.
*
* @param array $params The request parameters.
* @param bool $safe Send safe request WP functions or not, default to not.
*
* @return mixed The response from the API.
*/
public function send_post_request( $params = [], $safe = false ) {
Expand All @@ -53,6 +57,7 @@ public function send_post_request( $params = [], $safe = false ) {
*
* @param string $method The HTTP method (GET or POST).
* @param array $params The request parameters.
* @param bool $safe Send safe request WP functions or not, default to not.
* @return mixed The response from the API, or WP_Error if a timeout is active.
*/
private function send_request( $method, $params = [], $safe = false ) {
Expand All @@ -72,7 +77,7 @@ private function send_request( $method, $params = [], $safe = false ) {
}

$body = wp_remote_retrieve_body( $response );
if ( empty( $body ) || ( is_array( $response ) && !empty( $response['response']['code'] ) && 200 !== $response['response']['code'] ) ) {
if ( empty( $body ) || ( is_array( $response ) && ! empty( $response['response']['code'] ) && 200 !== $response['response']['code'] ) ) {
$this->set_timeout_transients();
return new WP_Error( 500, __( 'Not valid response.', 'rocket' ) );
}
Expand Down Expand Up @@ -116,6 +121,15 @@ private function delete_timeout_transients() {
delete_transient( $transient_key . '_timeout' );
}

/**
* Decide which WP core function will be used to send the request based on the params.
*
* @param string $api_url API Url.
* @param string $method Request method (GET or POST).
* @param array $params Parameters being sent with the request.
* @param bool $safe Send safe request WP functions or not, default to not.
* @return array|WP_Error
*/
private function send_remote_request( $api_url, $method, $params, $safe ) {
if ( ! $safe ) {
return wp_remote_request( $api_url, $params );
Expand Down

0 comments on commit b6d8497

Please sign in to comment.