@@ -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 | } |
@@ -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(), |
@@ -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] ?? ''); |