@@ -261,8 +261,7 @@ |
||
| 261 | 261 | $curlCode, |
| 262 | 262 | curl_error($ch).' | Explanation: '.curl_strerror($curlCode) |
| 263 | 263 | ); |
| 264 | - } |
|
| 265 | - else |
|
| 264 | + } else |
|
| 266 | 265 | { |
| 267 | 266 | $this->response->setBody((string)$output); |
| 268 | 267 | } |
@@ -46,19 +46,19 @@ discard block |
||
| 46 | 46 | protected int $contentLength = 0; |
| 47 | 47 | |
| 48 | 48 | /** |
| 49 | - * @var array<string,string> |
|
| 50 | - */ |
|
| 49 | + * @var array<string,string> |
|
| 50 | + */ |
|
| 51 | 51 | protected $headers = array(); |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @var resource|NULL |
|
| 55 | - */ |
|
| 53 | + /** |
|
| 54 | + * @var resource|NULL |
|
| 55 | + */ |
|
| 56 | 56 | protected $logfilePointer; |
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * Creates a new request helper to send POST data to the specified destination URL. |
|
| 60 | - * @param string $destinationURL |
|
| 61 | - */ |
|
| 58 | + /** |
|
| 59 | + * Creates a new request helper to send POST data to the specified destination URL. |
|
| 60 | + * @param string $destinationURL |
|
| 61 | + */ |
|
| 62 | 62 | public function __construct(string $destinationURL) |
| 63 | 63 | { |
| 64 | 64 | $this->destination = $destinationURL; |
@@ -81,13 +81,13 @@ discard block |
||
| 81 | 81 | return $this->eol; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Sets the timeout for the request, in seconds. If the request |
|
| 86 | - * takes longer, it will be cancelled and an exception triggered. |
|
| 87 | - * |
|
| 88 | - * @param int $seconds |
|
| 89 | - * @return RequestHelper |
|
| 90 | - */ |
|
| 84 | + /** |
|
| 85 | + * Sets the timeout for the request, in seconds. If the request |
|
| 86 | + * takes longer, it will be cancelled and an exception triggered. |
|
| 87 | + * |
|
| 88 | + * @param int $seconds |
|
| 89 | + * @return RequestHelper |
|
| 90 | + */ |
|
| 91 | 91 | public function setTimeout(int $seconds) : RequestHelper |
| 92 | 92 | { |
| 93 | 93 | $this->timeout = $seconds; |
@@ -100,13 +100,13 @@ discard block |
||
| 100 | 100 | return $this->timeout; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Enables verbose logging of the CURL request, which |
|
| 105 | - * is then redirected to the target file. |
|
| 106 | - * |
|
| 107 | - * @param string $targetFile |
|
| 108 | - * @return RequestHelper |
|
| 109 | - */ |
|
| 103 | + /** |
|
| 104 | + * Enables verbose logging of the CURL request, which |
|
| 105 | + * is then redirected to the target file. |
|
| 106 | + * |
|
| 107 | + * @param string $targetFile |
|
| 108 | + * @return RequestHelper |
|
| 109 | + */ |
|
| 110 | 110 | public function enableLogging(string $targetFile) : RequestHelper |
| 111 | 111 | { |
| 112 | 112 | $this->logfile = $targetFile; |
@@ -114,15 +114,15 @@ discard block |
||
| 114 | 114 | return $this; |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Adds a file to be sent with the request. |
|
| 119 | - * |
|
| 120 | - * @param string $varName The variable name to send the file in |
|
| 121 | - * @param string $fileName The name of the file as it should be received at the destination |
|
| 122 | - * @param string $content The raw content of the file |
|
| 123 | - * @param string $contentType The content type, use the constants to specify this |
|
| 124 | - * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 125 | - */ |
|
| 117 | + /** |
|
| 118 | + * Adds a file to be sent with the request. |
|
| 119 | + * |
|
| 120 | + * @param string $varName The variable name to send the file in |
|
| 121 | + * @param string $fileName The name of the file as it should be received at the destination |
|
| 122 | + * @param string $content The raw content of the file |
|
| 123 | + * @param string $contentType The content type, use the constants to specify this |
|
| 124 | + * @param string $encoding The encoding of the file, use the constants to specify this |
|
| 125 | + */ |
|
| 126 | 126 | public function addFile(string $varName, string $fileName, string $content, string $contentType = '', string $encoding = '') : RequestHelper |
| 127 | 127 | { |
| 128 | 128 | $this->boundaries->addFile($varName, $fileName, $content, $contentType, $encoding); |
@@ -160,13 +160,13 @@ discard block |
||
| 160 | 160 | return $this; |
| 161 | 161 | } |
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * Sets an HTTP header to include in the request. |
|
| 165 | - * |
|
| 166 | - * @param string $name |
|
| 167 | - * @param string $value |
|
| 168 | - * @return RequestHelper |
|
| 169 | - */ |
|
| 163 | + /** |
|
| 164 | + * Sets an HTTP header to include in the request. |
|
| 165 | + * |
|
| 166 | + * @param string $name |
|
| 167 | + * @param string $value |
|
| 168 | + * @return RequestHelper |
|
| 169 | + */ |
|
| 170 | 170 | public function setHeader(string $name, string $value) : RequestHelper |
| 171 | 171 | { |
| 172 | 172 | $this->headers[$name] = $value; |
@@ -174,31 +174,31 @@ discard block |
||
| 174 | 174 | return $this; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Disables SSL certificate checking. |
|
| 179 | - * |
|
| 180 | - * @return RequestHelper |
|
| 181 | - */ |
|
| 177 | + /** |
|
| 178 | + * Disables SSL certificate checking. |
|
| 179 | + * |
|
| 180 | + * @return RequestHelper |
|
| 181 | + */ |
|
| 182 | 182 | public function disableSSLChecks() : RequestHelper |
| 183 | 183 | { |
| 184 | 184 | $this->verifySSL = false; |
| 185 | 185 | return $this; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * Sends the POST request to the destination, and returns |
|
| 190 | - * the response text. |
|
| 191 | - * |
|
| 192 | - * The response object is stored internally, so after calling |
|
| 193 | - * this method it may be retrieved at any moment using the |
|
| 194 | - * {@link getResponse()} method. |
|
| 195 | - * |
|
| 196 | - * @return string |
|
| 197 | - * @see RequestHelper::getResponse() |
|
| 198 | - * @throws RequestHelper_Exception |
|
| 199 | - * |
|
| 200 | - * @see RequestHelper::ERROR_REQUEST_FAILED |
|
| 201 | - */ |
|
| 188 | + /** |
|
| 189 | + * Sends the POST request to the destination, and returns |
|
| 190 | + * the response text. |
|
| 191 | + * |
|
| 192 | + * The response object is stored internally, so after calling |
|
| 193 | + * this method it may be retrieved at any moment using the |
|
| 194 | + * {@link getResponse()} method. |
|
| 195 | + * |
|
| 196 | + * @return string |
|
| 197 | + * @see RequestHelper::getResponse() |
|
| 198 | + * @throws RequestHelper_Exception |
|
| 199 | + * |
|
| 200 | + * @see RequestHelper::ERROR_REQUEST_FAILED |
|
| 201 | + */ |
|
| 202 | 202 | public function send() : string |
| 203 | 203 | { |
| 204 | 204 | $info = parseURL($this->destination); |
@@ -238,13 +238,13 @@ discard block |
||
| 238 | 238 | return $this->response->getResponseBody(); |
| 239 | 239 | } |
| 240 | 240 | |
| 241 | - /** |
|
| 242 | - * Retrieves the request's body content. This is an alias |
|
| 243 | - * for {@see RequestHelper::getMimeBody()}. |
|
| 244 | - * |
|
| 245 | - * @return string |
|
| 246 | - * @see RequestHelper::getMimeBody() |
|
| 247 | - */ |
|
| 241 | + /** |
|
| 242 | + * Retrieves the request's body content. This is an alias |
|
| 243 | + * for {@see RequestHelper::getMimeBody()}. |
|
| 244 | + * |
|
| 245 | + * @return string |
|
| 246 | + * @see RequestHelper::getMimeBody() |
|
| 247 | + */ |
|
| 248 | 248 | public function getBody() : string |
| 249 | 249 | { |
| 250 | 250 | return $this->getMimeBody(); |
@@ -276,14 +276,14 @@ discard block |
||
| 276 | 276 | ); |
| 277 | 277 | } |
| 278 | 278 | |
| 279 | - /** |
|
| 280 | - * Creates a new CURL resource configured according to the |
|
| 281 | - * request's settings. |
|
| 282 | - * |
|
| 283 | - * @param URLInfo $url |
|
| 284 | - * @throws RequestHelper_Exception |
|
| 285 | - * @return resource |
|
| 286 | - */ |
|
| 279 | + /** |
|
| 280 | + * Creates a new CURL resource configured according to the |
|
| 281 | + * request's settings. |
|
| 282 | + * |
|
| 283 | + * @param URLInfo $url |
|
| 284 | + * @throws RequestHelper_Exception |
|
| 285 | + * @return resource |
|
| 286 | + */ |
|
| 287 | 287 | protected function configureCURL(URLInfo $url) |
| 288 | 288 | { |
| 289 | 289 | $ch = self::createCURL(); |
@@ -353,13 +353,13 @@ discard block |
||
| 353 | 353 | return true; |
| 354 | 354 | } |
| 355 | 355 | |
| 356 | - /** |
|
| 357 | - * Compiles the associative headers array into |
|
| 358 | - * the format understood by CURL, namely an indexed |
|
| 359 | - * array with one header string per entry. |
|
| 360 | - * |
|
| 361 | - * @return string[] |
|
| 362 | - */ |
|
| 356 | + /** |
|
| 357 | + * Compiles the associative headers array into |
|
| 358 | + * the format understood by CURL, namely an indexed |
|
| 359 | + * array with one header string per entry. |
|
| 360 | + * |
|
| 361 | + * @return string[] |
|
| 362 | + */ |
|
| 363 | 363 | protected function renderHeaders() : array |
| 364 | 364 | { |
| 365 | 365 | $result = array(); |
@@ -373,12 +373,12 @@ discard block |
||
| 373 | 373 | return $result; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | - /** |
|
| 377 | - * Retrieves the raw response header, in the form of an indexed |
|
| 378 | - * array containing all response header lines. |
|
| 379 | - * |
|
| 380 | - * @return string[] |
|
| 381 | - */ |
|
| 376 | + /** |
|
| 377 | + * Retrieves the raw response header, in the form of an indexed |
|
| 378 | + * array containing all response header lines. |
|
| 379 | + * |
|
| 380 | + * @return string[] |
|
| 381 | + */ |
|
| 382 | 382 | public function getResponseHeader() : array |
| 383 | 383 | { |
| 384 | 384 | $response = $this->getResponse(); |
@@ -390,33 +390,33 @@ discard block |
||
| 390 | 390 | return array(); |
| 391 | 391 | } |
| 392 | 392 | |
| 393 | - /** |
|
| 394 | - * After calling the {@link send()} method, this may be used to |
|
| 395 | - * retrieve the response text from the POST request. |
|
| 396 | - * |
|
| 397 | - * @return RequestHelper_Response|NULL |
|
| 398 | - */ |
|
| 393 | + /** |
|
| 394 | + * After calling the {@link send()} method, this may be used to |
|
| 395 | + * retrieve the response text from the POST request. |
|
| 396 | + * |
|
| 397 | + * @return RequestHelper_Response|NULL |
|
| 398 | + */ |
|
| 399 | 399 | public function getResponse() : ?RequestHelper_Response |
| 400 | 400 | { |
| 401 | 401 | return $this->response; |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - /** |
|
| 405 | - * Retrieves all headers set until now. |
|
| 406 | - * |
|
| 407 | - * @return array<string,string> |
|
| 408 | - */ |
|
| 404 | + /** |
|
| 405 | + * Retrieves all headers set until now. |
|
| 406 | + * |
|
| 407 | + * @return array<string,string> |
|
| 408 | + */ |
|
| 409 | 409 | public function getHeaders() : array |
| 410 | 410 | { |
| 411 | 411 | return $this->headers; |
| 412 | 412 | } |
| 413 | 413 | |
| 414 | - /** |
|
| 415 | - * Retrieves the value of a header by its name. |
|
| 416 | - * |
|
| 417 | - * @param string $name |
|
| 418 | - * @return string The header value, or an empty string if not set. |
|
| 419 | - */ |
|
| 414 | + /** |
|
| 415 | + * Retrieves the value of a header by its name. |
|
| 416 | + * |
|
| 417 | + * @param string $name |
|
| 418 | + * @return string The header value, or an empty string if not set. |
|
| 419 | + */ |
|
| 420 | 420 | public function getHeader(string $name) : string |
| 421 | 421 | { |
| 422 | 422 | return $this->headers[$name] ?? ''; |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | |
| 208 | 208 | $output = curl_exec($ch); |
| 209 | 209 | |
| 210 | - if(isset($this->logfilePointer)) |
|
| 210 | + if (isset($this->logfilePointer)) |
|
| 211 | 211 | { |
| 212 | 212 | fclose($this->logfilePointer); |
| 213 | 213 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | // CURL will complain about an empty response when the |
| 220 | 220 | // server sends a 100-continue code. That should not be |
| 221 | 221 | // regarded as an error. |
| 222 | - if($output === false && $this->response->getCode() !== 100) |
|
| 222 | + if ($output === false && $this->response->getCode() !== 100) |
|
| 223 | 223 | { |
| 224 | 224 | $curlCode = curl_errno($ch); |
| 225 | 225 | |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | { |
| 262 | 262 | $ch = curl_init(); |
| 263 | 263 | |
| 264 | - if($ch instanceof CurlHandle || is_resource($ch)) |
|
| 264 | + if ($ch instanceof CurlHandle || is_resource($ch)) |
|
| 265 | 265 | { |
| 266 | 266 | return $ch; |
| 267 | 267 | } |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | $ch = self::createCURL(); |
| 290 | 290 | |
| 291 | 291 | $this->setHeader('Content-Length', (string)$this->boundaries->getContentLength()); |
| 292 | - $this->setHeader('Content-Type', 'multipart/form-data; boundary=' . $this->mimeBoundary); |
|
| 292 | + $this->setHeader('Content-Type', 'multipart/form-data; boundary='.$this->mimeBoundary); |
|
| 293 | 293 | |
| 294 | 294 | curl_setopt($ch, CURLOPT_POST, true); |
| 295 | 295 | curl_setopt($ch, CURLOPT_URL, $url->getNormalizedWithoutAuth()); |
@@ -302,18 +302,18 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | $loggingEnabled = $this->configureLogging($ch); |
| 304 | 304 | |
| 305 | - if(!$loggingEnabled) |
|
| 305 | + if (!$loggingEnabled) |
|
| 306 | 306 | { |
| 307 | 307 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if($this->verifySSL) |
|
| 310 | + if ($this->verifySSL) |
|
| 311 | 311 | { |
| 312 | 312 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
| 313 | 313 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - if($url->hasUsername()) |
|
| 316 | + if ($url->hasUsername()) |
|
| 317 | 317 | { |
| 318 | 318 | curl_setopt($ch, CURLOPT_USERNAME, $url->getUsername()); |
| 319 | 319 | curl_setopt($ch, CURLOPT_PASSWORD, $url->getPassword()); |
@@ -329,14 +329,14 @@ discard block |
||
| 329 | 329 | */ |
| 330 | 330 | protected function configureLogging($ch) : bool |
| 331 | 331 | { |
| 332 | - if(empty($this->logfile)) |
|
| 332 | + if (empty($this->logfile)) |
|
| 333 | 333 | { |
| 334 | 334 | return false; |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | $res = fopen($this->logfile, 'wb+'); |
| 338 | 338 | |
| 339 | - if($res === false) |
|
| 339 | + if ($res === false) |
|
| 340 | 340 | { |
| 341 | 341 | throw new RequestHelper_Exception( |
| 342 | 342 | 'Cannot open logfile for writing.', |
@@ -366,7 +366,7 @@ discard block |
||
| 366 | 366 | |
| 367 | 367 | $this->setHeader('Expect', ''); |
| 368 | 368 | |
| 369 | - foreach($this->headers as $name => $value) { |
|
| 369 | + foreach ($this->headers as $name => $value) { |
|
| 370 | 370 | $result[] = $name.': '.$value; |
| 371 | 371 | } |
| 372 | 372 | |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | { |
| 384 | 384 | $response = $this->getResponse(); |
| 385 | 385 | |
| 386 | - if($response !== null) { |
|
| 386 | + if ($response !== null) { |
|
| 387 | 387 | return $response->getHeaders(); |
| 388 | 388 | } |
| 389 | 389 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public static function json($subject) : string |
| 110 | 110 | { |
| 111 | - if(!is_string($subject)) |
|
| 111 | + if (!is_string($subject)) |
|
| 112 | 112 | { |
| 113 | 113 | $subject = json_encode($subject, JSON_PRETTY_PRINT); |
| 114 | 114 | } |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | * @param bool $formatSource Whether to format the source with indentation to make it readable. |
| 126 | 126 | * @return string |
| 127 | 127 | */ |
| 128 | - public static function xml(string $xml, bool $formatSource=false) : string |
|
| 128 | + public static function xml(string $xml, bool $formatSource = false) : string |
|
| 129 | 129 | { |
| 130 | - if($formatSource) |
|
| 130 | + if ($formatSource) |
|
| 131 | 131 | { |
| 132 | 132 | $dom = new DOMDocument(); |
| 133 | 133 | $dom->preserveWhiteSpace = false; |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | * @param bool $formatSource |
| 149 | 149 | * @return string |
| 150 | 150 | */ |
| 151 | - public static function html(string $html, bool $formatSource=false) : string |
|
| 151 | + public static function html(string $html, bool $formatSource = false) : string |
|
| 152 | 152 | { |
| 153 | - if($formatSource) |
|
| 153 | + if ($formatSource) |
|
| 154 | 154 | { |
| 155 | 155 | $dom = new DOMDocument(); |
| 156 | 156 | $dom->preserveWhiteSpace = false; |
@@ -41,71 +41,71 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | class Highlighter |
| 43 | 43 | { |
| 44 | - /** |
|
| 45 | - * Creates a new GeSHi instance from a source code string. |
|
| 46 | - * |
|
| 47 | - * @param string $sourceCode |
|
| 48 | - * @param string $format |
|
| 49 | - * @return GeSHi |
|
| 50 | - */ |
|
| 44 | + /** |
|
| 45 | + * Creates a new GeSHi instance from a source code string. |
|
| 46 | + * |
|
| 47 | + * @param string $sourceCode |
|
| 48 | + * @param string $format |
|
| 49 | + * @return GeSHi |
|
| 50 | + */ |
|
| 51 | 51 | public static function fromString(string $sourceCode, string $format) : GeSHi |
| 52 | 52 | { |
| 53 | 53 | return new GeSHi($sourceCode, $format); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * Creates a new GeSHi instance from the contents of a file. |
|
| 58 | - * |
|
| 59 | - * @param string $path |
|
| 60 | - * @param string $format |
|
| 61 | - * @return GeSHi |
|
| 62 | - */ |
|
| 56 | + /** |
|
| 57 | + * Creates a new GeSHi instance from the contents of a file. |
|
| 58 | + * |
|
| 59 | + * @param string $path |
|
| 60 | + * @param string $format |
|
| 61 | + * @return GeSHi |
|
| 62 | + */ |
|
| 63 | 63 | public static function fromFile(string $path, string $format) : GeSHi |
| 64 | 64 | { |
| 65 | 65 | return self::fromString(FileHelper::readContents($path), $format); |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Parses and highlights the target string. |
|
| 70 | - * |
|
| 71 | - * @param string $sourceCode |
|
| 72 | - * @param string $format |
|
| 73 | - * @return string |
|
| 74 | - */ |
|
| 68 | + /** |
|
| 69 | + * Parses and highlights the target string. |
|
| 70 | + * |
|
| 71 | + * @param string $sourceCode |
|
| 72 | + * @param string $format |
|
| 73 | + * @return string |
|
| 74 | + */ |
|
| 75 | 75 | public static function parseString(string $sourceCode, string $format) : string |
| 76 | 76 | { |
| 77 | 77 | return self::fromString($sourceCode, $format)->parse_code(); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * Parses and highlights the contents of the target file. |
|
| 82 | - * |
|
| 83 | - * @param string $path |
|
| 84 | - * @param string $format |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 80 | + /** |
|
| 81 | + * Parses and highlights the contents of the target file. |
|
| 82 | + * |
|
| 83 | + * @param string $path |
|
| 84 | + * @param string $format |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | 87 | public static function parseFile(string $path, string $format) : string |
| 88 | 88 | { |
| 89 | 89 | return self::fromFile($path, $format)->parse_code(); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Adds HTML syntax highlighting to the specified SQL string. |
|
| 94 | - * |
|
| 95 | - * @param string $sql |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 92 | + /** |
|
| 93 | + * Adds HTML syntax highlighting to the specified SQL string. |
|
| 94 | + * |
|
| 95 | + * @param string $sql |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | 98 | public static function sql(string $sql) : string |
| 99 | 99 | { |
| 100 | 100 | return self::parseString($sql, 'sql'); |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * Adds HTML syntax highlighting to a JSON string, or a data array/object. |
|
| 105 | - * |
|
| 106 | - * @param array<int|string,mixed>|object|string $subject A JSON string, or data array/object to convert to JSON to highlight. |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 103 | + /** |
|
| 104 | + * Adds HTML syntax highlighting to a JSON string, or a data array/object. |
|
| 105 | + * |
|
| 106 | + * @param array<int|string,mixed>|object|string $subject A JSON string, or data array/object to convert to JSON to highlight. |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | 109 | public static function json($subject) : string |
| 110 | 110 | { |
| 111 | 111 | if(!is_string($subject)) |
@@ -118,13 +118,13 @@ discard block |
||
| 118 | 118 | return self::parseString($subject, 'javascript'); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Adds HTML syntax highlighting to the specified XML code. |
|
| 123 | - * |
|
| 124 | - * @param string $xml The XML to highlight. |
|
| 125 | - * @param bool $formatSource Whether to format the source with indentation to make it readable. |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 121 | + /** |
|
| 122 | + * Adds HTML syntax highlighting to the specified XML code. |
|
| 123 | + * |
|
| 124 | + * @param string $xml The XML to highlight. |
|
| 125 | + * @param bool $formatSource Whether to format the source with indentation to make it readable. |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | 128 | public static function xml(string $xml, bool $formatSource=false) : string |
| 129 | 129 | { |
| 130 | 130 | if($formatSource) |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | return self::parseString($xml, 'xml'); |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * Adds HTML syntax highlighting to the specified HTML code. |
|
| 146 | - * |
|
| 147 | - * @param string $html |
|
| 148 | - * @param bool $formatSource |
|
| 149 | - * @return string |
|
| 150 | - */ |
|
| 144 | + /** |
|
| 145 | + * Adds HTML syntax highlighting to the specified HTML code. |
|
| 146 | + * |
|
| 147 | + * @param string $html |
|
| 148 | + * @param bool $formatSource |
|
| 149 | + * @return string |
|
| 150 | + */ |
|
| 151 | 151 | public static function html(string $html, bool $formatSource=false) : string |
| 152 | 152 | { |
| 153 | 153 | if($formatSource) |
@@ -164,27 +164,27 @@ discard block |
||
| 164 | 164 | return self::parseString($html, 'xml'); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Adds HTML syntax highlighting to a bit of PHP code. |
|
| 169 | - * |
|
| 170 | - * @param string $phpCode |
|
| 171 | - * @return string |
|
| 172 | - */ |
|
| 167 | + /** |
|
| 168 | + * Adds HTML syntax highlighting to a bit of PHP code. |
|
| 169 | + * |
|
| 170 | + * @param string $phpCode |
|
| 171 | + * @return string |
|
| 172 | + */ |
|
| 173 | 173 | public static function php(string $phpCode) : string |
| 174 | 174 | { |
| 175 | 175 | return self::parseString($phpCode, 'php'); |
| 176 | 176 | } |
| 177 | 177 | |
| 178 | - /** |
|
| 179 | - * Adds HTML syntax highlighting to an URL. |
|
| 180 | - * |
|
| 181 | - * NOTE: Includes the necessary CSS styles. When |
|
| 182 | - * highlighting several URLs in the same page, |
|
| 183 | - * prefer using the `parseURL` function instead. |
|
| 184 | - * |
|
| 185 | - * @param string $url |
|
| 186 | - * @return string |
|
| 187 | - */ |
|
| 178 | + /** |
|
| 179 | + * Adds HTML syntax highlighting to an URL. |
|
| 180 | + * |
|
| 181 | + * NOTE: Includes the necessary CSS styles. When |
|
| 182 | + * highlighting several URLs in the same page, |
|
| 183 | + * prefer using the `parseURL` function instead. |
|
| 184 | + * |
|
| 185 | + * @param string $url |
|
| 186 | + * @return string |
|
| 187 | + */ |
|
| 188 | 188 | public static function url(string $url) : string |
| 189 | 189 | { |
| 190 | 190 | $info = parseURL($url); |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | private function initUnits() : void |
| 50 | 50 | { |
| 51 | - if(isset(self::$units)) |
|
| 51 | + if (isset(self::$units)) |
|
| 52 | 52 | { |
| 53 | 53 | return; |
| 54 | 54 | } |
@@ -90,12 +90,12 @@ discard block |
||
| 90 | 90 | public function toString() : string |
| 91 | 91 | { |
| 92 | 92 | // specifically handle zero |
| 93 | - if($this->seconds <= 0) |
|
| 93 | + if ($this->seconds <= 0) |
|
| 94 | 94 | { |
| 95 | - return '0 ' . t('seconds'); |
|
| 95 | + return '0 '.t('seconds'); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - if($this->seconds < 1) |
|
| 98 | + if ($this->seconds < 1) |
|
| 99 | 99 | { |
| 100 | 100 | return t('less than a second'); |
| 101 | 101 | } |
@@ -104,12 +104,12 @@ discard block |
||
| 104 | 104 | |
| 105 | 105 | $last = array_pop($tokens); |
| 106 | 106 | |
| 107 | - if(empty($tokens)) |
|
| 107 | + if (empty($tokens)) |
|
| 108 | 108 | { |
| 109 | 109 | return $last; |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | - return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
|
| 112 | + return implode(', ', $tokens).' '.t('and').' '.$last; |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -122,18 +122,18 @@ discard block |
||
| 122 | 122 | $seconds = $this->seconds; |
| 123 | 123 | $tokens = array(); |
| 124 | 124 | |
| 125 | - foreach(self::$units as $def) |
|
| 125 | + foreach (self::$units as $def) |
|
| 126 | 126 | { |
| 127 | 127 | $unitValue = intval($seconds / $def['value']); |
| 128 | 128 | |
| 129 | - if($unitValue <= 0) |
|
| 129 | + if ($unitValue <= 0) |
|
| 130 | 130 | { |
| 131 | 131 | continue; |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - $item = strval($unitValue) . ' '; |
|
| 134 | + $item = strval($unitValue).' '; |
|
| 135 | 135 | |
| 136 | - if(abs($unitValue) > 1) |
|
| 136 | + if (abs($unitValue) > 1) |
|
| 137 | 137 | { |
| 138 | 138 | $item .= $def['plural']; |
| 139 | 139 | } |
@@ -136,8 +136,7 @@ |
||
| 136 | 136 | if(abs($unitValue) > 1) |
| 137 | 137 | { |
| 138 | 138 | $item .= $def['plural']; |
| 139 | - } |
|
| 140 | - else |
|
| 139 | + } else |
|
| 141 | 140 | { |
| 142 | 141 | $item .= $def['singular']; |
| 143 | 142 | } |
@@ -23,19 +23,19 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class ConvertHelper_TimeConverter |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @var float |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var float |
|
| 28 | + */ |
|
| 29 | 29 | private $seconds; |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @var array<int,array<string,string|int>>|NULL |
|
| 33 | - */ |
|
| 31 | + /** |
|
| 32 | + * @var array<int,array<string,string|int>>|NULL |
|
| 33 | + */ |
|
| 34 | 34 | private static $units; |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param float $seconds |
|
| 38 | - */ |
|
| 36 | + /** |
|
| 37 | + * @param float $seconds |
|
| 38 | + */ |
|
| 39 | 39 | public function __construct($seconds) |
| 40 | 40 | { |
| 41 | 41 | $this->seconds = $seconds; |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | $this->initUnits(); |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Creates the list of units once per request as needed. |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * Creates the list of units once per request as needed. |
|
| 48 | + */ |
|
| 49 | 49 | private function initUnits() : void |
| 50 | 50 | { |
| 51 | 51 | if(isset(self::$units)) |
@@ -112,11 +112,11 @@ discard block |
||
| 112 | 112 | return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Resolves the list of converted units. |
|
| 117 | - * |
|
| 118 | - * @return string[] |
|
| 119 | - */ |
|
| 115 | + /** |
|
| 116 | + * Resolves the list of converted units. |
|
| 117 | + * |
|
| 118 | + * @return string[] |
|
| 119 | + */ |
|
| 120 | 120 | private function resolveTokens() : array |
| 121 | 121 | { |
| 122 | 122 | $seconds = $this->seconds; |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | $autoload = $root.'/vendor/autoload.php'; |
| 16 | 16 | |
| 17 | 17 | // we need the autoloader to be present |
| 18 | - if($autoload === false) |
|
| 18 | + if ($autoload === false) |
|
| 19 | 19 | { |
| 20 | 20 | die('<b>ERROR:</b> Autoloader not present. Run composer update first.'); |
| 21 | 21 | } |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public static function detect(string $subjectString) : ?ConvertHelper_EOL |
| 123 | 123 | { |
| 124 | - if(empty($subjectString)) { |
|
| 124 | + if (empty($subjectString)) { |
|
| 125 | 125 | return null; |
| 126 | 126 | } |
| 127 | 127 | |
@@ -129,18 +129,18 @@ discard block |
||
| 129 | 129 | $results = array(); |
| 130 | 130 | $chars = self::getEOLChars(); |
| 131 | 131 | |
| 132 | - foreach($chars as $def) |
|
| 132 | + foreach ($chars as $def) |
|
| 133 | 133 | { |
| 134 | 134 | $amount = substr_count($subjectString, $def['char']); |
| 135 | 135 | |
| 136 | - if($amount > $max) |
|
| 136 | + if ($amount > $max) |
|
| 137 | 137 | { |
| 138 | 138 | $max = $amount; |
| 139 | 139 | $results[] = $def; |
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if(empty($results)) { |
|
| 143 | + if (empty($results)) { |
|
| 144 | 144 | return null; |
| 145 | 145 | } |
| 146 | 146 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | */ |
| 157 | 157 | public static function getEOLChars() : array |
| 158 | 158 | { |
| 159 | - if(isset(self::$eolChars)) { |
|
| 159 | + if (isset(self::$eolChars)) { |
|
| 160 | 160 | return self::$eolChars; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -29,19 +29,19 @@ discard block |
||
| 29 | 29 | public const TYPE_LF = 'LF'; |
| 30 | 30 | public const TYPE_CR = 'CR'; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | 35 | protected $char; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | 40 | protected $type; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | 45 | protected $description; |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -56,33 +56,33 @@ discard block |
||
| 56 | 56 | $this->description = $description; |
| 57 | 57 | } |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * The actual EOL character. |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 59 | + /** |
|
| 60 | + * The actual EOL character. |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | 63 | public function getCharacter() : string |
| 64 | 64 | { |
| 65 | 65 | return $this->char; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * A more detailed, human readable description of the character. |
|
| 70 | - * @return string |
|
| 71 | - */ |
|
| 68 | + /** |
|
| 69 | + * A more detailed, human readable description of the character. |
|
| 70 | + * @return string |
|
| 71 | + */ |
|
| 72 | 72 | public function getDescription() : string |
| 73 | 73 | { |
| 74 | 74 | return $this->description; |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * The EOL character type, e.g. "CR+LF", "CR"... |
|
| 79 | - * @return string |
|
| 80 | - * |
|
| 81 | - * @see ConvertHelper_EOL::TYPE_CR |
|
| 82 | - * @see ConvertHelper_EOL::TYPE_CRLF |
|
| 83 | - * @see ConvertHelper_EOL::TYPE_LF |
|
| 84 | - * @see ConvertHelper_EOL::TYPE_LFCR |
|
| 85 | - */ |
|
| 77 | + /** |
|
| 78 | + * The EOL character type, e.g. "CR+LF", "CR"... |
|
| 79 | + * @return string |
|
| 80 | + * |
|
| 81 | + * @see ConvertHelper_EOL::TYPE_CR |
|
| 82 | + * @see ConvertHelper_EOL::TYPE_CRLF |
|
| 83 | + * @see ConvertHelper_EOL::TYPE_LF |
|
| 84 | + * @see ConvertHelper_EOL::TYPE_LFCR |
|
| 85 | + */ |
|
| 86 | 86 | public function getType() : string |
| 87 | 87 | { |
| 88 | 88 | return $this->type; |
@@ -13,20 +13,20 @@ discard block |
||
| 13 | 13 | $string = ''; |
| 14 | 14 | |
| 15 | 15 | // Simple function call |
| 16 | - if(is_string($this->value)) |
|
| 16 | + if (is_string($this->value)) |
|
| 17 | 17 | { |
| 18 | 18 | return $this->value.'()'; |
| 19 | 19 | } |
| 20 | 20 | |
| 21 | - if(is_array($this->value)) { |
|
| 21 | + if (is_array($this->value)) { |
|
| 22 | 22 | return $this->renderArray(); |
| 23 | 23 | } |
| 24 | 24 | |
| 25 | - if($this->value instanceof NamedClosure) { |
|
| 25 | + if ($this->value instanceof NamedClosure) { |
|
| 26 | 26 | return 'Closure:'.$this->value->getOrigin(); |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | - if($this->value instanceof Closure) { |
|
| 29 | + if ($this->value instanceof Closure) { |
|
| 30 | 30 | return 'Closure'; |
| 31 | 31 | } |
| 32 | 32 | |
@@ -38,9 +38,9 @@ discard block |
||
| 38 | 38 | $string = ''; |
| 39 | 39 | |
| 40 | 40 | if (is_string($this->value[0])) { |
| 41 | - $string .= $this->value[0] . '::'; |
|
| 41 | + $string .= $this->value[0].'::'; |
|
| 42 | 42 | } else { |
| 43 | - $string .= get_class($this->value[0]) . '->'; |
|
| 43 | + $string .= get_class($this->value[0]).'->'; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | $string .= $this->value[1].'()'; |
@@ -43,9 +43,9 @@ |
||
| 43 | 43 | |
| 44 | 44 | $result = array(); |
| 45 | 45 | $matches = array_unique($matches[2]); |
| 46 | - foreach($matches as $match) { |
|
| 46 | + foreach ($matches as $match) { |
|
| 47 | 47 | $match = trim($match); |
| 48 | - if(!empty($match) && !in_array($match, $result)) { |
|
| 48 | + if (!empty($match) && !in_array($match, $result)) { |
|
| 49 | 49 | $result[] = $match; |
| 50 | 50 | } |
| 51 | 51 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | |
| 35 | 35 | public function __construct() |
| 36 | 36 | { |
| 37 | - if(empty(self::$cacheFile)) { |
|
| 37 | + if (empty(self::$cacheFile)) { |
|
| 38 | 38 | self::$cacheFile = __DIR__.'/tlds-alpha-by-domain.txt'; |
| 39 | 39 | } |
| 40 | 40 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | private function load() : void |
| 60 | 60 | { |
| 61 | - if(!empty(self::$names)) { |
|
| 61 | + if (!empty(self::$names)) { |
|
| 62 | 62 | return; |
| 63 | 63 | } |
| 64 | 64 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | // Store the names as keys in the array to allow |
| 70 | 70 | // faster lookups (to avoid using in_array). |
| 71 | - foreach($names as $name) { |
|
| 71 | + foreach ($names as $name) { |
|
| 72 | 72 | self::$names[$name] = ''; |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -110,38 +110,38 @@ discard block |
||
| 110 | 110 | return $this; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Whether to enable sorting the URLs alphabetically (disabled by default). |
|
| 115 | - * |
|
| 116 | - * @param bool $enabled |
|
| 117 | - * @return $this |
|
| 118 | - */ |
|
| 113 | + /** |
|
| 114 | + * Whether to enable sorting the URLs alphabetically (disabled by default). |
|
| 115 | + * |
|
| 116 | + * @param bool $enabled |
|
| 117 | + * @return $this |
|
| 118 | + */ |
|
| 119 | 119 | public function enableSorting(bool $enabled=true) : ConvertHelper_URLFinder |
| 120 | 120 | { |
| 121 | 121 | $this->setOption('sorting', $enabled); |
| 122 | 122 | return $this; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Whether to include email addresses in the search. |
|
| 127 | - * This is only relevant when using the getURLs() |
|
| 128 | - * method. |
|
| 129 | - * |
|
| 130 | - * @param bool $include |
|
| 131 | - * @return ConvertHelper_URLFinder |
|
| 132 | - */ |
|
| 125 | + /** |
|
| 126 | + * Whether to include email addresses in the search. |
|
| 127 | + * This is only relevant when using the getURLs() |
|
| 128 | + * method. |
|
| 129 | + * |
|
| 130 | + * @param bool $include |
|
| 131 | + * @return ConvertHelper_URLFinder |
|
| 132 | + */ |
|
| 133 | 133 | public function includeEmails(bool $include=true) : ConvertHelper_URLFinder |
| 134 | 134 | { |
| 135 | 135 | $this->setOption('include-emails', $include); |
| 136 | 136 | return $this; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Whether to omit the mailto: that is automatically added to all email addresses. |
|
| 141 | - * |
|
| 142 | - * @param bool $omit |
|
| 143 | - * @return ConvertHelper_URLFinder |
|
| 144 | - */ |
|
| 139 | + /** |
|
| 140 | + * Whether to omit the mailto: that is automatically added to all email addresses. |
|
| 141 | + * |
|
| 142 | + * @param bool $omit |
|
| 143 | + * @return ConvertHelper_URLFinder |
|
| 144 | + */ |
|
| 145 | 145 | public function omitMailto(bool $omit=true) : ConvertHelper_URLFinder |
| 146 | 146 | { |
| 147 | 147 | $this->setOption('omit-mailto', $omit); |
@@ -267,11 +267,11 @@ discard block |
||
| 267 | 267 | ); |
| 268 | 268 | } |
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * Fetches all URLs that can be found in the subject string. |
|
| 272 | - * |
|
| 273 | - * @return string[] |
|
| 274 | - */ |
|
| 270 | + /** |
|
| 271 | + * Fetches all URLs that can be found in the subject string. |
|
| 272 | + * |
|
| 273 | + * @return string[] |
|
| 274 | + */ |
|
| 275 | 275 | public function getURLs() : array |
| 276 | 276 | { |
| 277 | 277 | $this->parse(); |
@@ -474,13 +474,13 @@ discard block |
||
| 474 | 474 | return array_pop($parts); |
| 475 | 475 | } |
| 476 | 476 | |
| 477 | - /** |
|
| 478 | - * Retrieves all email addresses from the subject string. |
|
| 479 | - * |
|
| 480 | - * @return string[] |
|
| 481 | - * |
|
| 482 | - * @see omitMailto() |
|
| 483 | - */ |
|
| 477 | + /** |
|
| 478 | + * Retrieves all email addresses from the subject string. |
|
| 479 | + * |
|
| 480 | + * @return string[] |
|
| 481 | + * |
|
| 482 | + * @see omitMailto() |
|
| 483 | + */ |
|
| 484 | 484 | public function getEmails() : array |
| 485 | 485 | { |
| 486 | 486 | $this->parse(); |
@@ -506,11 +506,11 @@ discard block |
||
| 506 | 506 | return $result; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | - /** |
|
| 510 | - * Retrieves all URLs as URLInfo instances. |
|
| 511 | - * |
|
| 512 | - * @return URLInfo[] |
|
| 513 | - */ |
|
| 509 | + /** |
|
| 510 | + * Retrieves all URLs as URLInfo instances. |
|
| 511 | + * |
|
| 512 | + * @return URLInfo[] |
|
| 513 | + */ |
|
| 514 | 514 | public function getInfos() : array |
| 515 | 515 | { |
| 516 | 516 | $this->parse(); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | * @param bool $enabled |
| 107 | 107 | * @return $this |
| 108 | 108 | */ |
| 109 | - public function enableNormalizing(bool $enabled=true) : ConvertHelper_URLFinder |
|
| 109 | + public function enableNormalizing(bool $enabled = true) : ConvertHelper_URLFinder |
|
| 110 | 110 | { |
| 111 | 111 | $this->setOption('normalize', $enabled); |
| 112 | 112 | return $this; |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | * @param bool $enabled |
| 119 | 119 | * @return $this |
| 120 | 120 | */ |
| 121 | - public function enableSorting(bool $enabled=true) : ConvertHelper_URLFinder |
|
| 121 | + public function enableSorting(bool $enabled = true) : ConvertHelper_URLFinder |
|
| 122 | 122 | { |
| 123 | 123 | $this->setOption('sorting', $enabled); |
| 124 | 124 | return $this; |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | * @param bool $include |
| 133 | 133 | * @return ConvertHelper_URLFinder |
| 134 | 134 | */ |
| 135 | - public function includeEmails(bool $include=true) : ConvertHelper_URLFinder |
|
| 135 | + public function includeEmails(bool $include = true) : ConvertHelper_URLFinder |
|
| 136 | 136 | { |
| 137 | 137 | $this->setOption('include-emails', $include); |
| 138 | 138 | return $this; |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @param bool $omit |
| 145 | 145 | * @return ConvertHelper_URLFinder |
| 146 | 146 | */ |
| 147 | - public function omitMailto(bool $omit=true) : ConvertHelper_URLFinder |
|
| 147 | + public function omitMailto(bool $omit = true) : ConvertHelper_URLFinder |
|
| 148 | 148 | { |
| 149 | 149 | $this->setOption('omit-mailto', $omit); |
| 150 | 150 | return $this; |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | { |
| 172 | 172 | $line = $this->analyzeLine($line); |
| 173 | 173 | |
| 174 | - if($line !== null) { |
|
| 174 | + if ($line !== null) { |
|
| 175 | 175 | $keep[] = $line; |
| 176 | 176 | } |
| 177 | 177 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | $line = trim($line, '.'); |
| 193 | 193 | |
| 194 | 194 | // Handle detecting an URI scheme |
| 195 | - if(strstr($line, ':') !== false) |
|
| 195 | + if (strstr($line, ':') !== false) |
|
| 196 | 196 | { |
| 197 | 197 | $scheme = URISchemes::detectScheme($line); |
| 198 | 198 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | // detect are email addresses and domain names. |
| 207 | 207 | |
| 208 | 208 | // No dot? Then it's certainly not a domain name. |
| 209 | - if(strstr($line, '.') === false) { |
|
| 209 | + if (strstr($line, '.') === false) { |
|
| 210 | 210 | return null; |
| 211 | 211 | } |
| 212 | 212 | |
@@ -224,10 +224,10 @@ discard block |
||
| 224 | 224 | { |
| 225 | 225 | $subject = stripslashes($subject); |
| 226 | 226 | |
| 227 | - foreach($this->detectors as $detector) |
|
| 227 | + foreach ($this->detectors as $detector) |
|
| 228 | 228 | { |
| 229 | 229 | // Avoid processing the string if it is not needed. |
| 230 | - if($detector->getRunPosition() !== ConvertHelper_URLFinder_Detector::RUN_BEFORE || !$detector->isValidFor($subject)) { |
|
| 230 | + if ($detector->getRunPosition() !== ConvertHelper_URLFinder_Detector::RUN_BEFORE || !$detector->isValidFor($subject)) { |
|
| 231 | 231 | continue; |
| 232 | 232 | } |
| 233 | 233 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | { |
| 249 | 249 | $detector = new $className(); |
| 250 | 250 | |
| 251 | - if($detector instanceof ConvertHelper_URLFinder_Detector) |
|
| 251 | + if ($detector instanceof ConvertHelper_URLFinder_Detector) |
|
| 252 | 252 | { |
| 253 | 253 | return $detector; |
| 254 | 254 | } |
@@ -275,12 +275,12 @@ discard block |
||
| 275 | 275 | |
| 276 | 276 | $result = $this->getItemsAsString($this->urls); |
| 277 | 277 | |
| 278 | - if($this->getBoolOption('include-emails')) |
|
| 278 | + if ($this->getBoolOption('include-emails')) |
|
| 279 | 279 | { |
| 280 | 280 | $result = array_merge($result, $this->getEmails()); |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if($this->getBoolOption('sorting')) |
|
| 283 | + if ($this->getBoolOption('sorting')) |
|
| 284 | 284 | { |
| 285 | 285 | usort($result, function(string $a, string $b) { |
| 286 | 286 | return strnatcasecmp($a, $b); |
@@ -300,12 +300,12 @@ discard block |
||
| 300 | 300 | |
| 301 | 301 | $result = array(); |
| 302 | 302 | |
| 303 | - foreach($collection as $url => $info) { |
|
| 304 | - if($normalize) { |
|
| 303 | + foreach ($collection as $url => $info) { |
|
| 304 | + if ($normalize) { |
|
| 305 | 305 | $url = $info->getNormalized(); |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - if(!in_array($url, $result)) { |
|
| 308 | + if (!in_array($url, $result)) { |
|
| 309 | 309 | $result[] = $url; |
| 310 | 310 | } |
| 311 | 311 | } |
@@ -322,9 +322,9 @@ discard block |
||
| 322 | 322 | */ |
| 323 | 323 | private function initDetectors() : void |
| 324 | 324 | { |
| 325 | - foreach($this->enabledDetectorClasses as $className => $enabled) |
|
| 325 | + foreach ($this->enabledDetectorClasses as $className => $enabled) |
|
| 326 | 326 | { |
| 327 | - if($enabled) { |
|
| 327 | + if ($enabled) { |
|
| 328 | 328 | $this->detectors[] = $this->createDetector($className); |
| 329 | 329 | } |
| 330 | 330 | } |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | */ |
| 340 | 340 | private function parse() : void |
| 341 | 341 | { |
| 342 | - if($this->parsed) { |
|
| 342 | + if ($this->parsed) { |
|
| 343 | 343 | return; |
| 344 | 344 | } |
| 345 | 345 | |
@@ -350,11 +350,11 @@ discard block |
||
| 350 | 350 | |
| 351 | 351 | unset($this->subject); |
| 352 | 352 | |
| 353 | - foreach($this->matches as $match) |
|
| 353 | + foreach ($this->matches as $match) |
|
| 354 | 354 | { |
| 355 | 355 | $info = parseURL($match); |
| 356 | 356 | |
| 357 | - if($info->isEmail()) |
|
| 357 | + if ($info->isEmail()) |
|
| 358 | 358 | { |
| 359 | 359 | $this->emails[$this->filterEmailAddress($match)] = $info; |
| 360 | 360 | continue; |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | * @param bool $enable |
| 371 | 371 | * @return $this |
| 372 | 372 | */ |
| 373 | - public function enableHTMLAttributes(bool $enable=true) : ConvertHelper_URLFinder |
|
| 373 | + public function enableHTMLAttributes(bool $enable = true) : ConvertHelper_URLFinder |
|
| 374 | 374 | { |
| 375 | 375 | $this->enabledDetectorClasses[ConvertHelper_URLFinder_Detector_HTMLAttributes::class] = $enable; |
| 376 | 376 | return $this; |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | private function filterEmailAddress(string $email) : string |
| 387 | 387 | { |
| 388 | - if(stristr($email, 'mailto:') === false) { |
|
| 388 | + if (stristr($email, 'mailto:') === false) { |
|
| 389 | 389 | $email = 'mailto:'.$email; |
| 390 | 390 | } |
| 391 | 391 | |
@@ -407,14 +407,14 @@ discard block |
||
| 407 | 407 | foreach ($lines as $line) |
| 408 | 408 | { |
| 409 | 409 | $scheme = URISchemes::detectScheme($line); |
| 410 | - if($scheme !== null) { |
|
| 410 | + if ($scheme !== null) { |
|
| 411 | 411 | $this->matches[] = $line; |
| 412 | 412 | continue; |
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | $extension = $this->detectDomainExtension($line); |
| 416 | 416 | |
| 417 | - if($domains->nameExists($extension)) { |
|
| 417 | + if ($domains->nameExists($extension)) { |
|
| 418 | 418 | $this->matches[] = $line; |
| 419 | 419 | } |
| 420 | 420 | } |
@@ -433,9 +433,9 @@ discard block |
||
| 433 | 433 | |
| 434 | 434 | $subject = str_replace($remove, ' ', $subject); |
| 435 | 435 | |
| 436 | - foreach($this->detectors as $detector) |
|
| 436 | + foreach ($this->detectors as $detector) |
|
| 437 | 437 | { |
| 438 | - if($detector->getRunPosition() !== ConvertHelper_URLFinder_Detector::RUN_AFTER || !$detector->isValidFor($subject)) { |
|
| 438 | + if ($detector->getRunPosition() !== ConvertHelper_URLFinder_Detector::RUN_AFTER || !$detector->isValidFor($subject)) { |
|
| 439 | 439 | continue; |
| 440 | 440 | } |
| 441 | 441 | |
@@ -458,8 +458,8 @@ discard block |
||
| 458 | 458 | $boundaries = array('/', '?'); |
| 459 | 459 | |
| 460 | 460 | // Remove the path or query parts to access the domain extension only |
| 461 | - foreach($boundaries as $boundary) { |
|
| 462 | - if(strstr($url, $boundary)) { |
|
| 461 | + foreach ($boundaries as $boundary) { |
|
| 462 | + if (strstr($url, $boundary)) { |
|
| 463 | 463 | $parts = explode($boundary, $url); |
| 464 | 464 | $url = array_shift($parts); |
| 465 | 465 | break; |
@@ -484,16 +484,16 @@ discard block |
||
| 484 | 484 | |
| 485 | 485 | $result = $this->getItemsAsString($this->emails); |
| 486 | 486 | |
| 487 | - if($this->getBoolOption('omit-mailto')) { |
|
| 487 | + if ($this->getBoolOption('omit-mailto')) { |
|
| 488 | 488 | $keep = array(); |
| 489 | - foreach($result as $email) { |
|
| 489 | + foreach ($result as $email) { |
|
| 490 | 490 | $keep[] = str_replace('mailto:', '', $email); |
| 491 | 491 | } |
| 492 | 492 | |
| 493 | 493 | $result = $keep; |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | - if($this->getBoolOption('sorting')) |
|
| 496 | + if ($this->getBoolOption('sorting')) |
|
| 497 | 497 | { |
| 498 | 498 | usort($result, function(string $a, string $b) { |
| 499 | 499 | return strnatcasecmp($a, $b); |
@@ -515,16 +515,16 @@ discard block |
||
| 515 | 515 | $result = array(); |
| 516 | 516 | $normalize = $this->getBoolOption('normalize'); |
| 517 | 517 | |
| 518 | - foreach($this->urls as $url => $info) |
|
| 518 | + foreach ($this->urls as $url => $info) |
|
| 519 | 519 | { |
| 520 | - if($normalize) { |
|
| 520 | + if ($normalize) { |
|
| 521 | 521 | $url = $info->getNormalized(); |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | 524 | $result[$url] = $info; |
| 525 | 525 | } |
| 526 | 526 | |
| 527 | - if($this->getBoolOption('sorting')) |
|
| 527 | + if ($this->getBoolOption('sorting')) |
|
| 528 | 528 | { |
| 529 | 529 | ksort($result); |
| 530 | 530 | } |