Skip to content

Commit

Permalink
Fix: backport to php 8.0 (#190)
Browse files Browse the repository at this point in the history
* switch return type to bool

* fix return type

* fix for 8.0
  • Loading branch information
jhnstn authored Aug 28, 2024
1 parent b64a2b6 commit 8e8323e
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 11 deletions.
5 changes: 4 additions & 1 deletion plugin/admin/includes/wpcloud-headstart.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ public function feedback( $message, ...$args ): string {
* @param WP_Upgrader_Skin $headstart_skin The skin to use for the installation.
* @return true|WP_Error True if headstart succeeded, WP_Error on failure.
*/
function wpcloud_headstart( WP_Upgrader_Skin $headstart_skin = new WPCloud_Quite_Skin() ): true|WP_Error { // phpcs:ignore
function wpcloud_headstart( WP_Upgrader_Skin $headstart_skin = null ): bool|WP_Error { // phpcs:ignore
if ( ! $headstart_skin ) {
$headstart_skin = new WPCloud_Quiet_Skin();
}

// Install the demo theme.
$available_themes = wp_get_themes();
Expand Down
10 changes: 5 additions & 5 deletions plugin/controllers/class-wpcloud-sites-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public function prepare_item_for_response( $item, $request ) {
*
* @return true|WP_Error
*/
public function validate_owner( string $owner_search, WP_REST_Request $request, string $param ): true|WP_Error {
public function validate_owner( string $owner_search, WP_REST_Request $request, string $param ): bool|WP_Error {

if ( ! $owner_search ) {
return true;
Expand Down Expand Up @@ -598,7 +598,7 @@ public function validate_owner( string $owner_search, WP_REST_Request $request,
*
* @return true|WP_Error
*/
public function validate_php_version( $php_version, $request, $param ): true|WP_Error {
public function validate_php_version( $php_version, $request, $param ): bool|WP_Error {
if ( ! $php_version ) {
return true;
}
Expand Down Expand Up @@ -626,7 +626,7 @@ public function validate_php_version( $php_version, $request, $param ): true|WP_
*
* @return true|WP_Error
*/
public function validate_data_center( $data_center, $request, $param ): true|WP_Error {
public function validate_data_center( $data_center, $request, $param ): bool|WP_Error {
if ( ! $data_center ) {
return true;
}
Expand All @@ -653,7 +653,7 @@ public function validate_data_center( $data_center, $request, $param ): true|WP_
*
* @return true|WP_Error
*/
public function validate_site_details( $site_details, $request, $param ): true|WP_Error {
public function validate_site_details( $site_details, $request, $param ): bool|WP_Error {
if ( ! $site_details ) {
return true;
}
Expand Down Expand Up @@ -723,7 +723,7 @@ public function get_items_permissions_check( $request ) {
*
* @return true|WP_Error
*/
public function get_item_permissions_check( $request ): true|WP_Error {
public function get_item_permissions_check( $request ): bool|WP_Error {
$post = $this->get_post( $request );
if ( is_wp_error( $post ) ) {
return $post;
Expand Down
4 changes: 2 additions & 2 deletions plugin/includes/class-wpcloud-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ protected static function log( string $message ): void {
*
* @param array|string|bool $result The result to log.
* @param int|null $padding The padding for the log.
* @return null
* @return mixed
*/
protected static function log_response( array|string|bool $result, int|null $padding = null ): null {
protected static function log_response( array|string|bool $result, int|null $padding = null ): mixed {
if ( empty( $result ) ) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/includes/class-wpcloud-site.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ public static function get_detail( int|WP_Post $post, string $key, ): mixed {
* @param array $data The data to update.
* @return true|WP_Error
*/
public static function update_detail( array $data ): true|WP_Error {
public static function update_detail( array $data ): bool|WP_Error {
error_log( print_r( $data, true ) );
$site_id = (int) ( $data['site_id'] ?? 0 );
if ( ! $site_id ) {
Expand Down
7 changes: 5 additions & 2 deletions plugin/includes/wpcloud-client.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,10 +485,13 @@ function wpcloud_client_data_centers_available( bool $include_no_preference = fa
$result = array_intersect_key( wpcloud_client_data_center_mapping(), array_flip( $response ) );

if ( $include_no_preference ) {
$available = $result;
$result = array(
'' => __( 'No Preference' ),
...$result,
);
foreach ( $available as $key => $name ) {
$result[ $key ] = $name;
}
}

return (object) $result;
Expand Down Expand Up @@ -840,7 +843,7 @@ function wpcloud_client_job_status( int $job_id ): string|WP_Error {
*
* @return true|WP_Error True if the test status matches the code and message. WP_Error on error.
*/
function wpcloud_client_test_status( int $code = 200, ?string $message = 'OK' ): true|WP_Error {
function wpcloud_client_test_status( int $code = 200, ?string $message = 'OK' ): bool|WP_Error {
$result = wpcloud_client_get( null, "test-status/$code/$message" );

if ( is_wp_error( $result ) ) {
Expand Down

0 comments on commit 8e8323e

Please sign in to comment.