@@ -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 | } |
@@ -33,14 +33,14 @@ |
||
| 33 | 33 | { |
| 34 | 34 | preg_match_all('%<([A-Z][A-Z0-9]*)\b[^>]*>(.*?)</\1>%si', $html, $result, PREG_PATTERN_ORDER); |
| 35 | 35 | |
| 36 | - if(empty($result[1])) { |
|
| 36 | + if (empty($result[1])) { |
|
| 37 | 37 | return '<p>'.$text.'</p>'; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | $tagName = array_pop($result[1]); |
| 41 | 41 | $pos = strrpos($html, '</'.$tagName.'>'); |
| 42 | 42 | |
| 43 | - if(in_array(strtolower($tagName), self::$newParaTags)) { |
|
| 43 | + if (in_array(strtolower($tagName), self::$newParaTags)) { |
|
| 44 | 44 | $replace = '</'.$tagName.'><p>'.$text.'</p>'; |
| 45 | 45 | } else { |
| 46 | 46 | $replace = $text.'</'.$tagName.'>'; |
@@ -25,10 +25,10 @@ |
||
| 25 | 25 | * |
| 26 | 26 | * @return string |
| 27 | 27 | */ |
| 28 | - function render() : string; |
|
| 28 | + function render() : string; |
|
| 29 | 29 | |
| 30 | 30 | /** |
| 31 | 31 | * Renders the string and echos it. |
| 32 | 32 | */ |
| 33 | - function display() : void; |
|
| 33 | + function display() : void; |
|
| 34 | 34 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | |
| 69 | 69 | $interval = $d2->diff($d1); |
| 70 | 70 | |
| 71 | - if(!$interval instanceof DateInterval) |
|
| 71 | + if (!$interval instanceof DateInterval) |
|
| 72 | 72 | { |
| 73 | 73 | throw new ConvertHelper_Exception( |
| 74 | 74 | 'Cannot create interval', |
@@ -187,24 +187,24 @@ discard block |
||
| 187 | 187 | * @see ConvertHelper::INTERVAL_HOURS |
| 188 | 188 | * @see ConvertHelper::INTERVAL_DAYS |
| 189 | 189 | */ |
| 190 | - public static function toTotal(DateInterval $interval, string $unit=ConvertHelper::INTERVAL_SECONDS) : int |
|
| 190 | + public static function toTotal(DateInterval $interval, string $unit = ConvertHelper::INTERVAL_SECONDS) : int |
|
| 191 | 191 | { |
| 192 | 192 | $total = (int)$interval->format('%a'); |
| 193 | 193 | if ($unit == ConvertHelper::INTERVAL_DAYS) { |
| 194 | 194 | return $total; |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - $total = ($total * 24) + ((int)$interval->h ); |
|
| 197 | + $total = ($total * 24) + ((int)$interval->h); |
|
| 198 | 198 | if ($unit == ConvertHelper::INTERVAL_HOURS) { |
| 199 | 199 | return $total; |
| 200 | 200 | } |
| 201 | 201 | |
| 202 | - $total = ($total * 60) + ((int)$interval->i ); |
|
| 202 | + $total = ($total * 60) + ((int)$interval->i); |
|
| 203 | 203 | if ($unit == ConvertHelper::INTERVAL_MINUTES) { |
| 204 | 204 | return $total; |
| 205 | 205 | } |
| 206 | 206 | |
| 207 | - $total = ($total * 60) + ((int)$interval->s ); |
|
| 207 | + $total = ($total * 60) + ((int)$interval->s); |
|
| 208 | 208 | if ($unit == ConvertHelper::INTERVAL_SECONDS) { |
| 209 | 209 | return $total; |
| 210 | 210 | } |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | public const TOKEN_MONTHS = 'm'; |
| 42 | 42 | public const TOKEN_YEARS = 'y'; |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var DateInterval |
|
| 46 | - */ |
|
| 44 | + /** |
|
| 45 | + * @var DateInterval |
|
| 46 | + */ |
|
| 47 | 47 | protected $interval; |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var int |
|
| 51 | - */ |
|
| 49 | + /** |
|
| 50 | + * @var int |
|
| 51 | + */ |
|
| 52 | 52 | protected $seconds; |
| 53 | 53 | |
| 54 | 54 | /** |
@@ -92,22 +92,22 @@ discard block |
||
| 92 | 92 | return new ConvertHelper_DateInterval($seconds); |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Creates the interval from an existing regular interval instance. |
|
| 97 | - * |
|
| 98 | - * @param DateInterval $interval |
|
| 99 | - * @return ConvertHelper_DateInterval |
|
| 100 | - */ |
|
| 95 | + /** |
|
| 96 | + * Creates the interval from an existing regular interval instance. |
|
| 97 | + * |
|
| 98 | + * @param DateInterval $interval |
|
| 99 | + * @return ConvertHelper_DateInterval |
|
| 100 | + */ |
|
| 101 | 101 | public static function fromInterval(DateInterval $interval) |
| 102 | 102 | { |
| 103 | 103 | return self::fromSeconds(ConvertHelper::interval2seconds($interval)); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Retrieves the PHP native date interval. |
|
| 108 | - * |
|
| 109 | - * @return DateInterval |
|
| 110 | - */ |
|
| 106 | + /** |
|
| 107 | + * Retrieves the PHP native date interval. |
|
| 108 | + * |
|
| 109 | + * @return DateInterval |
|
| 110 | + */ |
|
| 111 | 111 | public function getInterval() : DateInterval |
| 112 | 112 | { |
| 113 | 113 | return $this->interval; |
@@ -143,31 +143,31 @@ discard block |
||
| 143 | 143 | return $this->getToken(self::TOKEN_YEARS); |
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * Retrieves a specific time token, e.g. "h" (for hours). |
|
| 148 | - * Using the constants to specifiy the tokens is recommended. |
|
| 149 | - * |
|
| 150 | - * @param string $token |
|
| 151 | - * @return int |
|
| 152 | - * |
|
| 153 | - * @see ConvertHelper_DateInterval::TOKEN_SECONDS |
|
| 154 | - * @see ConvertHelper_DateInterval::TOKEN_MINUTES |
|
| 155 | - * @see ConvertHelper_DateInterval::TOKEN_HOURS |
|
| 156 | - * @see ConvertHelper_DateInterval::TOKEN_DAYS |
|
| 157 | - * @see ConvertHelper_DateInterval::TOKEN_MONTHS |
|
| 158 | - * @see ConvertHelper_DateInterval::TOKEN_YEARS |
|
| 159 | - */ |
|
| 146 | + /** |
|
| 147 | + * Retrieves a specific time token, e.g. "h" (for hours). |
|
| 148 | + * Using the constants to specifiy the tokens is recommended. |
|
| 149 | + * |
|
| 150 | + * @param string $token |
|
| 151 | + * @return int |
|
| 152 | + * |
|
| 153 | + * @see ConvertHelper_DateInterval::TOKEN_SECONDS |
|
| 154 | + * @see ConvertHelper_DateInterval::TOKEN_MINUTES |
|
| 155 | + * @see ConvertHelper_DateInterval::TOKEN_HOURS |
|
| 156 | + * @see ConvertHelper_DateInterval::TOKEN_DAYS |
|
| 157 | + * @see ConvertHelper_DateInterval::TOKEN_MONTHS |
|
| 158 | + * @see ConvertHelper_DateInterval::TOKEN_YEARS |
|
| 159 | + */ |
|
| 160 | 160 | public function getToken(string $token) : int |
| 161 | 161 | { |
| 162 | 162 | return (int)$this->interval->$token; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * The total amount of seconds in the interval (including |
|
| 167 | - * everything, from seconds to days, months, years...). |
|
| 168 | - * |
|
| 169 | - * @return int |
|
| 170 | - */ |
|
| 165 | + /** |
|
| 166 | + * The total amount of seconds in the interval (including |
|
| 167 | + * everything, from seconds to days, months, years...). |
|
| 168 | + * |
|
| 169 | + * @return int |
|
| 170 | + */ |
|
| 171 | 171 | public function getTotalSeconds() : int |
| 172 | 172 | { |
| 173 | 173 | return $this->seconds; |
@@ -398,8 +398,7 @@ discard block |
||
| 398 | 398 | if($datefrom instanceof DateTime) |
| 399 | 399 | { |
| 400 | 400 | $converter->setDateFrom($datefrom); |
| 401 | - } |
|
| 402 | - else |
|
| 401 | + } else |
|
| 403 | 402 | { |
| 404 | 403 | $converter->setDateFrom(ConvertHelper_Date::fromTimestamp($datefrom)); |
| 405 | 404 | } |
@@ -407,8 +406,7 @@ discard block |
||
| 407 | 406 | if($dateto instanceof DateTime) |
| 408 | 407 | { |
| 409 | 408 | $converter->setDateTo($dateto); |
| 410 | - } |
|
| 411 | - else if($dateto > 0) |
|
| 409 | + } else if($dateto > 0) |
|
| 412 | 410 | { |
| 413 | 411 | $converter->setDateTo(ConvertHelper_Date::fromTimestamp($dateto)); |
| 414 | 412 | } |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | |
| 72 | 72 | public function __construct() |
| 73 | 73 | { |
| 74 | - if(class_exists('\AppLocalize\Localization')) { |
|
| 74 | + if (class_exists('\AppLocalize\Localization')) { |
|
| 75 | 75 | \AppLocalize\Localization::onLocaleChanged(array($this, 'handle_localeChanged')); |
| 76 | 76 | } |
| 77 | 77 | } |
@@ -133,11 +133,11 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | $epoch = 'past'; |
| 135 | 135 | $key = 'singular'; |
| 136 | - if($this->dateDiff > 1) { |
|
| 136 | + if ($this->dateDiff > 1) { |
|
| 137 | 137 | $key = 'plural'; |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - if($this->future) { |
|
| 140 | + if ($this->future) { |
|
| 141 | 141 | $epoch = 'future'; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | protected function initTexts() : void |
| 152 | 152 | { |
| 153 | - if(isset(self::$texts)) { |
|
| 153 | + if (isset(self::$texts)) { |
|
| 154 | 154 | return; |
| 155 | 155 | } |
| 156 | 156 | |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | $day = (int)date("j", $this->dateTo); |
| 237 | 237 | $year = (int)date("Y", $this->dateFrom); |
| 238 | 238 | |
| 239 | - while(mktime($hour, $min, $sec, $month + ($months_difference), $day, $year) < $this->dateTo) |
|
| 239 | + while (mktime($hour, $min, $sec, $month + ($months_difference), $day, $year) < $this->dateTo) |
|
| 240 | 240 | { |
| 241 | 241 | $months_difference++; |
| 242 | 242 | } |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | protected function resolveCalculations() : void |
| 258 | 258 | { |
| 259 | - if(!isset($this->dateFrom)) |
|
| 259 | + if (!isset($this->dateFrom)) |
|
| 260 | 260 | { |
| 261 | 261 | throw new ConvertHelper_Exception( |
| 262 | 262 | 'No date from has been specified.', |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | // no date to set? Assume we want to use today. |
| 269 | - if(!isset($this->dateTo)) |
|
| 269 | + if (!isset($this->dateTo)) |
|
| 270 | 270 | { |
| 271 | 271 | $this->dateTo = time(); |
| 272 | 272 | } |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | |
| 334 | 334 | $difference = $this->dateTo - $this->dateFrom; |
| 335 | 335 | |
| 336 | - if($difference < 0) |
|
| 336 | + if ($difference < 0) |
|
| 337 | 337 | { |
| 338 | 338 | $difference = $difference * -1; |
| 339 | 339 | $this->future = true; |
@@ -395,7 +395,7 @@ discard block |
||
| 395 | 395 | { |
| 396 | 396 | $converter = new ConvertHelper_DurationConverter(); |
| 397 | 397 | |
| 398 | - if($datefrom instanceof DateTime) |
|
| 398 | + if ($datefrom instanceof DateTime) |
|
| 399 | 399 | { |
| 400 | 400 | $converter->setDateFrom($datefrom); |
| 401 | 401 | } |
@@ -404,11 +404,11 @@ discard block |
||
| 404 | 404 | $converter->setDateFrom(ConvertHelper_Date::fromTimestamp($datefrom)); |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - if($dateto instanceof DateTime) |
|
| 407 | + if ($dateto instanceof DateTime) |
|
| 408 | 408 | { |
| 409 | 409 | $converter->setDateTo($dateto); |
| 410 | 410 | } |
| 411 | - else if($dateto > 0) |
|
| 411 | + else if ($dateto > 0) |
|
| 412 | 412 | { |
| 413 | 413 | $converter->setDateTo(ConvertHelper_Date::fromTimestamp($dateto)); |
| 414 | 414 | } |
@@ -34,39 +34,39 @@ discard block |
||
| 34 | 34 | public const SECONDS_PER_MONTH_APPROX = 2505600; // imprecise - for 29 days, only for approximations. |
| 35 | 35 | public const SECONDS_PER_YEAR = 31536000; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var int|NULL |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var int|NULL |
|
| 39 | + */ |
|
| 40 | 40 | protected $dateFrom; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var int|NULL |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var int|NULL |
|
| 44 | + */ |
|
| 45 | 45 | protected $dateTo; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var bool |
|
| 49 | - */ |
|
| 47 | + /** |
|
| 48 | + * @var bool |
|
| 49 | + */ |
|
| 50 | 50 | protected $future = false; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 52 | + /** |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | 55 | protected $interval = ''; |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @var int |
|
| 59 | - */ |
|
| 57 | + /** |
|
| 58 | + * @var int |
|
| 59 | + */ |
|
| 60 | 60 | protected $difference = 0; |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @var int |
|
| 64 | - */ |
|
| 62 | + /** |
|
| 63 | + * @var int |
|
| 64 | + */ |
|
| 65 | 65 | protected $dateDiff = 0; |
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @var array<string,array<string,string>>|NULL |
|
| 69 | - */ |
|
| 67 | + /** |
|
| 68 | + * @var array<string,array<string,string>>|NULL |
|
| 69 | + */ |
|
| 70 | 70 | protected static $texts = null; |
| 71 | 71 | |
| 72 | 72 | public function __construct() |
@@ -86,17 +86,17 @@ discard block |
||
| 86 | 86 | self::$texts = null; |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | - /** |
|
| 90 | - * Sets the origin date to calculate from. |
|
| 91 | - * |
|
| 92 | - * NOTE: if this is further in the future than |
|
| 93 | - * the to: date, it will be considered as a |
|
| 94 | - * calculation for something to come, i.e. |
|
| 95 | - * "In two days". |
|
| 96 | - * |
|
| 97 | - * @param DateTime $date |
|
| 98 | - * @return ConvertHelper_DurationConverter |
|
| 99 | - */ |
|
| 89 | + /** |
|
| 90 | + * Sets the origin date to calculate from. |
|
| 91 | + * |
|
| 92 | + * NOTE: if this is further in the future than |
|
| 93 | + * the to: date, it will be considered as a |
|
| 94 | + * calculation for something to come, i.e. |
|
| 95 | + * "In two days". |
|
| 96 | + * |
|
| 97 | + * @param DateTime $date |
|
| 98 | + * @return ConvertHelper_DurationConverter |
|
| 99 | + */ |
|
| 100 | 100 | public function setDateFrom(DateTime $date) : ConvertHelper_DurationConverter |
| 101 | 101 | { |
| 102 | 102 | $this->dateFrom = ConvertHelper::date2timestamp($date); |
@@ -104,13 +104,13 @@ discard block |
||
| 104 | 104 | return $this; |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Sets the date to calculate to. Defaults to |
|
| 109 | - * the current time if not set. |
|
| 110 | - * |
|
| 111 | - * @param DateTime $date |
|
| 112 | - * @return ConvertHelper_DurationConverter |
|
| 113 | - */ |
|
| 107 | + /** |
|
| 108 | + * Sets the date to calculate to. Defaults to |
|
| 109 | + * the current time if not set. |
|
| 110 | + * |
|
| 111 | + * @param DateTime $date |
|
| 112 | + * @return ConvertHelper_DurationConverter |
|
| 113 | + */ |
|
| 114 | 114 | public function setDateTo(DateTime $date) : ConvertHelper_DurationConverter |
| 115 | 115 | { |
| 116 | 116 | $this->dateTo = ConvertHelper::date2timestamp($date); |
@@ -118,14 +118,14 @@ discard block |
||
| 118 | 118 | return $this; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Converts the specified dates to a human-readable string. |
|
| 123 | - * |
|
| 124 | - * @throws ConvertHelper_Exception |
|
| 125 | - * @return string |
|
| 126 | - * |
|
| 127 | - * @see ConvertHelper_DurationConverter::ERROR_NO_DATE_FROM_SET |
|
| 128 | - */ |
|
| 121 | + /** |
|
| 122 | + * Converts the specified dates to a human-readable string. |
|
| 123 | + * |
|
| 124 | + * @throws ConvertHelper_Exception |
|
| 125 | + * @return string |
|
| 126 | + * |
|
| 127 | + * @see ConvertHelper_DurationConverter::ERROR_NO_DATE_FROM_SET |
|
| 128 | + */ |
|
| 129 | 129 | public function convert() : string |
| 130 | 130 | { |
| 131 | 131 | $this->initTexts(); |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | * @param bool $short |
| 44 | 44 | * @return string|NULL |
| 45 | 45 | */ |
| 46 | - public static function toDayName(DateTime $date, bool $short=false) : ?string |
|
| 46 | + public static function toDayName(DateTime $date, bool $short = false) : ?string |
|
| 47 | 47 | { |
| 48 | 48 | $day = $date->format('l'); |
| 49 | 49 | $invariant = self::getDayNamesInvariant(); |
| 50 | 50 | |
| 51 | 51 | $idx = array_search($day, $invariant); |
| 52 | - if($idx !== false) { |
|
| 52 | + if ($idx !== false) { |
|
| 53 | 53 | $localized = self::getDayNames($short); |
| 54 | 54 | return $localized[$idx]; |
| 55 | 55 | } |
@@ -72,11 +72,11 @@ discard block |
||
| 72 | 72 | * @param bool $short |
| 73 | 73 | * @return string[] |
| 74 | 74 | */ |
| 75 | - public static function getDayNames(bool $short=false) : array |
|
| 75 | + public static function getDayNames(bool $short = false) : array |
|
| 76 | 76 | { |
| 77 | 77 | self::initDays(); |
| 78 | 78 | |
| 79 | - if($short) { |
|
| 79 | + if ($short) { |
|
| 80 | 80 | return self::$daysShort; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -102,13 +102,13 @@ discard block |
||
| 102 | 102 | public static function toListLabel(DateTime $date, bool $includeTime = false, bool $shortMonth = false) : string |
| 103 | 103 | { |
| 104 | 104 | $today = new DateTime(); |
| 105 | - if($date->format('d.m.Y') === $today->format('d.m.Y')) |
|
| 105 | + if ($date->format('d.m.Y') === $today->format('d.m.Y')) |
|
| 106 | 106 | { |
| 107 | 107 | $label = t('Today'); |
| 108 | 108 | } |
| 109 | 109 | else |
| 110 | 110 | { |
| 111 | - $label = $date->format('d') . '. ' . self::month2string((int)$date->format('m'), $shortMonth) . ' '; |
|
| 111 | + $label = $date->format('d').'. '.self::month2string((int)$date->format('m'), $shortMonth).' '; |
|
| 112 | 112 | |
| 113 | 113 | if ($date->format('Y') != date('Y')) |
| 114 | 114 | { |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | |
| 214 | 214 | private static function initDays() : void |
| 215 | 215 | { |
| 216 | - if(!empty(self::$daysShort)) |
|
| 216 | + if (!empty(self::$daysShort)) |
|
| 217 | 217 | { |
| 218 | 218 | return; |
| 219 | 219 | } |
@@ -105,8 +105,7 @@ |
||
| 105 | 105 | if($date->format('d.m.Y') === $today->format('d.m.Y')) |
| 106 | 106 | { |
| 107 | 107 | $label = t('Today'); |
| 108 | - } |
|
| 109 | - else |
|
| 108 | + } else |
|
| 110 | 109 | { |
| 111 | 110 | $label = $date->format('d') . '. ' . self::month2string((int)$date->format('m'), $shortMonth) . ' '; |
| 112 | 111 | |
@@ -15,9 +15,9 @@ discard block |
||
| 15 | 15 | */ |
| 16 | 16 | public static function removeKeys(array &$sourceArray, array $keys) : void |
| 17 | 17 | { |
| 18 | - foreach($keys as $key) |
|
| 18 | + foreach ($keys as $key) |
|
| 19 | 19 | { |
| 20 | - if(array_key_exists($key, $sourceArray)) { |
|
| 20 | + if (array_key_exists($key, $sourceArray)) { |
|
| 21 | 21 | unset($sourceArray[$key]); |
| 22 | 22 | } |
| 23 | 23 | } |
@@ -31,18 +31,18 @@ discard block |
||
| 31 | 31 | * @param bool $keepKeys Whether to maintain index association |
| 32 | 32 | * @return array<number|string,mixed> |
| 33 | 33 | */ |
| 34 | - public static function removeValues(array $sourceArray, array $values, bool $keepKeys=false) : array |
|
| 34 | + public static function removeValues(array $sourceArray, array $values, bool $keepKeys = false) : array |
|
| 35 | 35 | { |
| 36 | 36 | $result = array(); |
| 37 | 37 | $values = array_values($values); |
| 38 | 38 | |
| 39 | - foreach($sourceArray as $key => $value) |
|
| 39 | + foreach ($sourceArray as $key => $value) |
|
| 40 | 40 | { |
| 41 | - if(in_array($value, $values, true)) { |
|
| 41 | + if (in_array($value, $values, true)) { |
|
| 42 | 42 | continue; |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - if($keepKeys) { |
|
| 45 | + if ($keepKeys) { |
|
| 46 | 46 | $result[$key] = $value; |
| 47 | 47 | continue; |
| 48 | 48 | } |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | public static function toStyleString(array $subject) : string |
| 76 | 76 | { |
| 77 | 77 | $tokens = array(); |
| 78 | - foreach($subject as $name => $value) { |
|
| 78 | + foreach ($subject as $name => $value) { |
|
| 79 | 79 | $tokens[] = $name.':'.strval($value); |
| 80 | 80 | } |
| 81 | 81 | |
@@ -104,18 +104,18 @@ discard block |
||
| 104 | 104 | public static function toAttributeString(array $array) : string |
| 105 | 105 | { |
| 106 | 106 | $tokens = array(); |
| 107 | - foreach($array as $attr => $value) |
|
| 107 | + foreach ($array as $attr => $value) |
|
| 108 | 108 | { |
| 109 | 109 | $value = strval($value); |
| 110 | 110 | |
| 111 | - if($value === '') { |
|
| 111 | + if ($value === '') { |
|
| 112 | 112 | continue; |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | $tokens[] = $attr.'="'.htmlspecialchars($value, ENT_QUOTES, 'UTF-8').'"'; |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | - if(empty($tokens)) { |
|
| 118 | + if (empty($tokens)) { |
|
| 119 | 119 | return ''; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -136,17 +136,17 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | public static function implodeWithAnd(array $list, string $sep = ', ', string $conjunction = '') : string |
| 138 | 138 | { |
| 139 | - if(empty($list)) { |
|
| 139 | + if (empty($list)) { |
|
| 140 | 140 | return ''; |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - if(empty($conjunction)) { |
|
| 143 | + if (empty($conjunction)) { |
|
| 144 | 144 | $conjunction = ' '.t('and').' '; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | $last = array_pop($list); |
| 148 | - if($list) { |
|
| 149 | - return implode($sep, $list) . $conjunction . $last; |
|
| 148 | + if ($list) { |
|
| 149 | + return implode($sep, $list).$conjunction.$last; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | return $last; |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | { |
| 69 | 69 | self::$stack[] = 1; |
| 70 | 70 | |
| 71 | - if(ob_start() === true) { |
|
| 71 | + if (ob_start() === true) { |
|
| 72 | 72 | return; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | { |
| 91 | 91 | self::_stop(); |
| 92 | 92 | |
| 93 | - if(ob_end_clean() !== false) |
|
| 93 | + if (ob_end_clean() !== false) |
|
| 94 | 94 | { |
| 95 | 95 | return; |
| 96 | 96 | } |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | private static function _stop() : void |
| 109 | 109 | { |
| 110 | - if(empty(self::$stack)) |
|
| 110 | + if (empty(self::$stack)) |
|
| 111 | 111 | { |
| 112 | 112 | throw new OutputBuffering_Exception( |
| 113 | 113 | 'Output buffering is not active', |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | { |
| 131 | 131 | self::_stop(); |
| 132 | 132 | |
| 133 | - if(ob_end_flush() !== false) |
|
| 133 | + if (ob_end_flush() !== false) |
|
| 134 | 134 | { |
| 135 | 135 | return; |
| 136 | 136 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | |
| 159 | 159 | $content = ob_get_clean(); |
| 160 | 160 | |
| 161 | - if($content !== false) |
|
| 161 | + if ($content !== false) |
|
| 162 | 162 | { |
| 163 | 163 | return $content; |
| 164 | 164 | } |
@@ -87,14 +87,14 @@ |
||
| 87 | 87 | public function match(string $source, string $target) : float |
| 88 | 88 | { |
| 89 | 89 | // avoid doing this via levenshtein |
| 90 | - if($source === $target) { |
|
| 90 | + if ($source === $target) { |
|
| 91 | 91 | return 100; |
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | $maxL = $this->getMaxDistance(); |
| 95 | 95 | |
| 96 | 96 | $diff = levenshtein($source, $target); |
| 97 | - if($diff > $maxL) { |
|
| 97 | + if ($diff > $maxL) { |
|
| 98 | 98 | return 0; |
| 99 | 99 | } |
| 100 | 100 | |