@@ -40,7 +40,9 @@ |
||
40 | 40 | public function getJSON(): ?array |
41 | 41 | { |
42 | 42 | $data = json_decode($this->result, true); |
43 | - if (!is_array($data)) return null; |
|
43 | + if (!is_array($data)) { |
|
44 | + return null; |
|
45 | + } |
|
44 | 46 | |
45 | 47 | return $data; |
46 | 48 | } |
@@ -44,7 +44,9 @@ |
||
44 | 44 | */ |
45 | 45 | public function getAPIChallenge(): string |
46 | 46 | { |
47 | - if (!$this->_api_challenge) $this->_api_challenge = Utils::create_random_string(128); |
|
47 | + if (!$this->_api_challenge) { |
|
48 | + $this->_api_challenge = Utils::create_random_string(128); |
|
49 | + } |
|
48 | 50 | return $this->_api_challenge; |
49 | 51 | } |
50 | 52 |
@@ -25,7 +25,9 @@ |
||
25 | 25 | public static function create(Connector $connector, string $model, array $data = []): ?Model |
26 | 26 | { |
27 | 27 | $model = strtolower($model); |
28 | - if (!array_key_exists($model, self::CLASS_MAP)) return null; |
|
28 | + if (!array_key_exists($model, self::CLASS_MAP)) { |
|
29 | + return null; |
|
30 | + } |
|
29 | 31 | |
30 | 32 | $cls = self::CLASS_MAP[$model]; |
31 | 33 | return new $cls($connector, $data); |
@@ -43,7 +43,9 @@ |
||
43 | 43 | public function __get(string $service): Model |
44 | 44 | { |
45 | 45 | $obj = ObjectFactory::create($this, $service); |
46 | - if (!$obj) throw new BadMethodException("Service for `{$service}` does not exist"); |
|
46 | + if (!$obj) { |
|
47 | + throw new BadMethodException("Service for `{$service}` does not exist"); |
|
48 | + } |
|
47 | 49 | |
48 | 50 | return $obj; |
49 | 51 | } |
@@ -39,9 +39,15 @@ discard block |
||
39 | 39 | */ |
40 | 40 | public function __construct(string $url = null, array $data = [], array $headers = []) |
41 | 41 | { |
42 | - if (!is_null($url)) $this->setURL($url); |
|
43 | - foreach ($data as $name => $value) $this->addDataParam($name, $value); |
|
44 | - foreach ($headers as $name => $value) $this->addHeader($name, $value); |
|
42 | + if (!is_null($url)) { |
|
43 | + $this->setURL($url); |
|
44 | + } |
|
45 | + foreach ($data as $name => $value) { |
|
46 | + $this->addDataParam($name, $value); |
|
47 | + } |
|
48 | + foreach ($headers as $name => $value) { |
|
49 | + $this->addHeader($name, $value); |
|
50 | + } |
|
45 | 51 | } |
46 | 52 | |
47 | 53 | /** |
@@ -98,7 +104,9 @@ discard block |
||
98 | 104 | |
99 | 105 | public function removeDataParam(string $name): Curl |
100 | 106 | { |
101 | - if (array_key_exists($name, $this->_data)) unset($this->_data[$name]); |
|
107 | + if (array_key_exists($name, $this->_data)) { |
|
108 | + unset($this->_data[$name]); |
|
109 | + } |
|
102 | 110 | return $this; |
103 | 111 | } |
104 | 112 | |
@@ -127,7 +135,9 @@ discard block |
||
127 | 135 | */ |
128 | 136 | public function removeHeader(string $name): Curl |
129 | 137 | { |
130 | - if (array_key_exists($name, $this->_headers)) unset($this->_headers[$name]); |
|
138 | + if (array_key_exists($name, $this->_headers)) { |
|
139 | + unset($this->_headers[$name]); |
|
140 | + } |
|
131 | 141 | return $this; |
132 | 142 | } |
133 | 143 | |
@@ -171,13 +181,17 @@ discard block |
||
171 | 181 | $request_uri = $this->getURL(); |
172 | 182 | |
173 | 183 | // Headers |
174 | - foreach ($this->getHeaders() as $k => $v) $send_headers[] = "{$k}: {$v}"; |
|
184 | + foreach ($this->getHeaders() as $k => $v) { |
|
185 | + $send_headers[] = "{$k}: {$v}"; |
|
186 | + } |
|
175 | 187 | |
176 | 188 | // Request Data |
177 | 189 | switch ($this->getMethod()) { |
178 | 190 | case 'GET': |
179 | 191 | case 'DELETE': |
180 | - 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 | + } |
|
181 | 195 | break; |
182 | 196 | |
183 | 197 | case 'POST': |
@@ -208,7 +222,9 @@ discard block |
||
208 | 222 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
209 | 223 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
210 | 224 | |
211 | - 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 | + } |
|
212 | 228 | if (!is_null($post_data)) { |
213 | 229 | curl_setopt($ch, CURLOPT_POST, 1); |
214 | 230 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); |
@@ -218,7 +234,9 @@ discard block |
||
218 | 234 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
219 | 235 | |
220 | 236 | $response = new CurlResponse($http_code, $result); |
221 | - if ($this->_enable_cache && isset($cache_key)) self::$_cache[$cache_key] = $response; |
|
237 | + if ($this->_enable_cache && isset($cache_key)) { |
|
238 | + self::$_cache[$cache_key] = $response; |
|
239 | + } |
|
222 | 240 | |
223 | 241 | return $response; |
224 | 242 | } |
@@ -107,11 +107,15 @@ discard block |
||
107 | 107 | |
108 | 108 | $this->_max_items = (int) $data['available_items']; |
109 | 109 | |
110 | - if (empty($data['items'])) return $this->_items[$page] = []; |
|
110 | + if (empty($data['items'])) { |
|
111 | + return $this->_items[$page] = []; |
|
112 | + } |
|
111 | 113 | |
112 | 114 | foreach ($data['items'] as $item) { |
113 | 115 | $obj = ObjectFactory::make($this->getClient(), $item); |
114 | - if (!$obj) continue; |
|
116 | + if (!$obj) { |
|
117 | + continue; |
|
118 | + } |
|
115 | 119 | |
116 | 120 | $this->_items[$page][] = $obj; |
117 | 121 | } |
@@ -126,7 +130,9 @@ discard block |
||
126 | 130 | */ |
127 | 131 | public function offsetGet($offset): ?ObjectResource |
128 | 132 | { |
129 | - foreach ($this as $i => $obj) if ($i === $offset) return $obj; |
|
133 | + foreach ($this as $i => $obj) { |
|
134 | + if ($i === $offset) return $obj; |
|
135 | + } |
|
130 | 136 | return null; |
131 | 137 | } |
132 | 138 | |
@@ -157,7 +163,9 @@ discard block |
||
157 | 163 | */ |
158 | 164 | public function offsetExists($offset): bool |
159 | 165 | { |
160 | - foreach ($this as $i => $obj) if ($offset === $i) return true; |
|
166 | + foreach ($this as $i => $obj) { |
|
167 | + if ($offset === $i) return true; |
|
168 | + } |
|
161 | 169 | return false; |
162 | 170 | } |
163 | 171 | |
@@ -213,6 +221,8 @@ discard block |
||
213 | 221 | */ |
214 | 222 | public function first(): ?Model |
215 | 223 | { |
216 | - foreach ($this as $obj) return $obj; |
|
224 | + foreach ($this as $obj) { |
|
225 | + return $obj; |
|
226 | + } |
|
217 | 227 | } |
218 | 228 | } |