@@ -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 | } |
@@ -39,8 +39,12 @@ discard block |
||
| 39 | 39 | public function __construct(string $url, array $data = [], array $headers = []) |
| 40 | 40 | { |
| 41 | 41 | $this->setURL($url); |
| 42 | - foreach ($data as $name => $value) $this->addDataParam($name, $value); |
|
| 43 | - foreach ($headers as $name => $value) $this->addHeader($name, $value); |
|
| 42 | + foreach ($data as $name => $value) { |
|
| 43 | + $this->addDataParam($name, $value); |
|
| 44 | + } |
|
| 45 | + foreach ($headers as $name => $value) { |
|
| 46 | + $this->addHeader($name, $value); |
|
| 47 | + } |
|
| 44 | 48 | } |
| 45 | 49 | |
| 46 | 50 | /** |
@@ -99,7 +103,9 @@ discard block |
||
| 99 | 103 | |
| 100 | 104 | public function removeDataParam(string $name): Curl |
| 101 | 105 | { |
| 102 | - if (array_key_exists($name, $this->_data)) unset($this->_data[$name]); |
|
| 106 | + if (array_key_exists($name, $this->_data)) { |
|
| 107 | + unset($this->_data[$name]); |
|
| 108 | + } |
|
| 103 | 109 | return $this; |
| 104 | 110 | } |
| 105 | 111 | |
@@ -128,7 +134,9 @@ discard block |
||
| 128 | 134 | */ |
| 129 | 135 | public function removeHeader(string $name): Curl |
| 130 | 136 | { |
| 131 | - if (array_key_exists($name, $this->_headers)) unset($this->_headers[$name]); |
|
| 137 | + if (array_key_exists($name, $this->_headers)) { |
|
| 138 | + unset($this->_headers[$name]); |
|
| 139 | + } |
|
| 132 | 140 | return $this; |
| 133 | 141 | } |
| 134 | 142 | |
@@ -173,13 +181,17 @@ discard block |
||
| 173 | 181 | $request_uri = $this->getURL(); |
| 174 | 182 | |
| 175 | 183 | // Headers |
| 176 | - foreach ($this->getHeaders() as $k => $v) $send_headers[] = "{$k}: {$v}"; |
|
| 184 | + foreach ($this->getHeaders() as $k => $v) { |
|
| 185 | + $send_headers[] = "{$k}: {$v}"; |
|
| 186 | + } |
|
| 177 | 187 | |
| 178 | 188 | // Request Data |
| 179 | 189 | switch ($this->getMethod()) { |
| 180 | 190 | case 'GET': |
| 181 | 191 | case 'DELETE': |
| 182 | - foreach ($this->getDataParams() as $name => $value) $request_uri = URL::setGetVar($name, $value, $request_uri); |
|
| 192 | + foreach ($this->getDataParams() as $name => $value) { |
|
| 193 | + $request_uri = URL::setGetVar($name, $value, $request_uri); |
|
| 194 | + } |
|
| 183 | 195 | break; |
| 184 | 196 | |
| 185 | 197 | case 'POST': |
@@ -210,7 +222,9 @@ discard block |
||
| 210 | 222 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
| 211 | 223 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
| 212 | 224 | |
| 213 | - if (!empty($send_headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
|
| 225 | + if (!empty($send_headers)) { |
|
| 226 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
|
| 227 | + } |
|
| 214 | 228 | if (!is_null($post_data)) { |
| 215 | 229 | curl_setopt($ch, CURLOPT_POST, 1); |
| 216 | 230 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); |
@@ -219,10 +233,14 @@ discard block |
||
| 219 | 233 | $result = curl_exec($ch); |
| 220 | 234 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 221 | 235 | |
| 222 | - if ($http_code === 401 && $retry_on_401) return $this->curl(false); |
|
| 236 | + if ($http_code === 401 && $retry_on_401) { |
|
| 237 | + return $this->curl(false); |
|
| 238 | + } |
|
| 223 | 239 | |
| 224 | 240 | $response = new CurlResponse((int) $http_code, (string) $result); |
| 225 | - if ($this->_enable_cache && isset($cache_key)) self::$_cache[$cache_key] = $response; |
|
| 241 | + if ($this->_enable_cache && isset($cache_key)) { |
|
| 242 | + self::$_cache[$cache_key] = $response; |
|
| 243 | + } |
|
| 226 | 244 | |
| 227 | 245 | return $response; |
| 228 | 246 | } |
@@ -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) { |
@@ -58,7 +58,9 @@ discard block |
||
| 58 | 58 | public function __get(string $service): ?ApiService |
| 59 | 59 | { |
| 60 | 60 | $obj = ServiceFactory::inst($this, $service); |
| 61 | - if (!$obj) throw new BadMethodException("Service for `{$service}` does not exist"); |
|
| 61 | + if (!$obj) { |
|
| 62 | + throw new BadMethodException("Service for `{$service}` does not exist"); |
|
| 63 | + } |
|
| 62 | 64 | |
| 63 | 65 | return $obj; |
| 64 | 66 | } |
@@ -143,7 +145,9 @@ discard block |
||
| 143 | 145 | */ |
| 144 | 146 | public function getHost(): ?string |
| 145 | 147 | { |
| 146 | - if (!$this->getActiveSite(true)) return null; |
|
| 148 | + if (!$this->getActiveSite(true)) { |
|
| 149 | + return null; |
|
| 150 | + } |
|
| 147 | 151 | return $this->_host; |
| 148 | 152 | } |
| 149 | 153 | |
@@ -152,7 +156,9 @@ discard block |
||
| 152 | 156 | */ |
| 153 | 157 | public function getSiteKey(): ?string |
| 154 | 158 | { |
| 155 | - if (!$this->getActiveSite(true)) return null; |
|
| 159 | + if (!$this->getActiveSite(true)) { |
|
| 160 | + return null; |
|
| 161 | + } |
|
| 156 | 162 | return $this->_site_key; |
| 157 | 163 | } |
| 158 | 164 | |