@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | public function test_is_associative_array() |
| 22 | 22 | { |
| 23 | 23 | $this->assertEquals(true, ArrayLib::is_associative(['a' => 1])); |
| 24 | - $this->assertEquals(false, ArrayLib::is_associative([1,2,3])); |
|
| 24 | + $this->assertEquals(false, ArrayLib::is_associative([1, 2, 3])); |
|
| 25 | 25 | $this->assertEquals(false, ArrayLib::is_associative([])); |
| 26 | 26 | |
| 27 | 27 | try { |
@@ -42,16 +42,16 @@ discard block |
||
| 42 | 42 | public function test_set_get_var() |
| 43 | 43 | { |
| 44 | 44 | $rel_path = '/path'; |
| 45 | - $this->assertEquals($rel_path . '?var=1', URL::setGetVar('var', 1, $rel_path)); |
|
| 45 | + $this->assertEquals($rel_path.'?var=1', URL::setGetVar('var', 1, $rel_path)); |
|
| 46 | 46 | |
| 47 | 47 | $rel_path_t = '/path/'; |
| 48 | - $this->assertEquals($rel_path_t . '?var=1', URL::setGetVar('var', 1, $rel_path_t)); |
|
| 48 | + $this->assertEquals($rel_path_t.'?var=1', URL::setGetVar('var', 1, $rel_path_t)); |
|
| 49 | 49 | |
| 50 | 50 | $absolute = 'https://test.com'; |
| 51 | - $this->assertEquals($absolute . '?var=1', URL::setGetVar('var', 1, $absolute)); |
|
| 51 | + $this->assertEquals($absolute.'?var=1', URL::setGetVar('var', 1, $absolute)); |
|
| 52 | 52 | |
| 53 | 53 | $absolute_t = 'https://test.com/'; |
| 54 | - $this->assertEquals($absolute_t . '?var=1', URL::setGetVar('var', 1, $absolute_t)); |
|
| 54 | + $this->assertEquals($absolute_t.'?var=1', URL::setGetVar('var', 1, $absolute_t)); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | while (count($generated) < 100000) $generated[] = Utils::create_random_string(); |
| 72 | 72 | $count = count($generated); |
| 73 | 73 | $unique = count(array_unique($generated)); |
| 74 | - $random = 100 - ((100 / $count) * $unique); |
|
| 74 | + $random = 100-((100 / $count) * $unique); |
|
| 75 | 75 | |
| 76 | 76 | // Less than 2% repeat |
| 77 | 77 | $this->assertTrue($random < 2); |
@@ -68,7 +68,9 @@ |
||
| 68 | 68 | |
| 69 | 69 | // Test the randomness |
| 70 | 70 | $generated = []; |
| 71 | - while (count($generated) < 100000) $generated[] = Utils::create_random_string(); |
|
| 71 | + while (count($generated) < 100000) { |
|
| 72 | + $generated[] = Utils::create_random_string(); |
|
| 73 | + } |
|
| 72 | 74 | $count = count($generated); |
| 73 | 75 | $unique = count(array_unique($generated)); |
| 74 | 76 | $random = 100 - ((100 / $count) * $unique); |
@@ -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 | /** |
@@ -98,7 +102,9 @@ discard block |
||
| 98 | 102 | |
| 99 | 103 | public function removeDataParam(string $name): Curl |
| 100 | 104 | { |
| 101 | - if (array_key_exists($name, $this->_data)) unset($this->_data[$name]); |
|
| 105 | + if (array_key_exists($name, $this->_data)) { |
|
| 106 | + unset($this->_data[$name]); |
|
| 107 | + } |
|
| 102 | 108 | return $this; |
| 103 | 109 | } |
| 104 | 110 | |
@@ -127,7 +133,9 @@ discard block |
||
| 127 | 133 | */ |
| 128 | 134 | public function removeHeader(string $name): Curl |
| 129 | 135 | { |
| 130 | - if (array_key_exists($name, $this->_headers)) unset($this->_headers[$name]); |
|
| 136 | + if (array_key_exists($name, $this->_headers)) { |
|
| 137 | + unset($this->_headers[$name]); |
|
| 138 | + } |
|
| 131 | 139 | return $this; |
| 132 | 140 | } |
| 133 | 141 | |
@@ -171,13 +179,17 @@ discard block |
||
| 171 | 179 | $request_uri = $this->getURL(); |
| 172 | 180 | |
| 173 | 181 | // Headers |
| 174 | - foreach ($this->getHeaders() as $k => $v) $send_headers[] = "{$k}: {$v}"; |
|
| 182 | + foreach ($this->getHeaders() as $k => $v) { |
|
| 183 | + $send_headers[] = "{$k}: {$v}"; |
|
| 184 | + } |
|
| 175 | 185 | |
| 176 | 186 | // Request Data |
| 177 | 187 | switch ($this->getMethod()) { |
| 178 | 188 | case 'GET': |
| 179 | 189 | case 'DELETE': |
| 180 | - foreach ($this->getDataParams() as $name => $value) $request_uri = URL::setGetVar($name, $value, $request_uri); |
|
| 190 | + foreach ($this->getDataParams() as $name => $value) { |
|
| 191 | + $request_uri = URL::setGetVar($name, $value, $request_uri); |
|
| 192 | + } |
|
| 181 | 193 | break; |
| 182 | 194 | |
| 183 | 195 | case 'POST': |
@@ -208,7 +220,9 @@ discard block |
||
| 208 | 220 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
| 209 | 221 | curl_setopt($ch, CURLOPT_AUTOREFERER, true); |
| 210 | 222 | |
| 211 | - if (!empty($send_headers)) curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
|
| 223 | + if (!empty($send_headers)) { |
|
| 224 | + curl_setopt($ch, CURLOPT_HTTPHEADER, $send_headers); |
|
| 225 | + } |
|
| 212 | 226 | if (!is_null($post_data)) { |
| 213 | 227 | curl_setopt($ch, CURLOPT_POST, 1); |
| 214 | 228 | curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); |
@@ -218,7 +232,9 @@ discard block |
||
| 218 | 232 | $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
| 219 | 233 | |
| 220 | 234 | $response = new CurlResponse($http_code, $result); |
| 221 | - if ($this->_enable_cache && isset($cache_key)) self::$_cache[$cache_key] = $response; |
|
| 235 | + if ($this->_enable_cache && isset($cache_key)) { |
|
| 236 | + self::$_cache[$cache_key] = $response; |
|
| 237 | + } |
|
| 222 | 238 | |
| 223 | 239 | return $response; |
| 224 | 240 | } |
@@ -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, '/'); |