From 9068f59e0e00b863068da57fa6db08a065de055d Mon Sep 17 00:00:00 2001 From: abhijitb Date: Wed, 8 Feb 2023 17:40:56 +0530 Subject: [PATCH] refactored code to use IF instead of SWITCH --- includes/RestApi/SettingsController.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/includes/RestApi/SettingsController.php b/includes/RestApi/SettingsController.php index 05fdfbcc9..6280bd095 100644 --- a/includes/RestApi/SettingsController.php +++ b/includes/RestApi/SettingsController.php @@ -220,17 +220,14 @@ public function get_current_settings() { $filtered_social_urls = array(); // handle other social urls for onboarding foreach ( $social_data['other_social_urls'] as $index => $social_url ) { - switch ( $social_url ) { - case ( preg_match( '/(?:https?:\/\/)?(www\.)?yelp\.com/', $social_url ) ? true : false ): + if ( ! empty( $social_url ) ) { + if ( preg_match( '/(?:https?:\/\/)?(www\.)?yelp\.com/', $social_url ) ) { $filtered_social_urls['yelp_url'] = $social_url; - break; - case ( preg_match( '/(?:https?:\/\/)?(www\.)?tiktok\.com/', $social_url ) ? true : false ): + } elseif ( preg_match( '/(?:https?:\/\/)?(www\.)?tiktok\.com/', $social_url ) ) { $filtered_social_urls['tiktok_url'] = $social_url; - break; - default: - // creating key value pairs for other social urls instead of indexed array + } else { $filtered_social_urls[ 'social_url_' . $index ] = $social_url; - break; + } } } $social_data['other_social_urls'] = $filtered_social_urls;