@@ -20,13 +20,13 @@ discard block |
||
20 | 20 | public static function setGetVar(string $key, string $value, string $url): string |
21 | 21 | { |
22 | 22 | if (!self::is_absolute_url($url)) { |
23 | - $url = 'http://dummy.com/' . ltrim($url, '/'); |
|
23 | + $url = 'http://dummy.com/'.ltrim($url, '/'); |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | // try to parse uri |
27 | 27 | $parts = parse_url($url); |
28 | 28 | if (empty($parts)) { |
29 | - throw new InvalidArgumentException("Can't parse URL: " . $url); |
|
29 | + throw new InvalidArgumentException("Can't parse URL: ".$url); |
|
30 | 30 | } |
31 | 31 | |
32 | 32 | // Parse params and add new variable |
@@ -40,18 +40,18 @@ discard block |
||
40 | 40 | // Generate URI segments and formatting |
41 | 41 | $scheme = (array_key_exists('scheme', $parts)) ? $parts['scheme'] : 'http'; |
42 | 42 | $user = (array_key_exists('user', $parts)) ? $parts['user'] : ''; |
43 | - $port = (array_key_exists('port', $parts) && $parts['port']) ? ':' . $parts['port'] : ''; |
|
43 | + $port = (array_key_exists('port', $parts) && $parts['port']) ? ':'.$parts['port'] : ''; |
|
44 | 44 | |
45 | 45 | if ($user != '') { |
46 | 46 | // format in either user:[email protected] or [email protected] |
47 | - $user .= (array_key_exists('pass', $parts) && $parts['pass']) ? ':' . $parts['pass'] . '@' : ''; |
|
47 | + $user .= (array_key_exists('pass', $parts) && $parts['pass']) ? ':'.$parts['pass'].'@' : ''; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | // handle URL params which are existing / new |
51 | - $params = ($params) ? '?' . http_build_query($params) : ''; |
|
51 | + $params = ($params) ? '?'.http_build_query($params) : ''; |
|
52 | 52 | |
53 | 53 | // Recompile URI segments |
54 | - $newUri = $scheme . '://' . $user . $parts['host'] . $port . ($parts['path'] ?? '') . $params; |
|
54 | + $newUri = $scheme.'://'.$user.$parts['host'].$port.($parts['path'] ?? '').$params; |
|
55 | 55 | |
56 | 56 | return str_replace('http://dummy.com', '', $newUri); |
57 | 57 | } |
@@ -64,10 +64,10 @@ discard block |
||
64 | 64 | { |
65 | 65 | // Strip off the query and fragment parts of the URL before checking |
66 | 66 | if (($queryPosition = strpos($url, '?')) !== false) { |
67 | - $url = substr($url, 0, $queryPosition - 1); |
|
67 | + $url = substr($url, 0, $queryPosition-1); |
|
68 | 68 | } |
69 | 69 | if (($hashPosition = strpos($url, '#')) !== false) { |
70 | - $url = substr($url, 0, $hashPosition - 1); |
|
70 | + $url = substr($url, 0, $hashPosition-1); |
|
71 | 71 | } |
72 | 72 | $colonPosition = strpos($url, ':'); |
73 | 73 | $slashPosition = strpos($url, '/'); |
@@ -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 |
@@ -40,8 +40,12 @@ discard block |
||
40 | 40 | public function __construct(string $url, array $data = [], array $headers = []) |
41 | 41 | { |
42 | 42 | $this->setURL($url); |
43 | - foreach ($data as $name => $value) $this->addDataParam($name, $value); |
|
44 | - foreach ($headers as $name => $value) $this->addHeader($name, $value); |
|
43 | + foreach ($data as $name => $value) { |
|
44 | + $this->addDataParam($name, $value); |
|
45 | + } |
|
46 | + foreach ($headers as $name => $value) { |
|
47 | + $this->addHeader($name, $value); |
|
48 | + } |
|
45 | 49 | } |
46 | 50 | |
47 | 51 | /** |
@@ -100,7 +104,9 @@ discard block |
||
100 | 104 | |
101 | 105 | public function removeDataParam(string $name): Curl |
102 | 106 | { |
103 | - 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 | + } |
|
104 | 110 | return $this; |
105 | 111 | } |
106 | 112 | |
@@ -129,7 +135,9 @@ discard block |
||
129 | 135 | */ |
130 | 136 | public function removeHeader(string $name): Curl |
131 | 137 | { |
132 | - 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 | + } |
|
133 | 141 | return $this; |
134 | 142 | } |
135 | 143 | |
@@ -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); |
@@ -220,7 +234,9 @@ discard block |
||
220 | 234 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
221 | 235 | |
222 | 236 | $response = new CurlResponse((int) $http_code, (string) $result); |
223 | - 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 | + } |
|
224 | 240 | |
225 | 241 | return $response; |
226 | 242 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | private $_method = 'GET'; |
22 | 22 | private $_url = ''; |
23 | 23 | private $_data = []; |
24 | - private $_isfile = false; |
|
24 | + private $_isfile = false; |
|
25 | 25 | private $_headers = [ |
26 | 26 | 'Content-Type' => 'application/x-www-form-urlencoded', |
27 | 27 | 'X-Requested-By' => self::USER_AGENT |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | if ($this->_enable_cache && $this->getMethod() === 'GET') { |
194 | - $cache_key = urlencode($request_uri) . implode(',', $send_headers); |
|
194 | + $cache_key = urlencode($request_uri).implode(',', $send_headers); |
|
195 | 195 | if (array_key_exists($cache_key, self::$_cache)) { |
196 | 196 | return self::$_cache[$cache_key]; |
197 | 197 | } |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
212 | 212 | |
213 | 213 | if (!empty($send_headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
214 | - if (!is_null($post_data)) { |
|
214 | + if (!is_null($post_data)) { |
|
215 | 215 | curl_setopt($ch, CURLOPT_POST, 1); |
216 | 216 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); |
217 | 217 | } |
@@ -148,7 +148,7 @@ |
||
148 | 148 | string $url, |
149 | 149 | string $list_class = ListResource::class, |
150 | 150 | array $params = [] |
151 | - ){ |
|
151 | + ) { |
|
152 | 152 | $this->assertInstanceOf($list_class, $all); |
153 | 153 | $this->assertEquals($url, $all->getURL()); |
154 | 154 | $this->assertEquals($this->getMockClient(), $all->getClient()); |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | public function __construct(string $app_id, string $app_secret, $auth_domain = self::AUTH_DOMAIN) |
26 | 26 | { |
27 | 27 | if (!$app_id || !$app_secret) { |
28 | - throw new InvalidArgumentException(static::class . "expects an app_id and app_secret"); |
|
28 | + throw new InvalidArgumentException(static::class."expects an app_id and app_secret"); |
|
29 | 29 | } |
30 | 30 | |
31 | 31 | $this->setAppID($app_id); |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | |
158 | 158 | if (!$response->isValid() || !$json || !array_key_exists('access_token', $json)) { |
159 | 159 | return ''; |
160 | - } else { |
|
160 | + }else { |
|
161 | 161 | $this->setAccessToken($json['access_token']); |
162 | 162 | return $this->getAccessToken(false); |
163 | 163 | } |
@@ -109,7 +109,9 @@ discard block |
||
109 | 109 | */ |
110 | 110 | public function getAPIChallenge(bool $check_session = true): string |
111 | 111 | { |
112 | - if ($this->_api_challenge) return $this->_api_challenge; |
|
112 | + if ($this->_api_challenge) { |
|
113 | + return $this->_api_challenge; |
|
114 | + } |
|
113 | 115 | |
114 | 116 | if ($check_session && session_status() === PHP_SESSION_ACTIVE) { |
115 | 117 | $this->setAPIChallenge($_SESSION[self::API_CHALLENGE_PARAM] ?? ''); |
@@ -169,7 +171,9 @@ discard block |
||
169 | 171 | */ |
170 | 172 | public function getAccessToken(bool $check_session = true): string |
171 | 173 | { |
172 | - if ($this->_access_token) return $this->_access_token; |
|
174 | + if ($this->_access_token) { |
|
175 | + return $this->_access_token; |
|
176 | + } |
|
173 | 177 | |
174 | 178 | if ($check_session && session_status() === PHP_SESSION_ACTIVE) { |
175 | 179 | $this->setAccessToken($_SESSION[self::ACCESS_TOKEN_PARAM] ?? ''); |
@@ -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 | } |