@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | public function fetch(int $id): ?Order |
| 52 | 52 | { |
| 53 | 53 | /** @var Order|null $fetch */ |
| 54 | - $fetch = $this->_get('api/orders/order/' . $id); |
|
| 54 | + $fetch = $this->_get('api/orders/order/'.$id); |
|
| 55 | 55 | return $fetch; |
| 56 | 56 | } |
| 57 | 57 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | public function update(int $id, array $data): ?Order |
| 79 | 79 | { |
| 80 | 80 | /** @var Order|null $post */ |
| 81 | - $post = $this->_post('api/orders/order/' . $id, $data); |
|
| 81 | + $post = $this->_post('api/orders/order/'.$id, $data); |
|
| 82 | 82 | return $post; |
| 83 | 83 | } |
| 84 | 84 | |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | // Model or Object |
| 36 | 36 | if (!array_key_exists('field_name', $value)) { |
| 37 | 37 | $this->$field = ObjectFactory::make($client, $value); |
| 38 | - } else { |
|
| 38 | + }else { |
|
| 39 | 39 | // Has One Relation - Deprecated |
| 40 | 40 | $name = $value['field_name']; |
| 41 | 41 | $this->$name = $value['field_value']; |
| 42 | 42 | $this->$field = ObjectFactory::make($client, $value['object_data']); |
| 43 | 43 | } |
| 44 | - } else { |
|
| 44 | + }else { |
|
| 45 | 45 | // HasMany / ManyMany Relation |
| 46 | 46 | $list = []; |
| 47 | 47 | foreach ($value as $item) { |
| 48 | 48 | if (ArrayLib::is_associative($item)) { |
| 49 | 49 | $list[] = ObjectFactory::make($client, $item); |
| 50 | - } else { |
|
| 50 | + }else { |
|
| 51 | 51 | $list[] = $item; |
| 52 | 52 | } |
| 53 | 53 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | $data[$key] = []; |
| 75 | 75 | /** @var self $item */ |
| 76 | 76 | foreach ($value as $item) $data[$key][] = $item->toArray(true); |
| 77 | - } else $data[$key] = $value; |
|
| 77 | + }else $data[$key] = $value; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | return $data; |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | if ($model === static::class) return new $service($this->getClient()); |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | - throw new ErrorException("Could not determine which service to use for " . static::class); |
|
| 101 | + throw new ErrorException("Could not determine which service to use for ".static::class); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | if ($this->exists()) { |
| 113 | 113 | if (!method_exists($service, 'update')) return $this; |
| 114 | 114 | return $service->update($this->ID, $this->toArray()); |
| 115 | - } else { |
|
| 115 | + }else { |
|
| 116 | 116 | if (!method_exists($service, 'create')) return $this; |
| 117 | 117 | return $service->create($this->toArray()); |
| 118 | 118 | } |
@@ -64,17 +64,24 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function toArray(bool $flatten = false): array |
| 66 | 66 | { |
| 67 | - if (!$flatten) return iterator_to_array($this->getIterator()); |
|
| 67 | + if (!$flatten) { |
|
| 68 | + return iterator_to_array($this->getIterator()); |
|
| 69 | + } |
|
| 68 | 70 | |
| 69 | 71 | $data = []; |
| 70 | 72 | |
| 71 | 73 | foreach ($this->getIterator() as $key => $value) { |
| 72 | - if ($value instanceof self) $data[$key] = $value->toArray(true); |
|
| 73 | - else if ($value instanceof ListResource) { |
|
| 74 | + if ($value instanceof self) { |
|
| 75 | + $data[$key] = $value->toArray(true); |
|
| 76 | + } else if ($value instanceof ListResource) { |
|
| 74 | 77 | $data[$key] = []; |
| 75 | 78 | /** @var self $item */ |
| 76 | - foreach ($value as $item) $data[$key][] = $item->toArray(true); |
|
| 77 | - } else $data[$key] = $value; |
|
| 79 | + foreach ($value as $item) { |
|
| 80 | + $data[$key][] = $item->toArray(true); |
|
| 81 | + } |
|
| 82 | + } else { |
|
| 83 | + $data[$key] = $value; |
|
| 84 | + } |
|
| 78 | 85 | } |
| 79 | 86 | |
| 80 | 87 | return $data; |
@@ -95,7 +102,9 @@ discard block |
||
| 95 | 102 | public function getService(): ApiService |
| 96 | 103 | { |
| 97 | 104 | foreach (ClassMap::SERVICE_MODEL as $service => $model) { |
| 98 | - if ($model === static::class) return new $service($this->getClient()); |
|
| 105 | + if ($model === static::class) { |
|
| 106 | + return new $service($this->getClient()); |
|
| 107 | + } |
|
| 99 | 108 | } |
| 100 | 109 | |
| 101 | 110 | throw new ErrorException("Could not determine which service to use for " . static::class); |
@@ -110,10 +119,14 @@ discard block |
||
| 110 | 119 | $service = $this->getService(); |
| 111 | 120 | |
| 112 | 121 | if ($this->exists()) { |
| 113 | - if (!method_exists($service, 'update')) return $this; |
|
| 122 | + if (!method_exists($service, 'update')) { |
|
| 123 | + return $this; |
|
| 124 | + } |
|
| 114 | 125 | return $service->update($this->ID, $this->toArray()); |
| 115 | 126 | } else { |
| 116 | - if (!method_exists($service, 'create')) return $this; |
|
| 127 | + if (!method_exists($service, 'create')) { |
|
| 128 | + return $this; |
|
| 129 | + } |
|
| 117 | 130 | return $service->create($this->toArray()); |
| 118 | 131 | } |
| 119 | 132 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | public function fetch(int $id): ?TaxCode |
| 23 | 23 | { |
| 24 | 24 | /** @var TaxCode|null $fetch */ |
| 25 | - $fetch = $this->_get('api/tax_code/' . $id); |
|
| 25 | + $fetch = $this->_get('api/tax_code/'.$id); |
|
| 26 | 26 | return $fetch; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | public function update(int $id, array $data): ?TaxCode |
| 50 | 50 | { |
| 51 | 51 | /** @var TaxCode|null $post */ |
| 52 | - $post = $this->_post('api/tax_code/' . $id, $data); |
|
| 52 | + $post = $this->_post('api/tax_code/'.$id, $data); |
|
| 53 | 53 | return $post; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | public function fetch(int $id): ?Location |
| 23 | 23 | { |
| 24 | 24 | /** @var Location|null $fetch */ |
| 25 | - $fetch = $this->_get('api/locations/location/' . $id); |
|
| 25 | + $fetch = $this->_get('api/locations/location/'.$id); |
|
| 26 | 26 | return $fetch; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | public function update(int $id, array $data): ?Location |
| 50 | 50 | { |
| 51 | 51 | /** @var Location|null $post */ |
| 52 | - $post = $this->_post('api/locations/location/' . $id, $data); |
|
| 52 | + $post = $this->_post('api/locations/location/'.$id, $data); |
|
| 53 | 53 | return $post; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | public function fetch(int $id): ?DeliveryZone |
| 23 | 23 | { |
| 24 | 24 | /** @var DeliveryZone|null $fetch */ |
| 25 | - $fetch = $this->_get('api/delivery-zones/zone/' . $id); |
|
| 25 | + $fetch = $this->_get('api/delivery-zones/zone/'.$id); |
|
| 26 | 26 | return $fetch; |
| 27 | 27 | } |
| 28 | 28 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | public function update(int $id, array $data): ?DeliveryZone |
| 50 | 50 | { |
| 51 | 51 | /** @var DeliveryZone|null $post */ |
| 52 | - $post = $this->_post('api/delivery-zones/zone/' . $id, $data); |
|
| 52 | + $post = $this->_post('api/delivery-zones/zone/'.$id, $data); |
|
| 53 | 53 | return $post; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | public function fetch(int $id): ?Product |
| 40 | 40 | { |
| 41 | 41 | /** @var Product|null $fetch */ |
| 42 | - $fetch = $this->_get('api/products/product/' . $id); |
|
| 42 | + $fetch = $this->_get('api/products/product/'.$id); |
|
| 43 | 43 | return $fetch; |
| 44 | 44 | } |
| 45 | 45 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | public function update(int $id, array $data): ?Product |
| 67 | 67 | { |
| 68 | 68 | /** @var Product|null $post */ |
| 69 | - $post = $this->_post('api/products/product/' . $id, $data); |
|
| 69 | + $post = $this->_post('api/products/product/'.$id, $data); |
|
| 70 | 70 | return $post; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | public function delete(int $id): bool |
| 80 | 80 | { |
| 81 | - return $this->_delete('api/products/product/' . $id); |
|
| 81 | + return $this->_delete('api/products/product/'.$id); |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | public function setStockLevel(int $id, int $quantity, Location $location): bool |
| 93 | 93 | { |
| 94 | - return (bool) $this->_post('api/products/inventory/'. $id . '/quantity', [ |
|
| 94 | + return (bool) $this->_post('api/products/inventory/'.$id.'/quantity', [ |
|
| 95 | 95 | 'location' => $location->ID, |
| 96 | 96 | 'quantity' => $quantity |
| 97 | 97 | ]); |
@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | */ |
| 15 | 15 | class App extends Connector { |
| 16 | 16 | |
| 17 | - const CODE_URL = '/oauth/code'; |
|
| 17 | + const CODE_URL = '/oauth/code'; |
|
| 18 | 18 | |
| 19 | 19 | const ACCESS_TOKEN_PARAM = 'lb_app_access_token'; |
| 20 | 20 | const API_CHALLENGE_PARAM = 'lb_app_api_challenge'; |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | public function __construct(string $app_id, string $app_secret, string $auth_domain = self::AUTH_DOMAIN) |
| 32 | 32 | { |
| 33 | 33 | if (!$app_id || !$app_secret) { |
| 34 | - throw new InvalidArgumentException(static::class . "expects an app_id and app_secret"); |
|
| 34 | + throw new InvalidArgumentException(static::class."expects an app_id and app_secret"); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | $this->setAppID($app_id); |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | if (!$response->isValid() || !$json || !array_key_exists('access_token', $json)) { |
| 165 | 165 | if (array_key_exists('error', $json)) throw new OAuthException($json['error']); |
| 166 | 166 | return ''; |
| 167 | - } else { |
|
| 167 | + }else { |
|
| 168 | 168 | $this->setAccessToken($json['access_token']); |
| 169 | 169 | |
| 170 | 170 | if (array_key_exists('store_data', $json) && |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | if (!$response->isValid() || !$json || !array_key_exists('access_token', $json)) { |
| 215 | 215 | throw new OAuthException($response->getError()); |
| 216 | - } else { |
|
| 216 | + }else { |
|
| 217 | 217 | $this->setAccessToken($json['access_token']); |
| 218 | 218 | } |
| 219 | 219 | |
@@ -115,7 +115,9 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | public function getAPIChallenge(bool $check_session = true): string |
| 117 | 117 | { |
| 118 | - if ($this->_api_challenge) return $this->_api_challenge; |
|
| 118 | + if ($this->_api_challenge) { |
|
| 119 | + return $this->_api_challenge; |
|
| 120 | + } |
|
| 119 | 121 | |
| 120 | 122 | if ($check_session && session_status() === PHP_SESSION_ACTIVE) { |
| 121 | 123 | $this->setAPIChallenge($_SESSION[self::API_CHALLENGE_PARAM] ?? ''); |
@@ -140,7 +142,9 @@ discard block |
||
| 140 | 142 | $url = URL::setGetVar('process_url', urlencode($process_url), $url); |
| 141 | 143 | $url = URL::setGetVar('error_url', urlencode($error_url), $url); |
| 142 | 144 | |
| 143 | - if ($this->getSiteKey()) $url = URL::setGetVar('site_key', $this->getSiteKey(), $url); |
|
| 145 | + if ($this->getSiteKey()) { |
|
| 146 | + $url = URL::setGetVar('site_key', $this->getSiteKey(), $url); |
|
| 147 | + } |
|
| 144 | 148 | |
| 145 | 149 | return URL::setGetVar('challenge', Utils::pack($challenge), $url); |
| 146 | 150 | } |
@@ -164,7 +168,9 @@ discard block |
||
| 164 | 168 | $json = $response->getJSON(); |
| 165 | 169 | |
| 166 | 170 | if (!$response->isValid() || !$json || !array_key_exists('access_token', $json)) { |
| 167 | - if (array_key_exists('error', $json)) throw new OAuthException($json['error']); |
|
| 171 | + if (array_key_exists('error', $json)) { |
|
| 172 | + throw new OAuthException($json['error']); |
|
| 173 | + } |
|
| 168 | 174 | return ''; |
| 169 | 175 | } else { |
| 170 | 176 | $this->setAccessToken($json['access_token']); |
@@ -186,7 +192,9 @@ discard block |
||
| 186 | 192 | */ |
| 187 | 193 | public function getAccessToken(bool $check_session = true): string |
| 188 | 194 | { |
| 189 | - if ($this->_access_token) return $this->_access_token; |
|
| 195 | + if ($this->_access_token) { |
|
| 196 | + return $this->_access_token; |
|
| 197 | + } |
|
| 190 | 198 | |
| 191 | 199 | if ($check_session && session_status() === PHP_SESSION_ACTIVE) { |
| 192 | 200 | $this->setAccessToken($_SESSION[self::ACCESS_TOKEN_PARAM] ?? ''); |
@@ -60,7 +60,9 @@ discard block |
||
| 60 | 60 | public function __get(string $service): ?ApiService |
| 61 | 61 | { |
| 62 | 62 | $obj = ServiceFactory::inst($this, $service); |
| 63 | - if (!$obj) throw new BadMethodException("Service for `{$service}` does not exist"); |
|
| 63 | + if (!$obj) { |
|
| 64 | + throw new BadMethodException("Service for `{$service}` does not exist"); |
|
| 65 | + } |
|
| 64 | 66 | |
| 65 | 67 | return $obj; |
| 66 | 68 | } |
@@ -118,7 +120,9 @@ discard block |
||
| 118 | 120 | */ |
| 119 | 121 | public function getHost(): ?string |
| 120 | 122 | { |
| 121 | - if (!$this->getActiveSite(true)) return null; |
|
| 123 | + if (!$this->getActiveSite(true)) { |
|
| 124 | + return null; |
|
| 125 | + } |
|
| 122 | 126 | return $this->_host; |
| 123 | 127 | } |
| 124 | 128 | |
@@ -127,7 +131,9 @@ discard block |
||
| 127 | 131 | */ |
| 128 | 132 | public function getSiteKey(): ?string |
| 129 | 133 | { |
| 130 | - if (!$this->getActiveSite(true)) return null; |
|
| 134 | + if (!$this->getActiveSite(true)) { |
|
| 135 | + return null; |
|
| 136 | + } |
|
| 131 | 137 | return $this->_site_key; |
| 132 | 138 | } |
| 133 | 139 | |
@@ -151,7 +157,9 @@ discard block |
||
| 151 | 157 | $curl->addHeader('Host', $this->getHost()); |
| 152 | 158 | |
| 153 | 159 | foreach ($this->getAuthHeaders() as $header => $value) { |
| 154 | - if ($value) $curl->addHeader($header, $value); |
|
| 160 | + if ($value) { |
|
| 161 | + $curl->addHeader($header, $value); |
|
| 162 | + } |
|
| 155 | 163 | } |
| 156 | 164 | |
| 157 | 165 | return $curl->curl_json(); |
@@ -163,8 +171,12 @@ discard block |
||
| 163 | 171 | */ |
| 164 | 172 | public function getAuthHeaders(): array |
| 165 | 173 | { |
| 166 | - if (!$this->getAccessToken()) $this->fetchAccessToken(); |
|
| 167 | - if (!$this->getAccessToken()) throw new OAuthException("Access token has not been retreived"); |
|
| 174 | + if (!$this->getAccessToken()) { |
|
| 175 | + $this->fetchAccessToken(); |
|
| 176 | + } |
|
| 177 | + if (!$this->getAccessToken()) { |
|
| 178 | + throw new OAuthException("Access token has not been retreived"); |
|
| 179 | + } |
|
| 168 | 180 | |
| 169 | 181 | return [ |
| 170 | 182 | 'access-token' => $this->getAccessToken(), |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | namespace Lifeboat; |
| 4 | 4 | |
| 5 | -require_once __DIR__ . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'functions.php'; |
|
| 5 | +require_once __DIR__.DIRECTORY_SEPARATOR.'includes'.DIRECTORY_SEPARATOR.'functions.php'; |
|
| 6 | 6 | |
| 7 | 7 | use Lifeboat\Exceptions\BadMethodException; |
| 8 | 8 | use Lifeboat\Exceptions\OAuthException; |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | public function curl_api(string $url, string $method = 'GET', array $data = [], array $headers = []): CurlResponse |
| 143 | 143 | { |
| 144 | 144 | $uri = URL::is_absolute_url($url) ? $url |
| 145 | - : 'https://' . rtrim($this->getHost(), '/') . '/' . ltrim($url, '/'); |
|
| 145 | + : 'https://'.rtrim($this->getHost(), '/').'/'.ltrim($url, '/'); |
|
| 146 | 146 | |
| 147 | 147 | $curl = new Curl($uri, $data, $headers); |
| 148 | 148 | |
@@ -178,6 +178,6 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | protected function auth_url(string $path): string |
| 180 | 180 | { |
| 181 | - return rtrim($this->_auth_domain, '/') . '/' . ltrim($path, '/'); |
|
| 181 | + return rtrim($this->_auth_domain, '/').'/'.ltrim($path, '/'); |
|
| 182 | 182 | } |
| 183 | 183 | } |
@@ -90,7 +90,7 @@ |
||
| 90 | 90 | $challenge = self::get_app()->getAPIChallenge(); |
| 91 | 91 | |
| 92 | 92 | // Redirect to the auth URL |
| 93 | - header("Location: " . self::get_app()->getAuthURL($process, $error, $challenge)); |
|
| 93 | + header("Location: ".self::get_app()->getAuthURL($process, $error, $challenge)); |
|
| 94 | 94 | flush(); |
| 95 | 95 | die(); |
| 96 | 96 | } |