@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | |
| 241 | 241 | $output = curl_exec($ch); |
| 242 | 242 | |
| 243 | - if(isset($this->logfilePointer)) |
|
| 243 | + if (isset($this->logfilePointer)) |
|
| 244 | 244 | { |
| 245 | 245 | fclose($this->logfilePointer); |
| 246 | 246 | } |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | // CURL will complain about an empty response when the |
| 253 | 253 | // server sends a 100-continue code. That should not be |
| 254 | 254 | // regarded as an error. |
| 255 | - if($output === false && $this->response->getCode() !== 100) |
|
| 255 | + if ($output === false && $this->response->getCode() !== 100) |
|
| 256 | 256 | { |
| 257 | 257 | $this->response->setError( |
| 258 | 258 | curl_errno($ch), |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | { |
| 287 | 287 | $ch = curl_init(); |
| 288 | 288 | |
| 289 | - if(!is_resource($ch)) |
|
| 289 | + if (!is_resource($ch)) |
|
| 290 | 290 | { |
| 291 | 291 | throw new RequestHelper_Exception( |
| 292 | 292 | 'Could not initialize a new cURL instance.', |
@@ -296,7 +296,7 @@ discard block |
||
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | $this->setHeader('Content-Length', (string)$this->boundaries->getContentLength()); |
| 299 | - $this->setHeader('Content-Type', 'multipart/form-data; boundary=' . $this->mimeBoundary); |
|
| 299 | + $this->setHeader('Content-Type', 'multipart/form-data; boundary='.$this->mimeBoundary); |
|
| 300 | 300 | |
| 301 | 301 | curl_setopt($ch, CURLOPT_POST, true); |
| 302 | 302 | curl_setopt($ch, CURLOPT_URL, $url->getNormalizedWithoutAuth()); |
@@ -309,18 +309,18 @@ discard block |
||
| 309 | 309 | |
| 310 | 310 | $loggingEnabled = $this->configureLogging($ch); |
| 311 | 311 | |
| 312 | - if(!$loggingEnabled) |
|
| 312 | + if (!$loggingEnabled) |
|
| 313 | 313 | { |
| 314 | 314 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
| 315 | 315 | } |
| 316 | 316 | |
| 317 | - if($this->verifySSL) |
|
| 317 | + if ($this->verifySSL) |
|
| 318 | 318 | { |
| 319 | 319 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
| 320 | 320 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 321 | 321 | } |
| 322 | 322 | |
| 323 | - if($url->hasUsername()) |
|
| 323 | + if ($url->hasUsername()) |
|
| 324 | 324 | { |
| 325 | 325 | curl_setopt($ch, CURLOPT_USERNAME, $url->getUsername()); |
| 326 | 326 | curl_setopt($ch, CURLOPT_PASSWORD, $url->getPassword()); |
@@ -335,14 +335,14 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | protected function configureLogging($ch) : bool |
| 337 | 337 | { |
| 338 | - if(empty($this->logfile)) |
|
| 338 | + if (empty($this->logfile)) |
|
| 339 | 339 | { |
| 340 | 340 | return false; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | $res = fopen($this->logfile, 'w+'); |
| 344 | 344 | |
| 345 | - if($res === false) |
|
| 345 | + if ($res === false) |
|
| 346 | 346 | { |
| 347 | 347 | throw new RequestHelper_Exception( |
| 348 | 348 | 'Cannot open logfile for writing.', |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | |
| 373 | 373 | $this->setHeader('Expect', ''); |
| 374 | 374 | |
| 375 | - foreach($this->headers as $name => $value) { |
|
| 375 | + foreach ($this->headers as $name => $value) { |
|
| 376 | 376 | $result[] = $name.': '.$value; |
| 377 | 377 | } |
| 378 | 378 | |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | { |
| 390 | 390 | $response = $this->getResponse(); |
| 391 | 391 | |
| 392 | - if($response !== null) { |
|
| 392 | + if ($response !== null) { |
|
| 393 | 393 | return $response->getHeaders(); |
| 394 | 394 | } |
| 395 | 395 | |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | * @param string $message Should not contain a date, just the system specific info. |
| 84 | 84 | * @return OperationResult |
| 85 | 85 | */ |
| 86 | - public function makeSuccess(string $message, int $code=0) : OperationResult |
|
| 86 | + public function makeSuccess(string $message, int $code = 0) : OperationResult |
|
| 87 | 87 | { |
| 88 | 88 | return $this->setMessage($message, $code, true); |
| 89 | 89 | } |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | * @param string $message Should be as detailed as possible. |
| 95 | 95 | * @return OperationResult |
| 96 | 96 | */ |
| 97 | - public function makeError(string $message, int $code=0) : OperationResult |
|
| 97 | + public function makeError(string $message, int $code = 0) : OperationResult |
|
| 98 | 98 | { |
| 99 | 99 | return $this->setMessage($message, $code, false); |
| 100 | 100 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | protected function getMessage(bool $valid) : string |
| 142 | 142 | { |
| 143 | - if($this->valid === $valid) |
|
| 143 | + if ($this->valid === $valid) |
|
| 144 | 144 | { |
| 145 | 145 | return $this->message; |
| 146 | 146 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function setOption(string $name, $value) |
| 42 | 42 | { |
| 43 | - if(!isset($this->options)) { |
|
| 43 | + if (!isset($this->options)) { |
|
| 44 | 44 | $this->options = $this->getDefaultOptions(); |
| 45 | 45 | } |
| 46 | 46 | |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | */ |
| 57 | 57 | public function setOptions(array $options) |
| 58 | 58 | { |
| 59 | - foreach($options as $name => $value) { |
|
| 59 | + foreach ($options as $name => $value) { |
|
| 60 | 60 | $this->setOption($name, $value); |
| 61 | 61 | } |
| 62 | 62 | |
@@ -73,13 +73,13 @@ discard block |
||
| 73 | 73 | * @param mixed $default The default value to return if the option does not exist. |
| 74 | 74 | * @return mixed |
| 75 | 75 | */ |
| 76 | - public function getOption(string $name, $default=null) |
|
| 76 | + public function getOption(string $name, $default = null) |
|
| 77 | 77 | { |
| 78 | - if(!isset($this->options)) { |
|
| 78 | + if (!isset($this->options)) { |
|
| 79 | 79 | $this->options = $this->getDefaultOptions(); |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | - if(isset($this->options[$name])) { |
|
| 82 | + if (isset($this->options[$name])) { |
|
| 83 | 83 | return $this->options[$name]; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -96,11 +96,11 @@ discard block |
||
| 96 | 96 | * @param string $default Used if the option does not exist, is invalid, or empty. |
| 97 | 97 | * @return string |
| 98 | 98 | */ |
| 99 | - public function getStringOption(string $name, string $default='') : string |
|
| 99 | + public function getStringOption(string $name, string $default = '') : string |
|
| 100 | 100 | { |
| 101 | 101 | $value = $this->getOption($name, false); |
| 102 | 102 | |
| 103 | - if((is_string($value) || is_numeric($value)) && !empty($value)) { |
|
| 103 | + if ((is_string($value) || is_numeric($value)) && !empty($value)) { |
|
| 104 | 104 | return (string)$value; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * @param string $name |
| 117 | 117 | * @return bool |
| 118 | 118 | */ |
| 119 | - public function getBoolOption(string $name, bool $default=false) : bool |
|
| 119 | + public function getBoolOption(string $name, bool $default = false) : bool |
|
| 120 | 120 | { |
| 121 | - if($this->getOption($name) === true) { |
|
| 121 | + if ($this->getOption($name) === true) { |
|
| 122 | 122 | return true; |
| 123 | 123 | } |
| 124 | 124 | |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | * @param int $default |
| 135 | 135 | * @return int |
| 136 | 136 | */ |
| 137 | - public function getIntOption(string $name, int $default=0) : int |
|
| 137 | + public function getIntOption(string $name, int $default = 0) : int |
|
| 138 | 138 | { |
| 139 | 139 | $value = $this->getOption($name); |
| 140 | - if(ConvertHelper::isInteger($value)) { |
|
| 140 | + if (ConvertHelper::isInteger($value)) { |
|
| 141 | 141 | return (int)$value; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | public function getArrayOption(string $name) : array |
| 156 | 156 | { |
| 157 | 157 | $val = $this->getOption($name); |
| 158 | - if(is_array($val)) { |
|
| 158 | + if (is_array($val)) { |
|
| 159 | 159 | return $val; |
| 160 | 160 | } |
| 161 | 161 | |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | */ |
| 172 | 172 | public function hasOption(string $name) : bool |
| 173 | 173 | { |
| 174 | - if(!isset($this->options)) { |
|
| 174 | + if (!isset($this->options)) { |
|
| 175 | 175 | $this->options = $this->getDefaultOptions(); |
| 176 | 176 | } |
| 177 | 177 | |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | public function getOptions() : array |
| 186 | 186 | { |
| 187 | - if(!isset($this->options)) { |
|
| 187 | + if (!isset($this->options)) { |
|
| 188 | 188 | $this->options = $this->getDefaultOptions(); |
| 189 | 189 | } |
| 190 | 190 | |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * @param mixed $default |
| 239 | 239 | * @return $this |
| 240 | 240 | */ |
| 241 | - function getOption(string $name, $default=null); |
|
| 241 | + function getOption(string $name, $default = null); |
|
| 242 | 242 | |
| 243 | 243 | /** |
| 244 | 244 | * @param array $options |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | public function addFile(string $varName, string $fileName, string $content, string $contentType = '', string $encoding = '') : RequestHelper_Boundaries |
| 85 | 85 | { |
| 86 | - if(empty($contentType)) |
|
| 86 | + if (empty($contentType)) |
|
| 87 | 87 | { |
| 88 | 88 | $contentType = (string)FileHelper::detectMimeType($fileName); |
| 89 | 89 | } |
| 90 | 90 | |
| 91 | - if(empty($encoding)) |
|
| 91 | + if (empty($encoding)) |
|
| 92 | 92 | { |
| 93 | 93 | $encoding = RequestHelper::ENCODING_UTF8; |
| 94 | 94 | $content = ConvertHelper::string2utf8($content); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | */ |
| 154 | 154 | public function render() : string |
| 155 | 155 | { |
| 156 | - if(empty($this->boundaries)) |
|
| 156 | + if (empty($this->boundaries)) |
|
| 157 | 157 | { |
| 158 | 158 | throw new RequestHelper_Exception( |
| 159 | 159 | 'No mime boundaries added', |
@@ -164,13 +164,13 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | $result = ''; |
| 166 | 166 | |
| 167 | - foreach($this->boundaries as $boundary) |
|
| 167 | + foreach ($this->boundaries as $boundary) |
|
| 168 | 168 | { |
| 169 | 169 | $result .= $boundary->render(); |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - $result .= "--" . $this->getMimeBoundary() . "--" . |
|
| 173 | - $this->getEOL() . $this->getEOL(); // always finish with two eol's!! |
|
| 172 | + $result .= "--".$this->getMimeBoundary()."--". |
|
| 173 | + $this->getEOL().$this->getEOL(); // always finish with two eol's!! |
|
| 174 | 174 | |
| 175 | 175 | return $result; |
| 176 | 176 | } |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | 'fragment' |
| 78 | 78 | ); |
| 79 | 79 | |
| 80 | - foreach($parts as $part) |
|
| 80 | + foreach ($parts as $part) |
|
| 81 | 81 | { |
| 82 | 82 | $method = 'render_'.$part; |
| 83 | 83 | $result[] = (string)$this->$method(); |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | protected function render_scheme() : string |
| 90 | 90 | { |
| 91 | - if(!$this->info->hasScheme()) { |
|
| 91 | + if (!$this->info->hasScheme()) { |
|
| 92 | 92 | return ''; |
| 93 | 93 | } |
| 94 | 94 | |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | protected function render_username() : string |
| 105 | 105 | { |
| 106 | - if(!$this->info->hasUsername()) { |
|
| 106 | + if (!$this->info->hasUsername()) { |
|
| 107 | 107 | return ''; |
| 108 | 108 | } |
| 109 | 109 | |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | |
| 120 | 120 | protected function render_host() : string |
| 121 | 121 | { |
| 122 | - if(!$this->info->hasHost()) { |
|
| 122 | + if (!$this->info->hasHost()) { |
|
| 123 | 123 | return ''; |
| 124 | 124 | } |
| 125 | 125 | |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | protected function render_port() : string |
| 133 | 133 | { |
| 134 | - if(!$this->info->hasPort()) { |
|
| 134 | + if (!$this->info->hasPort()) { |
|
| 135 | 135 | return ''; |
| 136 | 136 | } |
| 137 | 137 | |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | protected function render_path() : string |
| 146 | 146 | { |
| 147 | - if(!$this->info->hasPath()) { |
|
| 147 | + if (!$this->info->hasPath()) { |
|
| 148 | 148 | return ''; |
| 149 | 149 | } |
| 150 | 150 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | { |
| 170 | 170 | $previous = $this->info->isParamExclusionEnabled(); |
| 171 | 171 | |
| 172 | - if($previous) |
|
| 172 | + if ($previous) |
|
| 173 | 173 | { |
| 174 | 174 | $this->info->setParamExclusion(false); |
| 175 | 175 | } |
@@ -185,19 +185,19 @@ discard block |
||
| 185 | 185 | { |
| 186 | 186 | $params = $this->resolveParams(); |
| 187 | 187 | |
| 188 | - if(empty($params)) { |
|
| 188 | + if (empty($params)) { |
|
| 189 | 189 | return ''; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | $tokens = array(); |
| 193 | 193 | $excluded = array(); |
| 194 | 194 | |
| 195 | - if($this->info->isParamExclusionEnabled()) |
|
| 195 | + if ($this->info->isParamExclusionEnabled()) |
|
| 196 | 196 | { |
| 197 | 197 | $excluded = $this->info->getExcludedParams(); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - foreach($params as $param => $value) |
|
| 200 | + foreach ($params as $param => $value) |
|
| 201 | 201 | { |
| 202 | 202 | $parts = sprintf( |
| 203 | 203 | '<span class="link-param-name">%s</span>'. |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | |
| 215 | 215 | $tag = $this->resolveTag($excluded, $param); |
| 216 | 216 | |
| 217 | - if(!empty($tag)) |
|
| 217 | + if (!empty($tag)) |
|
| 218 | 218 | { |
| 219 | 219 | $tokens[] = sprintf($tag, $parts); |
| 220 | 220 | } |
@@ -228,13 +228,13 @@ discard block |
||
| 228 | 228 | protected function resolveTag(array $excluded, string $paramName) : string |
| 229 | 229 | { |
| 230 | 230 | // regular, non-excluded parameter |
| 231 | - if(!isset($excluded[$paramName])) |
|
| 231 | + if (!isset($excluded[$paramName])) |
|
| 232 | 232 | { |
| 233 | 233 | return '<span class="link-param">%s</span>'; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | // highlight excluded parameters is disabled, ignore this parameter |
| 237 | - if(!$this->info->isHighlightExcludeEnabled()) |
|
| 237 | + if (!$this->info->isHighlightExcludeEnabled()) |
|
| 238 | 238 | { |
| 239 | 239 | return ''; |
| 240 | 240 | } |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | |
| 251 | 251 | protected function render_fragment() : string |
| 252 | 252 | { |
| 253 | - if(!$this->info->hasFragment()) { |
|
| 253 | + if (!$this->info->hasFragment()) { |
|
| 254 | 254 | return ''; |
| 255 | 255 | } |
| 256 | 256 | |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | { |
| 266 | 266 | $cssFolder = realpath(__DIR__.'/../../css'); |
| 267 | 267 | |
| 268 | - if($cssFolder === false) { |
|
| 268 | + if ($cssFolder === false) { |
|
| 269 | 269 | throw new BaseException( |
| 270 | 270 | 'Cannot find package CSS folder.', |
| 271 | 271 | null, |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @param bool $enable Whether to turn it on or off. |
| 40 | 40 | * @return URLInfo_Normalizer |
| 41 | 41 | */ |
| 42 | - public function enableAuth(bool $enable=true) : URLInfo_Normalizer |
|
| 42 | + public function enableAuth(bool $enable = true) : URLInfo_Normalizer |
|
| 43 | 43 | { |
| 44 | 44 | $this->auth = $enable; |
| 45 | 45 | return $this; |
@@ -86,48 +86,48 @@ discard block |
||
| 86 | 86 | |
| 87 | 87 | protected function renderAuth(string $normalized) : string |
| 88 | 88 | { |
| 89 | - if(!$this->info->hasUsername() || !$this->auth) { |
|
| 89 | + if (!$this->info->hasUsername() || !$this->auth) { |
|
| 90 | 90 | return $normalized; |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | - return $normalized . urlencode($this->info->getUsername()).':'.urlencode($this->info->getPassword()).'@'; |
|
| 93 | + return $normalized.urlencode($this->info->getUsername()).':'.urlencode($this->info->getPassword()).'@'; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | protected function renderPort(string $normalized) : string |
| 97 | 97 | { |
| 98 | - if(!$this->info->hasPort()) { |
|
| 98 | + if (!$this->info->hasPort()) { |
|
| 99 | 99 | return $normalized; |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - return $normalized . ':'.$this->info->getPort(); |
|
| 102 | + return $normalized.':'.$this->info->getPort(); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | protected function renderPath(string $normalized) : string |
| 106 | 106 | { |
| 107 | - if(!$this->info->hasPath()) { |
|
| 107 | + if (!$this->info->hasPath()) { |
|
| 108 | 108 | return $normalized; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - return $normalized . $this->info->getPath(); |
|
| 111 | + return $normalized.$this->info->getPath(); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | protected function renderParams(string $normalized) : string |
| 115 | 115 | { |
| 116 | 116 | $params = $this->info->getParams(); |
| 117 | 117 | |
| 118 | - if(empty($params)) { |
|
| 118 | + if (empty($params)) { |
|
| 119 | 119 | return $normalized; |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - return $normalized . '?'.http_build_query($params, '', '&', PHP_QUERY_RFC3986); |
|
| 122 | + return $normalized.'?'.http_build_query($params, '', '&', PHP_QUERY_RFC3986); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | protected function renderFragment(string $normalized) : string |
| 126 | 126 | { |
| 127 | - if(!$this->info->hasFragment()) { |
|
| 127 | + if (!$this->info->hasFragment()) { |
|
| 128 | 128 | return $normalized; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - return $normalized . '#'.$this->info->getFragment(); |
|
| 131 | + return $normalized.'#'.$this->info->getFragment(); |
|
| 132 | 132 | } |
| 133 | 133 | } |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | $result = array(); |
| 48 | 48 | |
| 49 | - foreach($parts as $part) |
|
| 49 | + foreach ($parts as $part) |
|
| 50 | 50 | { |
| 51 | 51 | $tokens = explode('=', $part); |
| 52 | 52 | |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | $trimmed = trim($name); |
| 57 | 57 | |
| 58 | - if(empty($trimmed)) |
|
| 58 | + if (empty($trimmed)) |
|
| 59 | 59 | { |
| 60 | 60 | continue; |
| 61 | 61 | } |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | * @param bool $enabled |
| 129 | 129 | * @return URLInfo |
| 130 | 130 | */ |
| 131 | - public function setUTFEncoding(bool $enabled=true) : URLInfo |
|
| 131 | + public function setUTFEncoding(bool $enabled = true) : URLInfo |
|
| 132 | 132 | { |
| 133 | - if($this->encodeUTFChars !== $enabled) |
|
| 133 | + if ($this->encodeUTFChars !== $enabled) |
|
| 134 | 134 | { |
| 135 | 135 | $this->encodeUTFChars = $enabled; |
| 136 | 136 | $this->parse(); // re-parse the URL to apply the changes |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | { |
| 235 | 235 | $port = $this->getInfoKey('port'); |
| 236 | 236 | |
| 237 | - if(!empty($port)) { |
|
| 237 | + if (!empty($port)) { |
|
| 238 | 238 | return (int)$port; |
| 239 | 239 | } |
| 240 | 240 | |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | protected function getInfoKey(string $name) : string |
| 316 | 316 | { |
| 317 | - if(isset($this->info[$name])) { |
|
| 317 | + if (isset($this->info[$name])) { |
|
| 318 | 318 | return (string)$this->info[$name]; |
| 319 | 319 | } |
| 320 | 320 | |
@@ -343,13 +343,13 @@ discard block |
||
| 343 | 343 | return $this->normalize(false); |
| 344 | 344 | } |
| 345 | 345 | |
| 346 | - protected function normalize(bool $auth=true) : string |
|
| 346 | + protected function normalize(bool $auth = true) : string |
|
| 347 | 347 | { |
| 348 | - if(!$this->isValid()) { |
|
| 348 | + if (!$this->isValid()) { |
|
| 349 | 349 | return ''; |
| 350 | 350 | } |
| 351 | 351 | |
| 352 | - if(!isset($this->normalizer)) { |
|
| 352 | + if (!isset($this->normalizer)) { |
|
| 353 | 353 | $this->normalizer = new URLInfo_Normalizer($this); |
| 354 | 354 | } |
| 355 | 355 | |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | */ |
| 380 | 380 | public function getHighlighted() : string |
| 381 | 381 | { |
| 382 | - if(!$this->isValid()) { |
|
| 382 | + if (!$this->isValid()) { |
|
| 383 | 383 | return ''; |
| 384 | 384 | } |
| 385 | 385 | |
@@ -421,14 +421,14 @@ discard block |
||
| 421 | 421 | */ |
| 422 | 422 | public function getParams() : array |
| 423 | 423 | { |
| 424 | - if(!$this->paramExclusion || empty($this->excludedParams)) { |
|
| 424 | + if (!$this->paramExclusion || empty($this->excludedParams)) { |
|
| 425 | 425 | return $this->info['params']; |
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | $keep = array(); |
| 429 | - foreach($this->info['params'] as $name => $value) |
|
| 429 | + foreach ($this->info['params'] as $name => $value) |
|
| 430 | 430 | { |
| 431 | - if(!isset($this->excludedParams[$name])) { |
|
| 431 | + if (!isset($this->excludedParams[$name])) { |
|
| 432 | 432 | $keep[$name] = $value; |
| 433 | 433 | } |
| 434 | 434 | } |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | */ |
| 455 | 455 | public function getParam(string $name) : string |
| 456 | 456 | { |
| 457 | - if(isset($this->info['params'][$name])) { |
|
| 457 | + if (isset($this->info['params'][$name])) { |
|
| 458 | 458 | return $this->info['params'][$name]; |
| 459 | 459 | } |
| 460 | 460 | |
@@ -473,7 +473,7 @@ discard block |
||
| 473 | 473 | */ |
| 474 | 474 | public function excludeParam(string $name, string $reason) : URLInfo |
| 475 | 475 | { |
| 476 | - if(!isset($this->excludedParams[$name])) |
|
| 476 | + if (!isset($this->excludedParams[$name])) |
|
| 477 | 477 | { |
| 478 | 478 | $this->excludedParams[$name] = $reason; |
| 479 | 479 | $this->setParamExclusion(); |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | |
| 500 | 500 | public function getTypeLabel() : string |
| 501 | 501 | { |
| 502 | - if(!isset(self::$typeLabels)) |
|
| 502 | + if (!isset(self::$typeLabels)) |
|
| 503 | 503 | { |
| 504 | 504 | self::$typeLabels = array( |
| 505 | 505 | self::TYPE_EMAIL => t('Email'), |
@@ -511,7 +511,7 @@ discard block |
||
| 511 | 511 | |
| 512 | 512 | $type = $this->getType(); |
| 513 | 513 | |
| 514 | - if(!isset(self::$typeLabels[$type])) |
|
| 514 | + if (!isset(self::$typeLabels[$type])) |
|
| 515 | 515 | { |
| 516 | 516 | throw new BaseException( |
| 517 | 517 | sprintf('Unknown URL type label for type [%s].', $type), |
@@ -531,7 +531,7 @@ discard block |
||
| 531 | 531 | * @param bool $highlight |
| 532 | 532 | * @return URLInfo |
| 533 | 533 | */ |
| 534 | - public function setHighlightExcluded(bool $highlight=true) : URLInfo |
|
| 534 | + public function setHighlightExcluded(bool $highlight = true) : URLInfo |
|
| 535 | 535 | { |
| 536 | 536 | $this->highlightExcluded = $highlight; |
| 537 | 537 | return $this; |
@@ -579,7 +579,7 @@ discard block |
||
| 579 | 579 | * @see URLInfo::isParamExclusionEnabled() |
| 580 | 580 | * @see URLInfo::setHighlightExcluded() |
| 581 | 581 | */ |
| 582 | - public function setParamExclusion(bool $enabled=true) : URLInfo |
|
| 582 | + public function setParamExclusion(bool $enabled = true) : URLInfo |
|
| 583 | 583 | { |
| 584 | 584 | $this->paramExclusion = $enabled; |
| 585 | 585 | return $this; |
@@ -605,13 +605,13 @@ discard block |
||
| 605 | 605 | */ |
| 606 | 606 | public function containsExcludedParams() : bool |
| 607 | 607 | { |
| 608 | - if(empty($this->excludedParams)) { |
|
| 608 | + if (empty($this->excludedParams)) { |
|
| 609 | 609 | return false; |
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | $names = array_keys($this->info['params']); |
| 613 | - foreach($names as $name) { |
|
| 614 | - if(isset($this->excludedParams[$name])) { |
|
| 613 | + foreach ($names as $name) { |
|
| 614 | + if (isset($this->excludedParams[$name])) { |
|
| 615 | 615 | return true; |
| 616 | 616 | } |
| 617 | 617 | } |
@@ -627,7 +627,7 @@ discard block |
||
| 627 | 627 | |
| 628 | 628 | public function offsetSet($offset, $value) |
| 629 | 629 | { |
| 630 | - if(in_array($offset, $this->infoKeys)) { |
|
| 630 | + if (in_array($offset, $this->infoKeys)) { |
|
| 631 | 631 | $this->info[$offset] = $value; |
| 632 | 632 | } |
| 633 | 633 | } |
@@ -644,11 +644,11 @@ discard block |
||
| 644 | 644 | |
| 645 | 645 | public function offsetGet($offset) |
| 646 | 646 | { |
| 647 | - if($offset === 'port') { |
|
| 647 | + if ($offset === 'port') { |
|
| 648 | 648 | return $this->getPort(); |
| 649 | 649 | } |
| 650 | 650 | |
| 651 | - if(in_array($offset, $this->infoKeys)) { |
|
| 651 | + if (in_array($offset, $this->infoKeys)) { |
|
| 652 | 652 | return $this->getInfoKey($offset); |
| 653 | 653 | } |
| 654 | 654 | |
@@ -680,12 +680,12 @@ discard block |
||
| 680 | 680 | * @return bool |
| 681 | 681 | * @throws BaseException |
| 682 | 682 | */ |
| 683 | - public function tryConnect(bool $verifySSL=true) : bool |
|
| 683 | + public function tryConnect(bool $verifySSL = true) : bool |
|
| 684 | 684 | { |
| 685 | 685 | requireCURL(); |
| 686 | 686 | |
| 687 | 687 | $ch = curl_init(); |
| 688 | - if(!is_resource($ch)) |
|
| 688 | + if (!is_resource($ch)) |
|
| 689 | 689 | { |
| 690 | 690 | throw new BaseException( |
| 691 | 691 | 'Could not initialize a new cURL instance.', |
@@ -701,13 +701,13 @@ discard block |
||
| 701 | 701 | curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
| 702 | 702 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 703 | 703 | |
| 704 | - if(!$verifySSL) |
|
| 704 | + if (!$verifySSL) |
|
| 705 | 705 | { |
| 706 | 706 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
| 707 | 707 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 708 | 708 | } |
| 709 | 709 | |
| 710 | - if($this->hasUsername()) |
|
| 710 | + if ($this->hasUsername()) |
|
| 711 | 711 | { |
| 712 | 712 | curl_setopt($ch, CURLOPT_USERNAME, $this->getUsername()); |
| 713 | 713 | curl_setopt($ch, CURLOPT_PASSWORD, $this->getPassword()); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | $this->parse(); |
| 84 | 84 | |
| 85 | - if(!$this->detectType()) { |
|
| 85 | + if (!$this->detectType()) { |
|
| 86 | 86 | $this->validate(); |
| 87 | 87 | } |
| 88 | 88 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | // if the URL contains any URL characters, and we |
| 110 | 110 | // do not want them URL encoded, restore them. |
| 111 | - if(!$this->encodeUTF && !empty($this->unicodeChars)) |
|
| 111 | + if (!$this->encodeUTF && !empty($this->unicodeChars)) |
|
| 112 | 112 | { |
| 113 | 113 | $this->info = $this->restoreUnicodeChars($this->info); |
| 114 | 114 | } |
@@ -125,13 +125,13 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | $keep = array(); |
| 127 | 127 | |
| 128 | - foreach($chars as $char) |
|
| 128 | + foreach ($chars as $char) |
|
| 129 | 129 | { |
| 130 | - if(preg_match('/\p{L}/usix', $char)) |
|
| 130 | + if (preg_match('/\p{L}/usix', $char)) |
|
| 131 | 131 | { |
| 132 | 132 | $encoded = rawurlencode($char); |
| 133 | 133 | |
| 134 | - if($encoded != $char) |
|
| 134 | + if ($encoded != $char) |
|
| 135 | 135 | { |
| 136 | 136 | $this->unicodeChars[$encoded] = $char; |
| 137 | 137 | $char = $encoded; |
@@ -152,11 +152,11 @@ discard block |
||
| 152 | 152 | 'phoneLink' |
| 153 | 153 | ); |
| 154 | 154 | |
| 155 | - foreach($types as $type) |
|
| 155 | + foreach ($types as $type) |
|
| 156 | 156 | { |
| 157 | 157 | $method = 'detectType_'.$type; |
| 158 | 158 | |
| 159 | - if($this->$method() === true) |
|
| 159 | + if ($this->$method() === true) |
|
| 160 | 160 | { |
| 161 | 161 | $this->isValid = true; |
| 162 | 162 | return true; |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | 'hostIsPresent' |
| 175 | 175 | ); |
| 176 | 176 | |
| 177 | - foreach($validations as $validation) |
|
| 177 | + foreach ($validations as $validation) |
|
| 178 | 178 | { |
| 179 | 179 | $method = 'validate_'.$validation; |
| 180 | 180 | |
| 181 | - if($this->$method() !== true) { |
|
| 181 | + if ($this->$method() !== true) { |
|
| 182 | 182 | return; |
| 183 | 183 | } |
| 184 | 184 | } |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | // every link needs a host. This case can happen for ex, if |
| 192 | 192 | // the link starts with a typo with only one slash, like: |
| 193 | 193 | // "http:/hostname" |
| 194 | - if(isset($this->info['host'])) { |
|
| 194 | + if (isset($this->info['host'])) { |
|
| 195 | 195 | return true; |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | $this->setError( |
| 199 | 199 | URLInfo::ERROR_MISSING_HOST, |
| 200 | - t('Cannot determine the link\'s host name.') . ' ' . |
|
| 200 | + t('Cannot determine the link\'s host name.').' '. |
|
| 201 | 201 | t('This usually happens when there\'s a typo somewhere.') |
| 202 | 202 | ); |
| 203 | 203 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | |
| 207 | 207 | protected function validate_schemeIsSet() : bool |
| 208 | 208 | { |
| 209 | - if(isset($this->info['scheme'])) { |
|
| 209 | + if (isset($this->info['scheme'])) { |
|
| 210 | 210 | return true; |
| 211 | 211 | } |
| 212 | 212 | |
@@ -223,13 +223,13 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | protected function validate_schemeIsKnown() : bool |
| 225 | 225 | { |
| 226 | - if(in_array($this->info['scheme'], $this->knownSchemes)) { |
|
| 226 | + if (in_array($this->info['scheme'], $this->knownSchemes)) { |
|
| 227 | 227 | return true; |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | $this->setError( |
| 231 | 231 | URLInfo::ERROR_INVALID_SCHEME, |
| 232 | - t('The scheme %1$s is not supported for links.', $this->info['scheme']) . ' ' . |
|
| 232 | + t('The scheme %1$s is not supported for links.', $this->info['scheme']).' '. |
|
| 233 | 233 | t('Valid schemes are: %1$s.', implode(', ', $this->knownSchemes)) |
| 234 | 234 | ); |
| 235 | 235 | |
@@ -246,23 +246,23 @@ discard block |
||
| 246 | 246 | $this->info['params'] = array(); |
| 247 | 247 | $this->info['type'] = URLInfo::TYPE_URL; |
| 248 | 248 | |
| 249 | - if(isset($this->info['user'])) { |
|
| 249 | + if (isset($this->info['user'])) { |
|
| 250 | 250 | $this->info['user'] = urldecode($this->info['user']); |
| 251 | 251 | } |
| 252 | 252 | |
| 253 | - if(isset($this->info['pass'])) { |
|
| 253 | + if (isset($this->info['pass'])) { |
|
| 254 | 254 | $this->info['pass'] = urldecode($this->info['pass']); |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - if(isset($this->info['host'])) { |
|
| 257 | + if (isset($this->info['host'])) { |
|
| 258 | 258 | $this->info['host'] = str_replace(' ', '', $this->info['host']); |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - if(isset($this->info['path'])) { |
|
| 261 | + if (isset($this->info['path'])) { |
|
| 262 | 262 | $this->info['path'] = str_replace(' ', '', $this->info['path']); |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - if(isset($this->info['query']) && !empty($this->info['query'])) |
|
| 265 | + if (isset($this->info['query']) && !empty($this->info['query'])) |
|
| 266 | 266 | { |
| 267 | 267 | $this->info['params'] = \AppUtils\ConvertHelper::parseQueryString($this->info['query']); |
| 268 | 268 | ksort($this->info['params']); |
@@ -280,9 +280,9 @@ discard block |
||
| 280 | 280 | { |
| 281 | 281 | $result = array(); |
| 282 | 282 | |
| 283 | - foreach($subject as $key => $val) |
|
| 283 | + foreach ($subject as $key => $val) |
|
| 284 | 284 | { |
| 285 | - if(is_array($val)) |
|
| 285 | + if (is_array($val)) |
|
| 286 | 286 | { |
| 287 | 287 | $val = $this->restoreUnicodeChars($val); |
| 288 | 288 | } |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | */ |
| 309 | 309 | protected function restoreUnicodeChar(string $string) : string |
| 310 | 310 | { |
| 311 | - if(strstr($string, '%')) |
|
| 311 | + if (strstr($string, '%')) |
|
| 312 | 312 | { |
| 313 | 313 | return str_replace(array_keys($this->unicodeChars), array_values($this->unicodeChars), $string); |
| 314 | 314 | } |
@@ -318,12 +318,12 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | protected function detectType_email() : bool |
| 320 | 320 | { |
| 321 | - if(isset($this->info['scheme']) && $this->info['scheme'] == 'mailto') { |
|
| 321 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'mailto') { |
|
| 322 | 322 | $this->info['type'] = URLInfo::TYPE_EMAIL; |
| 323 | 323 | return true; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - if(isset($this->info['path']) && preg_match(\AppUtils\RegexHelper::REGEX_EMAIL, $this->info['path'])) |
|
| 326 | + if (isset($this->info['path']) && preg_match(\AppUtils\RegexHelper::REGEX_EMAIL, $this->info['path'])) |
|
| 327 | 327 | { |
| 328 | 328 | $this->info['scheme'] = 'mailto'; |
| 329 | 329 | $this->info['type'] = URLInfo::TYPE_EMAIL; |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | |
| 336 | 336 | protected function detectType_fragmentLink() : bool |
| 337 | 337 | { |
| 338 | - if(isset($this->info['fragment']) && !isset($this->info['scheme'])) { |
|
| 338 | + if (isset($this->info['fragment']) && !isset($this->info['scheme'])) { |
|
| 339 | 339 | $this->info['type'] = URLInfo::TYPE_FRAGMENT; |
| 340 | 340 | return true; |
| 341 | 341 | } |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | |
| 346 | 346 | protected function detectType_phoneLink() : bool |
| 347 | 347 | { |
| 348 | - if(isset($this->info['scheme']) && $this->info['scheme'] == 'tel') { |
|
| 348 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'tel') { |
|
| 349 | 349 | $this->info['type'] = URLInfo::TYPE_PHONE; |
| 350 | 350 | return true; |
| 351 | 351 | } |
@@ -380,7 +380,7 @@ discard block |
||
| 380 | 380 | */ |
| 381 | 381 | public function getErrorMessage() : string |
| 382 | 382 | { |
| 383 | - if(isset($this->error)) { |
|
| 383 | + if (isset($this->error)) { |
|
| 384 | 384 | return $this->error['message']; |
| 385 | 385 | } |
| 386 | 386 | |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | */ |
| 396 | 396 | public function getErrorCode() : int |
| 397 | 397 | { |
| 398 | - if(isset($this->error)) { |
|
| 398 | + if (isset($this->error)) { |
|
| 399 | 399 | return $this->error['code']; |
| 400 | 400 | } |
| 401 | 401 | |