From 5b50afdcafd150186ea5c7b0e1cad98065590b35 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 28 Aug 2026 18:44:28 +0000
Subject: [PATCH] =A few more phpStorm suggestions, mainly in PHPDocs
---
inc/integrations/services/GoogleMyBusinessOld.php | 164 ++++++++++++++++++++++++++----------------------------
1 files changed, 78 insertions(+), 86 deletions(-)
diff --git a/inc/integrations/services/GoogleMyBusinessOld.php b/inc/integrations/services/GoogleMyBusinessOld.php
index 348700f..41fcbe4 100644
--- a/inc/integrations/services/GoogleMyBusinessOld.php
+++ b/inc/integrations/services/GoogleMyBusinessOld.php
@@ -1,7 +1,10 @@
<?php
namespace JVBase\integrations\services;
+use Exception;
use JVBase\integrations\Integrations;
use JVBase\meta\Meta;
+use WP_Error;
+use WP_Post;
if (!defined('ABSPATH')) {
exit;
@@ -143,9 +146,7 @@
]
);
- if (JVB_TESTING) {
- $this->cache->flush();
- }
+
}
protected function initialize(): void
@@ -174,7 +175,7 @@
try {
$accounts = $this->getAccounts(true);
return !empty($accounts);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
return false;
}
}
@@ -186,7 +187,7 @@
{
// Google APIs return errors in this format:
// {"error": {"code": 401, "message": "...", "status": "UNAUTHENTICATED"}}
- return isset($response['error']) && isset($response['error']['code']);
+ return isset($response['error']['code']);
}
protected function getRequestHeaders(): array
@@ -214,7 +215,7 @@
return $credentials;
}
- public function handleTheSavePost(int $postID, \WP_Post $post, bool $update, array $settings):void
+ public function handleTheSavePost(int $postID, WP_Post $post, bool $update, array $settings):void
{
if (!$this->hasOAuthCredentials()) {
@@ -236,33 +237,18 @@
try {
$gmb = (array_key_exists('user', $data) && $data['user'] !== 0) ? $this->getInstance((int)$data['user']) : $this;
$gmb->ensureInitialized();
- switch ($operation->type) {
- case 'gmb_create_menu_item':
- case 'gmb_update_menu_item':
- case 'gmb_menu_update':
- case 'gmb_menu_update_' . $this->userID:
- return $gmb->processMenuUpdate($operation, $data);
- case 'gmb_create_event':
- case 'gmb_update_event':
- return $gmb->syncEventPost($operation, $data);
- case 'gmb_create_offer':
- case 'gmb_update_offer':
- return $gmb->syncOfferPost($operation, $data);
- case 'gmb_create_post':
- case 'gmb_update_post':
- return $gmb->syncStandardPost($operation, $data);
- case 'gmb_specialHours':
- return $gmb->setSpecialHours($data['date'], $data['data']);
- case 'gmb_business_hours':
- return $gmb->updateBusinessHours($data);
- case 'gmb_business_info':
- return $gmb->updateBusinessInfo($data);
- case 'gmb_update_attributes':
- return $gmb->updateAttributes($data);
- default:
- return $result;
- }
- } catch (\Exception $e) {
+ return match ($operation->type) {
+ 'gmb_create_menu_item', 'gmb_update_menu_item', 'gmb_menu_update', 'gmb_menu_update_' . $this->userID => $gmb->processMenuUpdate($operation, $data),
+ 'gmb_create_event', 'gmb_update_event' => $gmb->syncEventPost($operation, $data),
+ 'gmb_create_offer', 'gmb_update_offer' => $gmb->syncOfferPost($operation, $data),
+ 'gmb_create_post', 'gmb_update_post' => $gmb->syncStandardPost($operation, $data),
+ 'gmb_specialHours' => $gmb->setSpecialHours($data['date'], $data['data']),
+ 'gmb_business_hours' => $gmb->updateBusinessHours($data),
+ 'gmb_business_info' => $gmb->updateBusinessInfo($data),
+ 'gmb_update_attributes' => $gmb->updateAttributes($data),
+ default => $result,
+ };
+ } catch (Exception $e) {
error_log('[GMB] Operation processing error: ' . $e->getMessage());
return [
'success' => false,
@@ -479,7 +465,7 @@
'result' => (is_array($result)) ? array_merge($result, ['menu'=>$menu_data]) : ['menu'=>$menu_data],
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
error_log('GMB Menu Update Error: ' . $e->getMessage());
return [
'success' => false,
@@ -516,7 +502,7 @@
}
}
}
- } catch (\Exception $e) {
+ } catch (Exception $e) {
error_log('[GMB] Error finding location resource name: ' . $e->getMessage());
}
@@ -698,7 +684,7 @@
$location_name = $this->getSelectedLocationResourceName();
if (empty($patch_data)) {
- throw new \Exception('No valid fields to update');
+ throw new Exception('No valid fields to update');
}
// Create updateMask from the fields being updated
@@ -716,7 +702,7 @@
'result' => $response
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'updateBusinessInfo'
]);
@@ -732,7 +718,6 @@
* Update business attributes (amenities, services, etc.)
*/
/**
- * @param string $location_name
* @param array $attributes
* @return array As expected by OperationQueue.php processOperation
*/
@@ -758,7 +743,7 @@
'result' => $response
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'updateAttributes'
]);
@@ -919,7 +904,7 @@
try {
// Validate required fields
if (empty($post_data['summary'])) {
- throw new \Exception('Post summary is required');
+ throw new Exception('Post summary is required');
}
// Build the post object according to API docs
@@ -960,7 +945,7 @@
return $response;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'createPost'
]);
@@ -1000,7 +985,7 @@
return !empty($response);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'updatePost'
@@ -1017,7 +1002,7 @@
try {
$this->makeRequest('DELETE', "/v1/accounts/{$post_name}", [], 'posts');
return true;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'deletePost'
@@ -1033,6 +1018,8 @@
*
* @param array $hours Array of periods with open/close times per day
* @return array Success status, according to OperationQueue.php
+ * @throws Exception
+ * @throws Exception
*/
public function updateBusinessHours(array $hours): array
{
@@ -1043,7 +1030,7 @@
if (empty($location_name)) {
error_log('[GMB] ERROR: No location selected or found');
- throw new \Exception('No location selected. Please select a location first.');
+ throw new Exception('No location selected. Please select a location first.');
}
try {
@@ -1052,7 +1039,7 @@
if (empty($periods)) {
error_log('[GMB] ERROR: No valid periods found after validation');
- throw new \Exception('No valid business hours provided');
+ throw new Exception('No valid business hours provided');
}
$update_data = [
@@ -1088,7 +1075,7 @@
'result' => $response
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'updateBusinessHours'
]);
@@ -1171,6 +1158,8 @@
* @param string $date
* @param array{open?: float, closed?:float, isClosed?: bool, location?: string} $options
* @return array Operation Queue [ 'success' => true/false, 'result' => $results]
+ * @throws Exception
+ * @throws Exception
*/
public function setSpecialHours(string $date, array $options = []):array
{
@@ -1178,7 +1167,7 @@
$location_name = $this->getSelectedLocationResourceName();
if (empty($location_name)) {
- throw new \Exception('No location selected. Please select a location first.');
+ throw new Exception('No location selected. Please select a location first.');
}
try {
@@ -1207,8 +1196,8 @@
}
}
- if (!empty($options['close'])) {
- $close_time = $this->formatTime($options['close']);
+ if (!empty($options['closed'])) {
+ $close_time = $this->formatTime($options['closed']);
if ($close_time) {
$special_hour_period['closeTime'] = $close_time;
}
@@ -1253,7 +1242,7 @@
'results' => $response
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'setSpecialHours'
]);
@@ -1282,7 +1271,7 @@
return $response !== null;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'clearSpecialHours'
@@ -1338,7 +1327,7 @@
];
if (!in_array($category, $valid_categories)) {
- throw new \Exception('Invalid photo category: ' . $category);
+ throw new Exception('Invalid photo category: ' . $category);
}
$mediaKey = $this->getImageMediaKey($imgID);
if ($mediaKey) {
@@ -1366,7 +1355,7 @@
return $mediaKey;
}
return null;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'uploadPhotoFromUrl'
]);
@@ -1420,15 +1409,17 @@
* Get reviews for the current location
* @param int $page_size Number of reviews to fetch (max 50)
* @return array|null
+ * @throws Exception
+ * @throws Exception
*/
public function getReviews(int $page_size = 5): ?array
{
$this->ensureInitialized();
if (!$this->location) {
- throw new \Exception('No location selected');
+ throw new Exception('No location selected');
}
if (!$this->account_id) {
- throw new \Exception('No account configured');
+ throw new Exception('No account configured');
}
$location = $this->getSelectedLocationResourceName();
@@ -1459,7 +1450,7 @@
return $reviews;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'getReviews'
]);
@@ -1494,7 +1485,7 @@
return null;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError('Failed to get reviews view URL: ' . $e->getMessage(), [
'method' => 'getReviewsViewUrl'
]);
@@ -1529,7 +1520,7 @@
return null;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError('Failed to get review URL: ' . $e->getMessage(), [
'method' => 'getReviewUrl'
]);
@@ -1557,9 +1548,9 @@
try {
$response = $this->getRequest("/v1/{$account_name}/locations", $params,'accounts', $ttl, $force);
- return isset($response['locations']) ? $response['locations'] : [];
+ return $response['locations'] ?? [];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
error_log('[GMB] Error getting locations for ' . $account_name . ': ' . $e->getMessage());
return [];
}
@@ -1612,7 +1603,7 @@
'message' => 'No accounts found'
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
error_log('[GMB] Error refreshing stored data: ' . $e->getMessage());
return [
'success' => false,
@@ -1706,7 +1697,7 @@
?>
</div>
<?php
- } catch (\Exception $e) {
+ } catch (Exception $e) {
echo '<p>Error loading business locations.</p>';
}
}
@@ -1840,7 +1831,7 @@
}
if (!$selected_account) {
- throw new \Exception('Invalid account selected');
+ throw new Exception('Invalid account selected');
}
// Update credentials with selected account
@@ -1855,7 +1846,7 @@
'reload' => true
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError('Failed to select account', [
'error' => $e->getMessage(),
'data' => $data
@@ -1884,12 +1875,12 @@
}
if (empty($location_name)) {
- throw new \Exception('No location selected');
+ throw new Exception('No location selected');
}
// Verify this is a valid location for the selected account
if (empty($this->credentials['account'])) {
- throw new \Exception('No account selected. Please select an account first.');
+ throw new Exception('No account selected. Please select an account first.');
}
$locations = $this->getLocations($this->credentials['account']);
@@ -1904,7 +1895,7 @@
}
if (!$valid_location) {
- throw new \Exception('Invalid location selected');
+ throw new Exception('Invalid location selected');
}
// Update credentials with selected location
@@ -1922,7 +1913,7 @@
'reload' => false // No need to reload for location selection
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError('Failed to select location', [
'error' => $e->getMessage(),
'data' => $data
@@ -1950,7 +1941,7 @@
'has_refresh_token' => !empty($this->credentials['refresh_token'])
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
return [
'success' => false,
'valid' => false,
@@ -2065,7 +2056,7 @@
public function getFoodMenus(): ?array
{
if (!$this->credentials['location']) {
- throw new \Exception('No location selected. Please select a location first.');
+ throw new Exception('No location selected. Please select a location first.');
}
$response = $this->getRequest(
@@ -2082,7 +2073,7 @@
public function updateFoodMenus(array $menus): bool
{
if (!$this->credentials['location']) {
- throw new \Exception('No location selected. Please select a location first.');
+ throw new Exception('No location selected. Please select a location first.');
}
try {
@@ -2104,7 +2095,7 @@
]);
return !empty($response);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'updateFoodMenus'
]);
@@ -2166,7 +2157,7 @@
{
// Extract mediaKey from format: accounts/{accountId}/locations/{locationId}/media/{mediaKey}
$parts = explode('/media/', $mediaResourceName);
- return isset($parts[1]) ? $parts[1] : '';
+ return $parts[1] ?? '';
}
/**
@@ -2175,7 +2166,7 @@
public function getLocationMedia(): array
{
if (!$this->credentials['location']) {
- throw new \Exception('No location selected. Please select a location first.');
+ throw new Exception('No location selected. Please select a location first.');
}
try {
@@ -2186,7 +2177,7 @@
);
return $response['mediaItems'] ?? [];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError('Failed to get location media: ' . $e->getMessage());
return [];
}
@@ -2214,7 +2205,7 @@
'cached' => !$force
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
return new WP_Error('failure', 'Something went wrong: '.$e->getMessage());
}
}
@@ -2235,7 +2226,7 @@
}
if (empty($selected_account)) {
- throw new \Exception('No account selected');
+ throw new Exception('No account selected');
}
// Save the selected account
@@ -2259,7 +2250,7 @@
'reload' => true // Trigger page refresh to show location dropdown
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError('Failed to update location', [
'error' => $e->getMessage(),
'data' => $data
@@ -2279,7 +2270,7 @@
$this->cache->flush();
return true;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
error_log('[GMB] Error clearing stored data: ' . $e->getMessage());
return false;
}
@@ -2288,13 +2279,13 @@
public function getPriceLists(): ?array
{
if (!$this->credentials['location']) {
- throw new \Exception('No location selected. Please select a location first.');
+ throw new Exception('No location selected. Please select a location first.');
}
try {
$location_data = $this->getLocation($this->credentials['location']);
return $location_data['priceLists'] ?? [];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'getPriceLists'
@@ -2389,7 +2380,7 @@
$location_name = $this->getSelectedLocationResourceName();
if (empty($location_name)) {
- throw new \Exception('No location selected. Please select a location first.');
+ throw new Exception('No location selected. Please select a location first.');
}
$post_data = [
@@ -2416,7 +2407,7 @@
$location_name = $this->getSelectedLocationResourceName();
if (empty($location_name)) {
- throw new \Exception('No location selected. Please select a location first.');
+ throw new Exception('No location selected. Please select a location first.');
}
return $this->updateBusinessInfo($location_name, $updates);
@@ -2432,7 +2423,7 @@
$location_name = $this->getSelectedLocationResourceName();
if (empty($location_name)) {
- throw new \Exception('No location selected. Please select a location first.');
+ throw new Exception('No location selected. Please select a location first.');
}
return $this->clearSpecialHours($location_name);
@@ -2482,7 +2473,8 @@
$gmb_item = $this->buildMenuItem($item, $defaults);
// Get section for this item
- $categories = wp_get_post_terms($item->ID, BASE.'section');
+ $categories = wp_get_post_terms($item->ID, 'product_cat');
+// $categories = wp_get_post_terms($item->ID, BASE.'section');
$section_slug = !empty($categories) ?
$categories[0]->slug :
'menu-items';
@@ -2530,7 +2522,7 @@
return [$gmb_menu]; // GMB expects an array of menus
}
- protected function buildMenuItem(\WP_Post $item, array $defaults):array
+ protected function buildMenuItem(WP_Post $item, array $defaults):array
{
$meta = Meta::forPost($item->ID);
$fields = $this->mappedMenuFields($item->post_type);
--
Gitblit v1.10.0