From a9654f00c8fbc9934289d761843ddd071025013f Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 28 Aug 2026 17:20:28 +0000
Subject: [PATCH] =PHPStorm Code Inspection: fixed class reference errors (from getting rid of JVB() and replacing with direct class::getInstance; as well as general code sniffing, etc
---
inc/integrations/services/GoogleMyBusinessOld.php | 150 +++++++++++++++++++++++---------------------------
1 files changed, 69 insertions(+), 81 deletions(-)
diff --git a/inc/integrations/services/GoogleMyBusinessOld.php b/inc/integrations/services/GoogleMyBusinessOld.php
index 111845f..e4af35f 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;
@@ -172,7 +175,7 @@
try {
$accounts = $this->getAccounts(true);
return !empty($accounts);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
return false;
}
}
@@ -184,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
@@ -212,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()) {
@@ -234,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,
@@ -477,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,
@@ -514,7 +502,7 @@
}
}
}
- } catch (\Exception $e) {
+ } catch (Exception $e) {
error_log('[GMB] Error finding location resource name: ' . $e->getMessage());
}
@@ -696,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
@@ -714,7 +702,7 @@
'result' => $response
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'updateBusinessInfo'
]);
@@ -756,7 +744,7 @@
'result' => $response
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'updateAttributes'
]);
@@ -917,7 +905,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
@@ -958,7 +946,7 @@
return $response;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'createPost'
]);
@@ -998,7 +986,7 @@
return !empty($response);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'updatePost'
@@ -1015,7 +1003,7 @@
try {
$this->makeRequest('DELETE', "/v1/accounts/{$post_name}", [], 'posts');
return true;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'deletePost'
@@ -1041,7 +1029,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 {
@@ -1050,7 +1038,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 = [
@@ -1086,7 +1074,7 @@
'result' => $response
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'updateBusinessHours'
]);
@@ -1176,7 +1164,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 {
@@ -1205,8 +1193,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;
}
@@ -1251,7 +1239,7 @@
'results' => $response
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'setSpecialHours'
]);
@@ -1280,7 +1268,7 @@
return $response !== null;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'clearSpecialHours'
@@ -1336,7 +1324,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) {
@@ -1364,7 +1352,7 @@
return $mediaKey;
}
return null;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'uploadPhotoFromUrl'
]);
@@ -1423,10 +1411,10 @@
{
$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();
@@ -1457,7 +1445,7 @@
return $reviews;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'getReviews'
]);
@@ -1492,7 +1480,7 @@
return null;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError('Failed to get reviews view URL: ' . $e->getMessage(), [
'method' => 'getReviewsViewUrl'
]);
@@ -1527,7 +1515,7 @@
return null;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError('Failed to get review URL: ' . $e->getMessage(), [
'method' => 'getReviewUrl'
]);
@@ -1555,9 +1543,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 [];
}
@@ -1610,7 +1598,7 @@
'message' => 'No accounts found'
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
error_log('[GMB] Error refreshing stored data: ' . $e->getMessage());
return [
'success' => false,
@@ -1704,7 +1692,7 @@
?>
</div>
<?php
- } catch (\Exception $e) {
+ } catch (Exception $e) {
echo '<p>Error loading business locations.</p>';
}
}
@@ -1838,7 +1826,7 @@
}
if (!$selected_account) {
- throw new \Exception('Invalid account selected');
+ throw new Exception('Invalid account selected');
}
// Update credentials with selected account
@@ -1853,7 +1841,7 @@
'reload' => true
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError('Failed to select account', [
'error' => $e->getMessage(),
'data' => $data
@@ -1882,12 +1870,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']);
@@ -1902,7 +1890,7 @@
}
if (!$valid_location) {
- throw new \Exception('Invalid location selected');
+ throw new Exception('Invalid location selected');
}
// Update credentials with selected location
@@ -1920,7 +1908,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
@@ -1948,7 +1936,7 @@
'has_refresh_token' => !empty($this->credentials['refresh_token'])
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
return [
'success' => false,
'valid' => false,
@@ -2063,7 +2051,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(
@@ -2080,7 +2068,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 {
@@ -2102,7 +2090,7 @@
]);
return !empty($response);
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError($e->getMessage(), [
'method' => 'updateFoodMenus'
]);
@@ -2164,7 +2152,7 @@
{
// Extract mediaKey from format: accounts/{accountId}/locations/{locationId}/media/{mediaKey}
$parts = explode('/media/', $mediaResourceName);
- return isset($parts[1]) ? $parts[1] : '';
+ return $parts[1] ?? '';
}
/**
@@ -2173,7 +2161,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 {
@@ -2184,7 +2172,7 @@
);
return $response['mediaItems'] ?? [];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
$this->logError('Failed to get location media: ' . $e->getMessage());
return [];
}
@@ -2212,7 +2200,7 @@
'cached' => !$force
];
- } catch (\Exception $e) {
+ } catch (Exception $e) {
return new WP_Error('failure', 'Something went wrong: '.$e->getMessage());
}
}
@@ -2233,7 +2221,7 @@
}
if (empty($selected_account)) {
- throw new \Exception('No account selected');
+ throw new Exception('No account selected');
}
// Save the selected account
@@ -2257,7 +2245,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
@@ -2277,7 +2265,7 @@
$this->cache->flush();
return true;
- } catch (\Exception $e) {
+ } catch (Exception $e) {
error_log('[GMB] Error clearing stored data: ' . $e->getMessage());
return false;
}
@@ -2286,13 +2274,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'
@@ -2387,7 +2375,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 = [
@@ -2414,7 +2402,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);
@@ -2430,7 +2418,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);
@@ -2529,7 +2517,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