@@ -93,6 +93,6 @@ |
||
| 93 | 93 | default: return ''; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - return ($value !== 0) ? number_format($value, 2) . $this->Currency : '-'; |
|
| 96 | + return ($value !== 0) ? number_format($value, 2).$this->Currency : '-'; |
|
| 97 | 97 | } |
| 98 | 98 | } |
@@ -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 | |
@@ -138,7 +138,7 @@ |
||
| 138 | 138 | // the current user has access to so that he/she can switch |
| 139 | 139 | // between them |
| 140 | 140 | return $this->renderWith('[[Your template]]', [ |
| 141 | - 'Options' => $options |
|
| 141 | + 'Options' => $options |
|
| 142 | 142 | ]); |
| 143 | 143 | |
| 144 | 144 | |
@@ -130,7 +130,7 @@ |
||
| 130 | 130 | foreach ($sites as $site) { |
| 131 | 131 | $options[] = [ |
| 132 | 132 | 'Label' => $site['domain'], |
| 133 | - 'URL' => $this->Link('select') . '?site_key=' . $site['site_key'] |
|
| 133 | + 'URL' => $this->Link('select').'?site_key='.$site['site_key'] |
|
| 134 | 134 | ]; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -115,7 +115,9 @@ |
||
| 115 | 115 | $sites = $this->app->getSites(); |
| 116 | 116 | |
| 117 | 117 | // If the user doesn't have access to any Lifeboat site force a re-auth |
| 118 | - if (count($sites) < 1) return $this->reloadAuth(); |
|
| 118 | + if (count($sites) < 1) { |
|
| 119 | + return $this->reloadAuth(); |
|
| 120 | + } |
|
| 119 | 121 | |
| 120 | 122 | // If the user only has access to one Lifeboat site then automatically use that |
| 121 | 123 | if (count($sites) === 1) { |
@@ -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] ?? ''); |
@@ -162,7 +164,9 @@ discard block |
||
| 162 | 164 | $json = $response->getJSON(); |
| 163 | 165 | |
| 164 | 166 | if (!$response->isValid() || !$json || !array_key_exists('access_token', $json)) { |
| 165 | - if (array_key_exists('error', $json)) throw new OAuthException($json['error']); |
|
| 167 | + if (array_key_exists('error', $json)) { |
|
| 168 | + throw new OAuthException($json['error']); |
|
| 169 | + } |
|
| 166 | 170 | return ''; |
| 167 | 171 | } else { |
| 168 | 172 | $this->setAccessToken($json['access_token']); |
@@ -184,7 +188,9 @@ discard block |
||
| 184 | 188 | */ |
| 185 | 189 | public function getAccessToken(bool $check_session = true): string |
| 186 | 190 | { |
| 187 | - if ($this->_access_token) return $this->_access_token; |
|
| 191 | + if ($this->_access_token) { |
|
| 192 | + return $this->_access_token; |
|
| 193 | + } |
|
| 188 | 194 | |
| 189 | 195 | if ($check_session && session_status() === PHP_SESSION_ACTIVE) { |
| 190 | 196 | $this->setAccessToken($_SESSION[self::ACCESS_TOKEN_PARAM] ?? ''); |