@@ -60,7 +60,7 @@ discard block |
||
| 60 | 60 | * The converted string will be all lowercase. |
| 61 | 61 | * @return Transliteration |
| 62 | 62 | */ |
| 63 | - public function setLowercase(bool $lowercase=true) : Transliteration |
|
| 63 | + public function setLowercase(bool $lowercase = true) : Transliteration |
|
| 64 | 64 | { |
| 65 | 65 | $this->setOption('lowercase', $lowercase); |
| 66 | 66 | |
@@ -97,8 +97,8 @@ discard block |
||
| 97 | 97 | |
| 98 | 98 | $result = implode('', $keep); |
| 99 | 99 | |
| 100 | - while (strstr($result, $space . $space)) { |
|
| 101 | - $result = str_replace($space . $space, $space, $result); |
|
| 100 | + while (strstr($result, $space.$space)) { |
|
| 101 | + $result = str_replace($space.$space, $space, $result); |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | $result = trim($result, $space); |
@@ -38,24 +38,24 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | class NumberInfo |
| 40 | 40 | { |
| 41 | - /** |
|
| 42 | - * @var mixed |
|
| 43 | - */ |
|
| 41 | + /** |
|
| 42 | + * @var mixed |
|
| 43 | + */ |
|
| 44 | 44 | protected $rawValue; |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var array |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * @var array |
|
| 48 | + */ |
|
| 49 | 49 | protected $info; |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var bool |
|
| 53 | - */ |
|
| 51 | + /** |
|
| 52 | + * @var bool |
|
| 53 | + */ |
|
| 54 | 54 | protected $empty = false; |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var array |
|
| 58 | - */ |
|
| 56 | + /** |
|
| 57 | + * @var array |
|
| 58 | + */ |
|
| 59 | 59 | protected $knownUnits = array( |
| 60 | 60 | '%' => true, |
| 61 | 61 | 'rem' => true, |
@@ -95,21 +95,21 @@ discard block |
||
| 95 | 95 | return $this; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Retrieves the raw, internal information array resulting |
|
| 100 | - * from the parsing of the number. |
|
| 101 | - * |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 98 | + /** |
|
| 99 | + * Retrieves the raw, internal information array resulting |
|
| 100 | + * from the parsing of the number. |
|
| 101 | + * |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | 104 | public function getRawInfo() : array |
| 105 | 105 | { |
| 106 | 106 | return $this->info; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Whether the number was empty (null or empty string). |
|
| 111 | - * @return boolean |
|
| 112 | - */ |
|
| 109 | + /** |
|
| 110 | + * Whether the number was empty (null or empty string). |
|
| 111 | + * @return boolean |
|
| 112 | + */ |
|
| 113 | 113 | public function isEmpty() : bool |
| 114 | 114 | { |
| 115 | 115 | return $this->empty; |
@@ -532,12 +532,12 @@ discard block |
||
| 532 | 532 | return $cache[$key]; |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | - /** |
|
| 536 | - * Parses a string number notation with units included, e.g. 14px, 50%... |
|
| 537 | - * |
|
| 538 | - * @param string $test |
|
| 539 | - * @return array |
|
| 540 | - */ |
|
| 535 | + /** |
|
| 536 | + * Parses a string number notation with units included, e.g. 14px, 50%... |
|
| 537 | + * |
|
| 538 | + * @param string $test |
|
| 539 | + * @return array |
|
| 540 | + */ |
|
| 541 | 541 | private function parseStringValue(string $test) : array |
| 542 | 542 | { |
| 543 | 543 | $number = null; |
@@ -588,13 +588,13 @@ discard block |
||
| 588 | 588 | return $this->filterInfo($result); |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - /** |
|
| 592 | - * Attempts to determine what kind of units are specified |
|
| 593 | - * in the string. Returns NULL if none could be matched. |
|
| 594 | - * |
|
| 595 | - * @param string $value |
|
| 596 | - * @return array|NULL |
|
| 597 | - */ |
|
| 591 | + /** |
|
| 592 | + * Attempts to determine what kind of units are specified |
|
| 593 | + * in the string. Returns NULL if none could be matched. |
|
| 594 | + * |
|
| 595 | + * @param string $value |
|
| 596 | + * @return array|NULL |
|
| 597 | + */ |
|
| 598 | 598 | private function findUnits(string $value) : ?array |
| 599 | 599 | { |
| 600 | 600 | $vlength = strlen($value); |
@@ -622,12 +622,12 @@ discard block |
||
| 622 | 622 | return null; |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | - /** |
|
| 626 | - * Creates the cache key for the specified value. |
|
| 627 | - * |
|
| 628 | - * @param mixed $value |
|
| 629 | - * @return string |
|
| 630 | - */ |
|
| 625 | + /** |
|
| 626 | + * Creates the cache key for the specified value. |
|
| 627 | + * |
|
| 628 | + * @param mixed $value |
|
| 629 | + * @return string |
|
| 630 | + */ |
|
| 631 | 631 | private function createValueKey($value) : string |
| 632 | 632 | { |
| 633 | 633 | if(!is_string($value) && !is_numeric($value)) |
@@ -640,59 +640,59 @@ discard block |
||
| 640 | 640 | |
| 641 | 641 | protected $postProcess = false; |
| 642 | 642 | |
| 643 | - /** |
|
| 644 | - * Called if explicitly enabled: allows filtering the |
|
| 645 | - * number after the detection process has completed. |
|
| 646 | - * |
|
| 647 | - * @param string|NULL $number The adjusted number |
|
| 648 | - * @param string $originalString The original value before it was parsed |
|
| 649 | - * @return mixed |
|
| 650 | - */ |
|
| 643 | + /** |
|
| 644 | + * Called if explicitly enabled: allows filtering the |
|
| 645 | + * number after the detection process has completed. |
|
| 646 | + * |
|
| 647 | + * @param string|NULL $number The adjusted number |
|
| 648 | + * @param string $originalString The original value before it was parsed |
|
| 649 | + * @return mixed |
|
| 650 | + */ |
|
| 651 | 651 | protected function postProcess(?string $number, /** @scrutinizer ignore-unused */ string $originalString) |
| 652 | 652 | { |
| 653 | 653 | return $number; |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | - /** |
|
| 657 | - * Filters the value before it is parsed, but only if it is a string. |
|
| 658 | - * |
|
| 659 | - * NOTE: This may be overwritten in a subclass, to allow custom filtering |
|
| 660 | - * the the values. An example of a use case would be a preprocessor for |
|
| 661 | - * variables in a templating system. |
|
| 662 | - * |
|
| 663 | - * @param string $trimmedString The trimmed value. |
|
| 664 | - * @param array $cache The internal values cache array. |
|
| 665 | - * @param string $originalValue The original value that the NumberInfo was created for. |
|
| 666 | - * @return string |
|
| 667 | - * |
|
| 668 | - * @see NumberInfo::enablePostProcess() |
|
| 669 | - */ |
|
| 656 | + /** |
|
| 657 | + * Filters the value before it is parsed, but only if it is a string. |
|
| 658 | + * |
|
| 659 | + * NOTE: This may be overwritten in a subclass, to allow custom filtering |
|
| 660 | + * the the values. An example of a use case would be a preprocessor for |
|
| 661 | + * variables in a templating system. |
|
| 662 | + * |
|
| 663 | + * @param string $trimmedString The trimmed value. |
|
| 664 | + * @param array $cache The internal values cache array. |
|
| 665 | + * @param string $originalValue The original value that the NumberInfo was created for. |
|
| 666 | + * @return string |
|
| 667 | + * |
|
| 668 | + * @see NumberInfo::enablePostProcess() |
|
| 669 | + */ |
|
| 670 | 670 | protected function preProcess(string $trimmedString, /** @scrutinizer ignore-unused */ array &$cache, /** @scrutinizer ignore-unused */ string $originalValue) : string |
| 671 | 671 | { |
| 672 | 672 | return str_replace(',', '.', $trimmedString); |
| 673 | 673 | } |
| 674 | 674 | |
| 675 | - /** |
|
| 676 | - * Enables the post processing so the postProcess method gets called. |
|
| 677 | - * This should be called in the {@link NumberInfo::preProcess()} |
|
| 678 | - * method as needed. |
|
| 679 | - * |
|
| 680 | - * @return NumberInfo |
|
| 681 | - * @see NumberInfo::postProcess() |
|
| 682 | - */ |
|
| 675 | + /** |
|
| 676 | + * Enables the post processing so the postProcess method gets called. |
|
| 677 | + * This should be called in the {@link NumberInfo::preProcess()} |
|
| 678 | + * method as needed. |
|
| 679 | + * |
|
| 680 | + * @return NumberInfo |
|
| 681 | + * @see NumberInfo::postProcess() |
|
| 682 | + */ |
|
| 683 | 683 | private function enablePostProcess() : NumberInfo |
| 684 | 684 | { |
| 685 | 685 | $this->postProcess = true; |
| 686 | 686 | return $this; |
| 687 | 687 | } |
| 688 | 688 | |
| 689 | - /** |
|
| 690 | - * Filters the number info array to adjust the units |
|
| 691 | - * and number according to the required rules. |
|
| 692 | - * |
|
| 693 | - * @param array $info |
|
| 694 | - * @return array |
|
| 695 | - */ |
|
| 689 | + /** |
|
| 690 | + * Filters the number info array to adjust the units |
|
| 691 | + * and number according to the required rules. |
|
| 692 | + * |
|
| 693 | + * @param array $info |
|
| 694 | + * @return array |
|
| 695 | + */ |
|
| 696 | 696 | protected function filterInfo(array $info) : array |
| 697 | 697 | { |
| 698 | 698 | $useUnits = 'px'; |
@@ -572,8 +572,7 @@ |
||
| 572 | 572 | { |
| 573 | 573 | $number = null; |
| 574 | 574 | $empty = true; |
| 575 | - } |
|
| 576 | - else |
|
| 575 | + } else |
|
| 577 | 576 | { |
| 578 | 577 | $number = $number * 1; |
| 579 | 578 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | public function setValue($value) : NumberInfo |
| 86 | 86 | { |
| 87 | - if($value instanceof NumberInfo) { |
|
| 87 | + if ($value instanceof NumberInfo) { |
|
| 88 | 88 | $value = $value->getValue(); |
| 89 | 89 | } |
| 90 | 90 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | |
| 118 | 118 | public function isPositive() : bool |
| 119 | 119 | { |
| 120 | - if(!$this->isEmpty()) { |
|
| 120 | + if (!$this->isEmpty()) { |
|
| 121 | 121 | $number = $this->getNumber(); |
| 122 | 122 | return $number > 0; |
| 123 | 123 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | public function hasValue() : bool |
| 150 | 150 | { |
| 151 | - if(!$this->isEmpty() && !$this->isZero()) { |
|
| 151 | + if (!$this->isEmpty() && !$this->isZero()) { |
|
| 152 | 152 | return true; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -221,7 +221,7 @@ discard block |
||
| 221 | 221 | */ |
| 222 | 222 | public function getUnits() |
| 223 | 223 | { |
| 224 | - if(!$this->hasUnits()) { |
|
| 224 | + if (!$this->hasUnits()) { |
|
| 225 | 225 | return 'px'; |
| 226 | 226 | } |
| 227 | 227 | |
@@ -255,15 +255,15 @@ discard block |
||
| 255 | 255 | */ |
| 256 | 256 | public function toAttribute() |
| 257 | 257 | { |
| 258 | - if($this->isEmpty()) { |
|
| 258 | + if ($this->isEmpty()) { |
|
| 259 | 259 | return null; |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - if($this->isZero()) { |
|
| 262 | + if ($this->isZero()) { |
|
| 263 | 263 | return '0'; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | - if($this->isPercent()) { |
|
| 266 | + if ($this->isPercent()) { |
|
| 267 | 267 | return $this->getNumber().$this->getUnits(); |
| 268 | 268 | } |
| 269 | 269 | |
@@ -276,11 +276,11 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | public function toCSS() : string |
| 278 | 278 | { |
| 279 | - if($this->isEmpty()) { |
|
| 279 | + if ($this->isEmpty()) { |
|
| 280 | 280 | return ''; |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - if($this->isZero()) { |
|
| 283 | + if ($this->isZero()) { |
|
| 284 | 284 | return '0'; |
| 285 | 285 | } |
| 286 | 286 | |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | |
| 290 | 290 | public function __toString() |
| 291 | 291 | { |
| 292 | - if($this->isEmpty()) { |
|
| 292 | + if ($this->isEmpty()) { |
|
| 293 | 293 | return ''; |
| 294 | 294 | } |
| 295 | 295 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | public function isBiggerThan($number) |
| 308 | 308 | { |
| 309 | 309 | $number = parseNumber($number); |
| 310 | - if($number->getUnits() != $this->getUnits()) { |
|
| 310 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 311 | 311 | return false; |
| 312 | 312 | } |
| 313 | 313 | |
@@ -325,7 +325,7 @@ discard block |
||
| 325 | 325 | public function isSmallerThan($number) |
| 326 | 326 | { |
| 327 | 327 | $number = parseNumber($number); |
| 328 | - if($number->getUnits() != $this->getUnits()) { |
|
| 328 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 329 | 329 | return false; |
| 330 | 330 | } |
| 331 | 331 | |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | public function isBiggerEqual($number) |
| 336 | 336 | { |
| 337 | 337 | $number = parseNumber($number); |
| 338 | - if($number->getUnits() != $this->getUnits()) { |
|
| 338 | + if ($number->getUnits() != $this->getUnits()) { |
|
| 339 | 339 | return false; |
| 340 | 340 | } |
| 341 | 341 | |
@@ -352,14 +352,14 @@ discard block |
||
| 352 | 352 | */ |
| 353 | 353 | public function add($value) |
| 354 | 354 | { |
| 355 | - if($this->isEmpty()) { |
|
| 355 | + if ($this->isEmpty()) { |
|
| 356 | 356 | $this->setValue($value); |
| 357 | 357 | return $this; |
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | $number = parseNumber($value); |
| 361 | 361 | |
| 362 | - if($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 362 | + if ($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 363 | 363 | { |
| 364 | 364 | $new = $this->getNumber() + $number->getNumber(); |
| 365 | 365 | $this->setValue($new.$this->getUnits()); |
@@ -378,14 +378,14 @@ discard block |
||
| 378 | 378 | */ |
| 379 | 379 | public function subtract($value) |
| 380 | 380 | { |
| 381 | - if($this->isEmpty()) { |
|
| 381 | + if ($this->isEmpty()) { |
|
| 382 | 382 | $this->setValue($value); |
| 383 | 383 | return $this; |
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | $number = parseNumber($value); |
| 387 | 387 | |
| 388 | - if($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 388 | + if ($number->getUnits() == $this->getUnits() || !$number->hasUnits()) |
|
| 389 | 389 | { |
| 390 | 390 | $new = $this->getNumber() - $number->getNumber(); |
| 391 | 391 | $this->setValue($new.$this->getUnits()); |
@@ -412,25 +412,25 @@ discard block |
||
| 412 | 412 | |
| 413 | 413 | protected function percentOperation($operation, $percent) |
| 414 | 414 | { |
| 415 | - if($this->isZeroOrEmpty()) { |
|
| 415 | + if ($this->isZeroOrEmpty()) { |
|
| 416 | 416 | return $this; |
| 417 | 417 | } |
| 418 | 418 | |
| 419 | 419 | $percent = parseNumber($percent); |
| 420 | - if($percent->hasUnits() && !$percent->isPercent()) { |
|
| 420 | + if ($percent->hasUnits() && !$percent->isPercent()) { |
|
| 421 | 421 | return $this; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | $number = $this->getNumber(); |
| 425 | 425 | $value = $number * $percent->getNumber() / 100; |
| 426 | 426 | |
| 427 | - if($operation == '-') { |
|
| 427 | + if ($operation == '-') { |
|
| 428 | 428 | $number = $number - $value; |
| 429 | 429 | } else { |
| 430 | 430 | $number = $number + $value; |
| 431 | 431 | } |
| 432 | 432 | |
| 433 | - if($this->isUnitInteger()) { |
|
| 433 | + if ($this->isUnitInteger()) { |
|
| 434 | 434 | $number = intval($number); |
| 435 | 435 | } |
| 436 | 436 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | |
| 482 | 482 | $key = $this->createValueKey($value); |
| 483 | 483 | |
| 484 | - if(array_key_exists($key, $cache)) { |
|
| 484 | + if (array_key_exists($key, $cache)) { |
|
| 485 | 485 | return $cache[$key]; |
| 486 | 486 | } |
| 487 | 487 | |
@@ -491,13 +491,13 @@ discard block |
||
| 491 | 491 | 'number' => null |
| 492 | 492 | ); |
| 493 | 493 | |
| 494 | - if($key === '_EMPTY_') |
|
| 494 | + if ($key === '_EMPTY_') |
|
| 495 | 495 | { |
| 496 | 496 | $cache[$key]['empty'] = true; |
| 497 | 497 | return $cache[$key]; |
| 498 | 498 | } |
| 499 | 499 | |
| 500 | - if($value === 0 || $value === '0') |
|
| 500 | + if ($value === 0 || $value === '0') |
|
| 501 | 501 | { |
| 502 | 502 | $cache[$key]['number'] = 0; |
| 503 | 503 | $cache[$key] = $this->filterInfo($cache[$key]); |
@@ -506,20 +506,20 @@ discard block |
||
| 506 | 506 | |
| 507 | 507 | $test = trim((string)$value); |
| 508 | 508 | |
| 509 | - if($test === '') |
|
| 509 | + if ($test === '') |
|
| 510 | 510 | { |
| 511 | 511 | $cache[$key]['empty'] = true; |
| 512 | 512 | return $cache[$key]; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | // replace comma notation (which is only possible if it's a string) |
| 516 | - if(is_string($value)) |
|
| 516 | + if (is_string($value)) |
|
| 517 | 517 | { |
| 518 | 518 | $test = $this->preProcess($test, $cache, $value); |
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | // convert to a number if it's numeric |
| 522 | - if(is_numeric($test)) |
|
| 522 | + if (is_numeric($test)) |
|
| 523 | 523 | { |
| 524 | 524 | $cache[$key]['number'] = $test * 1; |
| 525 | 525 | $cache[$key] = $this->filterInfo($cache[$key]); |
@@ -545,19 +545,19 @@ discard block |
||
| 545 | 545 | $empty = false; |
| 546 | 546 | |
| 547 | 547 | $found = $this->findUnits($test); |
| 548 | - if($found !== null) |
|
| 548 | + if ($found !== null) |
|
| 549 | 549 | { |
| 550 | 550 | $number = $found['number']; |
| 551 | 551 | $units = $found['units']; |
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | // the filters have to restore the value |
| 555 | - if($this->postProcess) |
|
| 555 | + if ($this->postProcess) |
|
| 556 | 556 | { |
| 557 | 557 | $number = $this->postProcess($number, $test); |
| 558 | 558 | } |
| 559 | 559 | // empty number |
| 560 | - else if($number === '' || $number === null || is_bool($number)) |
|
| 560 | + else if ($number === '' || $number === null || is_bool($number)) |
|
| 561 | 561 | { |
| 562 | 562 | $number = null; |
| 563 | 563 | $empty = true; |
@@ -568,7 +568,7 @@ discard block |
||
| 568 | 568 | $number = trim($number); |
| 569 | 569 | |
| 570 | 570 | // may be an arbitrary string in some cases |
| 571 | - if(!is_numeric($number)) |
|
| 571 | + if (!is_numeric($number)) |
|
| 572 | 572 | { |
| 573 | 573 | $number = null; |
| 574 | 574 | $empty = true; |
@@ -600,17 +600,17 @@ discard block |
||
| 600 | 600 | $vlength = strlen($value); |
| 601 | 601 | $names = array_keys($this->knownUnits); |
| 602 | 602 | |
| 603 | - foreach($names as $unit) |
|
| 603 | + foreach ($names as $unit) |
|
| 604 | 604 | { |
| 605 | 605 | $ulength = strlen($unit); |
| 606 | - $start = $vlength-$ulength; |
|
| 607 | - if($start < 0) { |
|
| 606 | + $start = $vlength - $ulength; |
|
| 607 | + if ($start < 0) { |
|
| 608 | 608 | continue; |
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | $search = substr($value, $start, $ulength); |
| 612 | 612 | |
| 613 | - if($search==$unit) |
|
| 613 | + if ($search == $unit) |
|
| 614 | 614 | { |
| 615 | 615 | return array( |
| 616 | 616 | 'units' => $unit, |
@@ -630,7 +630,7 @@ discard block |
||
| 630 | 630 | */ |
| 631 | 631 | private function createValueKey($value) : string |
| 632 | 632 | { |
| 633 | - if(!is_string($value) && !is_numeric($value)) |
|
| 633 | + if (!is_string($value) && !is_numeric($value)) |
|
| 634 | 634 | { |
| 635 | 635 | return '_EMPTY_'; |
| 636 | 636 | } |
@@ -696,12 +696,12 @@ discard block |
||
| 696 | 696 | protected function filterInfo(array $info) : array |
| 697 | 697 | { |
| 698 | 698 | $useUnits = 'px'; |
| 699 | - if($info['units'] !== null) { |
|
| 699 | + if ($info['units'] !== null) { |
|
| 700 | 700 | $useUnits = $info['units']; |
| 701 | 701 | } |
| 702 | 702 | |
| 703 | 703 | // the units are non-decimal: convert decimal values |
| 704 | - if($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number'])) |
|
| 704 | + if ($useUnits !== null && $this->knownUnits[$useUnits] === false && !$info['empty'] && is_numeric($info['number'])) |
|
| 705 | 705 | { |
| 706 | 706 | $info['number'] = intval($info['number']); |
| 707 | 707 | } |
@@ -23,9 +23,9 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | class ConvertHelper_ByteConverter |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @var int |
|
| 28 | - */ |
|
| 26 | + /** |
|
| 27 | + * @var int |
|
| 28 | + */ |
|
| 29 | 29 | protected $bytes; |
| 30 | 30 | |
| 31 | 31 | public function __construct(int $bytes) |
@@ -39,12 +39,12 @@ discard block |
||
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Detects the size matching the byte value for the specified base. |
|
| 44 | - * |
|
| 45 | - * @param int $base |
|
| 46 | - * @return ConvertHelper_StorageSizeEnum_Size |
|
| 47 | - */ |
|
| 42 | + /** |
|
| 43 | + * Detects the size matching the byte value for the specified base. |
|
| 44 | + * |
|
| 45 | + * @param int $base |
|
| 46 | + * @return ConvertHelper_StorageSizeEnum_Size |
|
| 47 | + */ |
|
| 48 | 48 | protected function detectSize(int $base) : ConvertHelper_StorageSizeEnum_Size |
| 49 | 49 | { |
| 50 | 50 | $sizes = $this->getSizesSorted($base); |
@@ -70,13 +70,13 @@ discard block |
||
| 70 | 70 | return ConvertHelper_StorageSizeEnum::getSizeByName('b'); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Retrieves all storage sizes for the specified base, |
|
| 75 | - * sorted from smallest byte size to highest. |
|
| 76 | - * |
|
| 77 | - * @param int $base |
|
| 78 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 79 | - */ |
|
| 73 | + /** |
|
| 74 | + * Retrieves all storage sizes for the specified base, |
|
| 75 | + * sorted from smallest byte size to highest. |
|
| 76 | + * |
|
| 77 | + * @param int $base |
|
| 78 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 79 | + */ |
|
| 80 | 80 | protected function getSizesSorted(int $base) |
| 81 | 81 | { |
| 82 | 82 | $sizes = ConvertHelper_StorageSizeEnum::getSizesByBase($base); |
@@ -89,16 +89,16 @@ discard block |
||
| 89 | 89 | return $sizes; |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Converts the byte value to a human readable string, e.g. "5 KB", "140 MB". |
|
| 94 | - * |
|
| 95 | - * @param int $precision The amount of decimals (rounded up) |
|
| 96 | - * @param int $base The base to calculate bytes with. |
|
| 97 | - * @return string |
|
| 98 | - * |
|
| 99 | - * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
| 100 | - * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
| 101 | - */ |
|
| 92 | + /** |
|
| 93 | + * Converts the byte value to a human readable string, e.g. "5 KB", "140 MB". |
|
| 94 | + * |
|
| 95 | + * @param int $precision The amount of decimals (rounded up) |
|
| 96 | + * @param int $base The base to calculate bytes with. |
|
| 97 | + * @return string |
|
| 98 | + * |
|
| 99 | + * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
| 100 | + * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
| 101 | + */ |
|
| 102 | 102 | public function toString(int $precision, int $base=ConvertHelper_StorageSizeEnum::BASE_10) : string |
| 103 | 103 | { |
| 104 | 104 | $size = $this->detectSize($base); |
@@ -106,13 +106,13 @@ discard block |
||
| 106 | 106 | return round($this->bytes / $size->getBytes(), $precision) . ' ' . $size->getSuffix(); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Converts the byte value to the amount of the corresponding units (KB, MB...). |
|
| 111 | - * |
|
| 112 | - * @param int $precision The amount of decimals (rounded up) |
|
| 113 | - * @param string $sizeName The lowercase storage size name (e.g. "kb", "kib") |
|
| 114 | - * @return float |
|
| 115 | - */ |
|
| 109 | + /** |
|
| 110 | + * Converts the byte value to the amount of the corresponding units (KB, MB...). |
|
| 111 | + * |
|
| 112 | + * @param int $precision The amount of decimals (rounded up) |
|
| 113 | + * @param string $sizeName The lowercase storage size name (e.g. "kb", "kib") |
|
| 114 | + * @return float |
|
| 115 | + */ |
|
| 116 | 116 | public function toNumber(int $precision, string $sizeName) : float |
| 117 | 117 | { |
| 118 | 118 | $size = ConvertHelper_StorageSizeEnum::getSizeByName($sizeName); |
@@ -120,56 +120,56 @@ discard block |
||
| 120 | 120 | return round($this->bytes / $size->getBytes(), $precision); |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Converts the bytes to Kilobytes. |
|
| 125 | - * |
|
| 126 | - * @param int $precision Amount of decimals (rounded up) |
|
| 127 | - * @return float |
|
| 128 | - */ |
|
| 123 | + /** |
|
| 124 | + * Converts the bytes to Kilobytes. |
|
| 125 | + * |
|
| 126 | + * @param int $precision Amount of decimals (rounded up) |
|
| 127 | + * @return float |
|
| 128 | + */ |
|
| 129 | 129 | public function toKilobytes(int $precision=1) : float |
| 130 | 130 | { |
| 131 | 131 | return $this->toNumber($precision, 'kb'); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Converts the bytes to Megabytes. |
|
| 136 | - * |
|
| 137 | - * @param int $precision Amount of decimals (rounded up) |
|
| 138 | - * @return float |
|
| 139 | - */ |
|
| 134 | + /** |
|
| 135 | + * Converts the bytes to Megabytes. |
|
| 136 | + * |
|
| 137 | + * @param int $precision Amount of decimals (rounded up) |
|
| 138 | + * @return float |
|
| 139 | + */ |
|
| 140 | 140 | public function toMegabytes(int $precision=1) : float |
| 141 | 141 | { |
| 142 | 142 | return $this->toNumber($precision, 'mb'); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - /** |
|
| 146 | - * Converts the bytes to Gigabytes. |
|
| 147 | - * |
|
| 148 | - * @param int $precision Amount of decimals (rounded up) |
|
| 149 | - * @return float |
|
| 150 | - */ |
|
| 145 | + /** |
|
| 146 | + * Converts the bytes to Gigabytes. |
|
| 147 | + * |
|
| 148 | + * @param int $precision Amount of decimals (rounded up) |
|
| 149 | + * @return float |
|
| 150 | + */ |
|
| 151 | 151 | public function toGigabytes(int $precision=1) : float |
| 152 | 152 | { |
| 153 | 153 | return $this->toNumber($precision, 'gb'); |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - /** |
|
| 157 | - * Converts the bytes to Terabytes. |
|
| 158 | - * |
|
| 159 | - * @param int $precision Amount of decimals (rounded up) |
|
| 160 | - * @return float |
|
| 161 | - */ |
|
| 156 | + /** |
|
| 157 | + * Converts the bytes to Terabytes. |
|
| 158 | + * |
|
| 159 | + * @param int $precision Amount of decimals (rounded up) |
|
| 160 | + * @return float |
|
| 161 | + */ |
|
| 162 | 162 | public function toTerabytes(int $precision=1) : float |
| 163 | 163 | { |
| 164 | 164 | return $this->toNumber($precision, 'tb'); |
| 165 | 165 | } |
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Converts the bytes to Petabytes. |
|
| 169 | - * |
|
| 170 | - * @param int $precision Amount of decimals (rounded up) |
|
| 171 | - * @return float |
|
| 172 | - */ |
|
| 167 | + /** |
|
| 168 | + * Converts the bytes to Petabytes. |
|
| 169 | + * |
|
| 170 | + * @param int $precision Amount of decimals (rounded up) |
|
| 171 | + * @return float |
|
| 172 | + */ |
|
| 173 | 173 | public function toPetabytes(int $precision=1) : float |
| 174 | 174 | { |
| 175 | 175 | return $this->toNumber($precision, 'pb'); |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $this->bytes = $bytes; |
| 34 | 34 | |
| 35 | 35 | // correct negative values |
| 36 | - if($this->bytes < 0) |
|
| 36 | + if ($this->bytes < 0) |
|
| 37 | 37 | { |
| 38 | 38 | $this->bytes = 0; |
| 39 | 39 | } |
@@ -49,19 +49,19 @@ discard block |
||
| 49 | 49 | { |
| 50 | 50 | $sizes = $this->getSizesSorted($base); |
| 51 | 51 | |
| 52 | - if($this->bytes >= $sizes[0]->getBytes()) |
|
| 52 | + if ($this->bytes >= $sizes[0]->getBytes()) |
|
| 53 | 53 | { |
| 54 | 54 | $total = count($sizes); |
| 55 | 55 | |
| 56 | - for($i=0; $i < $total; $i++) |
|
| 56 | + for ($i = 0; $i < $total; $i++) |
|
| 57 | 57 | { |
| 58 | 58 | $size = $sizes[$i]; |
| 59 | 59 | |
| 60 | - if(!isset($sizes[($i+1)])) { |
|
| 60 | + if (!isset($sizes[($i + 1)])) { |
|
| 61 | 61 | return $size; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if($this->bytes >= $size->getBytes() && $this->bytes < $sizes[($i+1)]->getBytes()) { |
|
| 64 | + if ($this->bytes >= $size->getBytes() && $this->bytes < $sizes[($i + 1)]->getBytes()) { |
|
| 65 | 65 | return $size; |
| 66 | 66 | } |
| 67 | 67 | } |
@@ -99,11 +99,11 @@ discard block |
||
| 99 | 99 | * @see ConvertHelper_StorageSizeEnum::BASE_10 |
| 100 | 100 | * @see ConvertHelper_StorageSizeEnum::BASE_2 |
| 101 | 101 | */ |
| 102 | - public function toString(int $precision, int $base=ConvertHelper_StorageSizeEnum::BASE_10) : string |
|
| 102 | + public function toString(int $precision, int $base = ConvertHelper_StorageSizeEnum::BASE_10) : string |
|
| 103 | 103 | { |
| 104 | 104 | $size = $this->detectSize($base); |
| 105 | 105 | |
| 106 | - return round($this->bytes / $size->getBytes(), $precision) . ' ' . $size->getSuffix(); |
|
| 106 | + return round($this->bytes / $size->getBytes(), $precision).' '.$size->getSuffix(); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | * @param int $precision Amount of decimals (rounded up) |
| 127 | 127 | * @return float |
| 128 | 128 | */ |
| 129 | - public function toKilobytes(int $precision=1) : float |
|
| 129 | + public function toKilobytes(int $precision = 1) : float |
|
| 130 | 130 | { |
| 131 | 131 | return $this->toNumber($precision, 'kb'); |
| 132 | 132 | } |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * @param int $precision Amount of decimals (rounded up) |
| 138 | 138 | * @return float |
| 139 | 139 | */ |
| 140 | - public function toMegabytes(int $precision=1) : float |
|
| 140 | + public function toMegabytes(int $precision = 1) : float |
|
| 141 | 141 | { |
| 142 | 142 | return $this->toNumber($precision, 'mb'); |
| 143 | 143 | } |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * @param int $precision Amount of decimals (rounded up) |
| 149 | 149 | * @return float |
| 150 | 150 | */ |
| 151 | - public function toGigabytes(int $precision=1) : float |
|
| 151 | + public function toGigabytes(int $precision = 1) : float |
|
| 152 | 152 | { |
| 153 | 153 | return $this->toNumber($precision, 'gb'); |
| 154 | 154 | } |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | * @param int $precision Amount of decimals (rounded up) |
| 160 | 160 | * @return float |
| 161 | 161 | */ |
| 162 | - public function toTerabytes(int $precision=1) : float |
|
| 162 | + public function toTerabytes(int $precision = 1) : float |
|
| 163 | 163 | { |
| 164 | 164 | return $this->toNumber($precision, 'tb'); |
| 165 | 165 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | * @param int $precision Amount of decimals (rounded up) |
| 171 | 171 | * @return float |
| 172 | 172 | */ |
| 173 | - public function toPetabytes(int $precision=1) : float |
|
| 173 | + public function toPetabytes(int $precision = 1) : float |
|
| 174 | 174 | { |
| 175 | 175 | return $this->toNumber($precision, 'pb'); |
| 176 | 176 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param int $precision Amount of decimals (rounded up) |
| 182 | 182 | * @return float |
| 183 | 183 | */ |
| 184 | - public function toKibibytes(int $precision=1) : float |
|
| 184 | + public function toKibibytes(int $precision = 1) : float |
|
| 185 | 185 | { |
| 186 | 186 | return $this->toNumber($precision, 'kib'); |
| 187 | 187 | } |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | * @param int $precision Amount of decimals (rounded up) |
| 193 | 193 | * @return float |
| 194 | 194 | */ |
| 195 | - public function toMebibytes(int $precision=1) : float |
|
| 195 | + public function toMebibytes(int $precision = 1) : float |
|
| 196 | 196 | { |
| 197 | 197 | return $this->toNumber($precision, 'mib'); |
| 198 | 198 | } |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | * @param int $precision Amount of decimals (rounded up) |
| 204 | 204 | * @return float |
| 205 | 205 | */ |
| 206 | - public function toGibibytes(int $precision=1) : float |
|
| 206 | + public function toGibibytes(int $precision = 1) : float |
|
| 207 | 207 | { |
| 208 | 208 | return $this->toNumber($precision, 'gib'); |
| 209 | 209 | } |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | * @param int $precision Amount of decimals (rounded up) |
| 215 | 215 | * @return float |
| 216 | 216 | */ |
| 217 | - public function toTebibytes(int $precision=1) : float |
|
| 217 | + public function toTebibytes(int $precision = 1) : float |
|
| 218 | 218 | { |
| 219 | 219 | return $this->toNumber($precision, 'tib'); |
| 220 | 220 | } |
@@ -225,7 +225,7 @@ discard block |
||
| 225 | 225 | * @param int $precision Amount of decimals (rounded up) |
| 226 | 226 | * @return float |
| 227 | 227 | */ |
| 228 | - public function toPebibytes(int $precision=1) : float |
|
| 228 | + public function toPebibytes(int $precision = 1) : float |
|
| 229 | 229 | { |
| 230 | 230 | return $this->toNumber($precision, 'pib'); |
| 231 | 231 | } |
@@ -25,34 +25,34 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class ConvertHelper_StorageSizeEnum_Size |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | 31 | protected $name; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var int |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var int |
|
| 35 | + */ |
|
| 36 | 36 | protected $base; |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var int |
|
| 40 | - */ |
|
| 38 | + /** |
|
| 39 | + * @var int |
|
| 40 | + */ |
|
| 41 | 41 | protected $exponent; |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @var string |
|
| 45 | - */ |
|
| 43 | + /** |
|
| 44 | + * @var string |
|
| 45 | + */ |
|
| 46 | 46 | protected $singular; |
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 48 | + /** |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | 51 | protected $plural; |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 53 | + /** |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | 56 | protected $suffix; |
| 57 | 57 | |
| 58 | 58 | public function __construct(string $name, int $base, int $exponent, string $suffix, string $singular, string $plural) |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | protected static function init() |
| 46 | 46 | { |
| 47 | - if(isset(self::$sizes)) { |
|
| 47 | + if (isset(self::$sizes)) { |
|
| 48 | 48 | return; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | self::addSize('b', 1, 1, t('B'), t('Byte'), t('Bytes')); |
| 66 | 66 | |
| 67 | - if(class_exists('AppLocalize\Localization')) |
|
| 67 | + if (class_exists('AppLocalize\Localization')) |
|
| 68 | 68 | { |
| 69 | 69 | \AppLocalize\Localization::onLocaleChanged(array(self::class, 'handle_localeChanged')); |
| 70 | 70 | } |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | $name = strtolower($name); |
| 134 | 134 | |
| 135 | - if(isset(self::$sizes[$name])) { |
|
| 135 | + if (isset(self::$sizes[$name])) { |
|
| 136 | 136 | return self::$sizes[$name]; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -174,9 +174,9 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | $result = array(); |
| 176 | 176 | |
| 177 | - foreach(self::$sizes as $size) |
|
| 177 | + foreach (self::$sizes as $size) |
|
| 178 | 178 | { |
| 179 | - if($size->getBase() === $base) { |
|
| 179 | + if ($size->getBase() === $base) { |
|
| 180 | 180 | $result[] = $size; |
| 181 | 181 | } |
| 182 | 182 | } |
@@ -31,17 +31,17 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | const BASE_2 = 1024; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var ConvertHelper_StorageSizeEnum_Size[] |
|
| 36 | - */ |
|
| 34 | + /** |
|
| 35 | + * @var ConvertHelper_StorageSizeEnum_Size[] |
|
| 36 | + */ |
|
| 37 | 37 | protected static $sizes; |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Initializes the supported unit notations, and |
|
| 41 | - * how they are supposed to be calculated. |
|
| 42 | - * |
|
| 43 | - * @see ConvertHelper_SizeNotation::parseSize() |
|
| 44 | - */ |
|
| 39 | + /** |
|
| 40 | + * Initializes the supported unit notations, and |
|
| 41 | + * how they are supposed to be calculated. |
|
| 42 | + * |
|
| 43 | + * @see ConvertHelper_SizeNotation::parseSize() |
|
| 44 | + */ |
|
| 45 | 45 | protected static function init() |
| 46 | 46 | { |
| 47 | 47 | if(isset(self::$sizes)) { |
@@ -70,30 +70,30 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * Called whenever the application locale is changed, |
|
| 75 | - * to reset the size definitions so the labels get |
|
| 76 | - * translated to the new locale. |
|
| 77 | - * |
|
| 78 | - * @param \AppLocalize\Localization_Event_LocaleChanged $event |
|
| 79 | - */ |
|
| 73 | + /** |
|
| 74 | + * Called whenever the application locale is changed, |
|
| 75 | + * to reset the size definitions so the labels get |
|
| 76 | + * translated to the new locale. |
|
| 77 | + * |
|
| 78 | + * @param \AppLocalize\Localization_Event_LocaleChanged $event |
|
| 79 | + */ |
|
| 80 | 80 | public static function handle_localeChanged(\AppLocalize\Localization_Event_LocaleChanged $event) |
| 81 | 81 | { |
| 82 | 82 | self::$sizes = null; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Adds a storage size to the internal collection. |
|
| 87 | - * |
|
| 88 | - * @param string $name The lowercase size name, e.g. "kb", "mib" |
|
| 89 | - * @param int $base This defines how many bytes there are in a kilobyte, to differentiate with the two common way to calculate sizes: base 10 or base 2. See the Wikipedia link for more details. |
|
| 90 | - * @param int $exponent The multiplier of the base to get the byte value |
|
| 91 | - * @param string $suffix The localized short suffix, e.g. "KB", "MiB" |
|
| 92 | - * @param string $singular The localized singular label of the size, e.g. "Kilobyte". |
|
| 93 | - * @param string $plural The localized plural label of the size, e.g. "Kilobytes". |
|
| 94 | - * |
|
| 95 | - * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 96 | - */ |
|
| 85 | + /** |
|
| 86 | + * Adds a storage size to the internal collection. |
|
| 87 | + * |
|
| 88 | + * @param string $name The lowercase size name, e.g. "kb", "mib" |
|
| 89 | + * @param int $base This defines how many bytes there are in a kilobyte, to differentiate with the two common way to calculate sizes: base 10 or base 2. See the Wikipedia link for more details. |
|
| 90 | + * @param int $exponent The multiplier of the base to get the byte value |
|
| 91 | + * @param string $suffix The localized short suffix, e.g. "KB", "MiB" |
|
| 92 | + * @param string $singular The localized singular label of the size, e.g. "Kilobyte". |
|
| 93 | + * @param string $plural The localized plural label of the size, e.g. "Kilobytes". |
|
| 94 | + * |
|
| 95 | + * @see https://en.m.wikipedia.org/wiki/Megabyte#Definitions |
|
| 96 | + */ |
|
| 97 | 97 | protected static function addSize(string $name, int $base, int $exponent, string $suffix, string $singular, string $plural) |
| 98 | 98 | { |
| 99 | 99 | self::$sizes[$name] = new ConvertHelper_StorageSizeEnum_Size( |
@@ -106,11 +106,11 @@ discard block |
||
| 106 | 106 | ); |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - /** |
|
| 110 | - * Retrieves all known sizes. |
|
| 111 | - * |
|
| 112 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 113 | - */ |
|
| 109 | + /** |
|
| 110 | + * Retrieves all known sizes. |
|
| 111 | + * |
|
| 112 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 113 | + */ |
|
| 114 | 114 | public static function getSizes() |
| 115 | 115 | { |
| 116 | 116 | self::init(); |
@@ -118,15 +118,15 @@ discard block |
||
| 118 | 118 | return self::$sizes; |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Retrieves a size definition instance by its name. |
|
| 123 | - * |
|
| 124 | - * @param string $name Case insensitive. For example "kb", "MiB"... |
|
| 125 | - * @throws ConvertHelper_Exception |
|
| 126 | - * @return ConvertHelper_StorageSizeEnum_Size |
|
| 127 | - * |
|
| 128 | - * @see ConvertHelper_StorageSizeEnum::ERROR_UNKNOWN_UNIT_NAME |
|
| 129 | - */ |
|
| 121 | + /** |
|
| 122 | + * Retrieves a size definition instance by its name. |
|
| 123 | + * |
|
| 124 | + * @param string $name Case insensitive. For example "kb", "MiB"... |
|
| 125 | + * @throws ConvertHelper_Exception |
|
| 126 | + * @return ConvertHelper_StorageSizeEnum_Size |
|
| 127 | + * |
|
| 128 | + * @see ConvertHelper_StorageSizeEnum::ERROR_UNKNOWN_UNIT_NAME |
|
| 129 | + */ |
|
| 130 | 130 | public static function getSizeByName(string $name) : ConvertHelper_StorageSizeEnum_Size |
| 131 | 131 | { |
| 132 | 132 | self::init(); |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | ); |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Retrieves a list of all size names, e.g. "mb", "kib" (lowercase). |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 151 | + /** |
|
| 152 | + * Retrieves a list of all size names, e.g. "mb", "kib" (lowercase). |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | 155 | public static function getSizeNames() : array |
| 156 | 156 | { |
| 157 | 157 | self::init(); |
@@ -159,16 +159,16 @@ discard block |
||
| 159 | 159 | return array_keys(self::$sizes); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Retrieves all available storage sizes for the specified |
|
| 164 | - * base value. |
|
| 165 | - * |
|
| 166 | - * @param int $base |
|
| 167 | - * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 168 | - * |
|
| 169 | - * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
| 170 | - * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
| 171 | - */ |
|
| 162 | + /** |
|
| 163 | + * Retrieves all available storage sizes for the specified |
|
| 164 | + * base value. |
|
| 165 | + * |
|
| 166 | + * @param int $base |
|
| 167 | + * @return \AppUtils\ConvertHelper_StorageSizeEnum_Size[] |
|
| 168 | + * |
|
| 169 | + * @see ConvertHelper_StorageSizeEnum::BASE_10 |
|
| 170 | + * @see ConvertHelper_StorageSizeEnum::BASE_2 |
|
| 171 | + */ |
|
| 172 | 172 | public static function getSizesByBase(int $base) |
| 173 | 173 | { |
| 174 | 174 | self::init(); |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | const VALIDATION_ERROR_NEGATIVE_VALUE = 43803; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 34 | + /** |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | 37 | protected $sizeString; |
| 38 | 38 | |
| 39 | 39 | /** |
@@ -41,41 +41,41 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | protected $sizeDefinition; |
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var integer |
|
| 46 | - */ |
|
| 44 | + /** |
|
| 45 | + * @var integer |
|
| 46 | + */ |
|
| 47 | 47 | protected $bytes = 0; |
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * @var bool |
|
| 51 | - */ |
|
| 49 | + /** |
|
| 50 | + * @var bool |
|
| 51 | + */ |
|
| 52 | 52 | protected $valid = true; |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 54 | + /** |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | 57 | protected $units = null; |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 59 | + /** |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | 62 | protected $number = ''; |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 64 | + /** |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | 67 | protected $errorMessage = ''; |
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @var int |
|
| 71 | - */ |
|
| 69 | + /** |
|
| 70 | + * @var int |
|
| 71 | + */ |
|
| 72 | 72 | protected $errorCode = 0; |
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Create a new instance for the specified size string. |
|
| 76 | - * |
|
| 77 | - * @param string $sizeString A size notation in the format "50 MB", or a number of bytes without units. Spaces are ignored, so "50MB" = "50 MB" = " 50 MB ". Floating point values are accepted, both with dot and comma notation ("50.5" = "50,5"). To use Base 2 values, ose appropriate units, e.g. "50 MiB", "1.5 GiB". The units are case insensitive, so "50 MB" = "50 mb". |
|
| 78 | - */ |
|
| 74 | + /** |
|
| 75 | + * Create a new instance for the specified size string. |
|
| 76 | + * |
|
| 77 | + * @param string $sizeString A size notation in the format "50 MB", or a number of bytes without units. Spaces are ignored, so "50MB" = "50 MB" = " 50 MB ". Floating point values are accepted, both with dot and comma notation ("50.5" = "50,5"). To use Base 2 values, ose appropriate units, e.g. "50 MiB", "1.5 GiB". The units are case insensitive, so "50 MB" = "50 mb". |
|
| 78 | + */ |
|
| 79 | 79 | public function __construct(string $sizeString) |
| 80 | 80 | { |
| 81 | 81 | $this->sizeString = $this->cleanString($sizeString); |
@@ -83,31 +83,31 @@ discard block |
||
| 83 | 83 | $this->convert(); |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * Gets the amount of bytes contained in the size notation. |
|
| 88 | - * @return int |
|
| 89 | - */ |
|
| 86 | + /** |
|
| 87 | + * Gets the amount of bytes contained in the size notation. |
|
| 88 | + * @return int |
|
| 89 | + */ |
|
| 90 | 90 | public function toBytes() : int |
| 91 | 91 | { |
| 92 | 92 | return $this->bytes; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Converts the size notation to a human readable string, e.g. "50 MB". |
|
| 97 | - * |
|
| 98 | - * @param int $precision |
|
| 99 | - * @return string |
|
| 100 | - * @see ConvertHelper::bytes2readable() |
|
| 101 | - */ |
|
| 95 | + /** |
|
| 96 | + * Converts the size notation to a human readable string, e.g. "50 MB". |
|
| 97 | + * |
|
| 98 | + * @param int $precision |
|
| 99 | + * @return string |
|
| 100 | + * @see ConvertHelper::bytes2readable() |
|
| 101 | + */ |
|
| 102 | 102 | public function toString(int $precision=1) : string |
| 103 | 103 | { |
| 104 | 104 | return ConvertHelper::bytes2readable($this->bytes, $precision, $this->getBase()); |
| 105 | 105 | } |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * Retrieves the detected number's base. |
|
| 109 | - * @return int The base number (1000 for Base 10, or 1024 for Base 2), or 0 if it is not valid. |
|
| 110 | - */ |
|
| 107 | + /** |
|
| 108 | + * Retrieves the detected number's base. |
|
| 109 | + * @return int The base number (1000 for Base 10, or 1024 for Base 2), or 0 if it is not valid. |
|
| 110 | + */ |
|
| 111 | 111 | public function getBase() : int |
| 112 | 112 | { |
| 113 | 113 | if($this->isValid()) { |
@@ -117,13 +117,13 @@ discard block |
||
| 117 | 117 | return 0; |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Retrieves the detected storage size instance, if |
|
| 122 | - * the size string is valid. |
|
| 123 | - * |
|
| 124 | - * @return ConvertHelper_StorageSizeEnum_Size|NULL |
|
| 125 | - * @see ConvertHelper_StorageSizeEnum_Size |
|
| 126 | - */ |
|
| 120 | + /** |
|
| 121 | + * Retrieves the detected storage size instance, if |
|
| 122 | + * the size string is valid. |
|
| 123 | + * |
|
| 124 | + * @return ConvertHelper_StorageSizeEnum_Size|NULL |
|
| 125 | + * @see ConvertHelper_StorageSizeEnum_Size |
|
| 126 | + */ |
|
| 127 | 127 | public function getSizeDefinition() : ?ConvertHelper_StorageSizeEnum_Size |
| 128 | 128 | { |
| 129 | 129 | if($this->isValid()) { |
@@ -133,27 +133,27 @@ discard block |
||
| 133 | 133 | return null; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * Checks whether the size notation was valid and could be parsed |
|
| 138 | - * into a meaningful byte value. If this returns `false`, it is |
|
| 139 | - * possible to use the `getErrorXXX` methods to retrieve information |
|
| 140 | - * on what went wrong. |
|
| 141 | - * |
|
| 142 | - * @return bool |
|
| 143 | - * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
| 144 | - * @see ConvertHelper_SizeNotation::getErrorCode() |
|
| 145 | - */ |
|
| 136 | + /** |
|
| 137 | + * Checks whether the size notation was valid and could be parsed |
|
| 138 | + * into a meaningful byte value. If this returns `false`, it is |
|
| 139 | + * possible to use the `getErrorXXX` methods to retrieve information |
|
| 140 | + * on what went wrong. |
|
| 141 | + * |
|
| 142 | + * @return bool |
|
| 143 | + * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
| 144 | + * @see ConvertHelper_SizeNotation::getErrorCode() |
|
| 145 | + */ |
|
| 146 | 146 | public function isValid() : bool |
| 147 | 147 | { |
| 148 | 148 | return $this->valid; |
| 149 | 149 | } |
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Retrieves the error message if the size notation validation failed. |
|
| 153 | - * |
|
| 154 | - * @return string |
|
| 155 | - * @see ConvertHelper_SizeNotation::getErrorCode() |
|
| 156 | - */ |
|
| 151 | + /** |
|
| 152 | + * Retrieves the error message if the size notation validation failed. |
|
| 153 | + * |
|
| 154 | + * @return string |
|
| 155 | + * @see ConvertHelper_SizeNotation::getErrorCode() |
|
| 156 | + */ |
|
| 157 | 157 | public function getErrorMessage() : string |
| 158 | 158 | { |
| 159 | 159 | return $this->errorMessage; |
@@ -200,12 +200,12 @@ discard block |
||
| 200 | 200 | ); |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - /** |
|
| 204 | - * Detects the units and the number in the size notation string. |
|
| 205 | - * Populates the `units` and `number` properties. |
|
| 206 | - * |
|
| 207 | - * @return bool Whether the string could be parsed successfully. |
|
| 208 | - */ |
|
| 203 | + /** |
|
| 204 | + * Detects the units and the number in the size notation string. |
|
| 205 | + * Populates the `units` and `number` properties. |
|
| 206 | + * |
|
| 207 | + * @return bool Whether the string could be parsed successfully. |
|
| 208 | + */ |
|
| 209 | 209 | protected function detectParts() : bool |
| 210 | 210 | { |
| 211 | 211 | $units = ConvertHelper_StorageSizeEnum::getSizeNames(); |
@@ -241,16 +241,16 @@ discard block |
||
| 241 | 241 | return true; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - /** |
|
| 245 | - * If the validation fails, this is used to store the reason for retrieval later. |
|
| 246 | - * |
|
| 247 | - * @param string $message |
|
| 248 | - * @param int $code |
|
| 249 | - * |
|
| 250 | - * @see ConvertHelper_SizeNotation::isValid() |
|
| 251 | - * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
| 252 | - * @see ConvertHelper_SizeNotation::getErrorCode() |
|
| 253 | - */ |
|
| 244 | + /** |
|
| 245 | + * If the validation fails, this is used to store the reason for retrieval later. |
|
| 246 | + * |
|
| 247 | + * @param string $message |
|
| 248 | + * @param int $code |
|
| 249 | + * |
|
| 250 | + * @see ConvertHelper_SizeNotation::isValid() |
|
| 251 | + * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
| 252 | + * @see ConvertHelper_SizeNotation::getErrorCode() |
|
| 253 | + */ |
|
| 254 | 254 | protected function setError(string $message, int $code) : void |
| 255 | 255 | { |
| 256 | 256 | $this->valid = false; |
@@ -258,12 +258,12 @@ discard block |
||
| 258 | 258 | $this->errorCode = $code; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - /** |
|
| 262 | - * Retrieves the error code, if the size notation validation failed. |
|
| 263 | - * |
|
| 264 | - * @return int |
|
| 265 | - * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
| 266 | - */ |
|
| 261 | + /** |
|
| 262 | + * Retrieves the error code, if the size notation validation failed. |
|
| 263 | + * |
|
| 264 | + * @return int |
|
| 265 | + * @see ConvertHelper_SizeNotation::getErrorMessage() |
|
| 266 | + */ |
|
| 267 | 267 | public function getErrorCode() : int |
| 268 | 268 | { |
| 269 | 269 | return $this->errorCode; |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | * @return string |
| 100 | 100 | * @see ConvertHelper::bytes2readable() |
| 101 | 101 | */ |
| 102 | - public function toString(int $precision=1) : string |
|
| 102 | + public function toString(int $precision = 1) : string |
|
| 103 | 103 | { |
| 104 | 104 | return ConvertHelper::bytes2readable($this->bytes, $precision, $this->getBase()); |
| 105 | 105 | } |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | */ |
| 111 | 111 | public function getBase() : int |
| 112 | 112 | { |
| 113 | - if($this->isValid()) { |
|
| 113 | + if ($this->isValid()) { |
|
| 114 | 114 | return $this->sizeDefinition->getBase(); |
| 115 | 115 | } |
| 116 | 116 | |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function getSizeDefinition() : ?ConvertHelper_StorageSizeEnum_Size |
| 128 | 128 | { |
| 129 | - if($this->isValid()) { |
|
| 129 | + if ($this->isValid()) { |
|
| 130 | 130 | return $this->sizeDefinition; |
| 131 | 131 | } |
| 132 | 132 | |
@@ -175,18 +175,18 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | protected function parseSize() : void |
| 177 | 177 | { |
| 178 | - if(!$this->detectParts()) { |
|
| 178 | + if (!$this->detectParts()) { |
|
| 179 | 179 | return; |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | // we detected units in the string: all good. |
| 183 | - if($this->units !== null) |
|
| 183 | + if ($this->units !== null) |
|
| 184 | 184 | { |
| 185 | 185 | return; |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | // just a numeric value: we assume this means we're dealing with bytes. |
| 189 | - if(is_numeric($this->number)) |
|
| 189 | + if (is_numeric($this->number)) |
|
| 190 | 190 | { |
| 191 | 191 | $this->units = 'b'; |
| 192 | 192 | return; |
@@ -212,12 +212,12 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | $number = $this->sizeString; |
| 214 | 214 | |
| 215 | - foreach($units as $unit) |
|
| 215 | + foreach ($units as $unit) |
|
| 216 | 216 | { |
| 217 | - if(stristr($number, $unit)) |
|
| 217 | + if (stristr($number, $unit)) |
|
| 218 | 218 | { |
| 219 | 219 | // there are more than 1 unit defined in the string |
| 220 | - if($this->units !== null) |
|
| 220 | + if ($this->units !== null) |
|
| 221 | 221 | { |
| 222 | 222 | $this->setError( |
| 223 | 223 | t( |
@@ -273,14 +273,14 @@ discard block |
||
| 273 | 273 | { |
| 274 | 274 | $this->parseSize(); |
| 275 | 275 | |
| 276 | - if(!$this->valid) { |
|
| 276 | + if (!$this->valid) { |
|
| 277 | 277 | return; |
| 278 | 278 | } |
| 279 | 279 | |
| 280 | 280 | $int = intval($this->number); |
| 281 | 281 | |
| 282 | 282 | // negative values |
| 283 | - if($int < 0) |
|
| 283 | + if ($int < 0) |
|
| 284 | 284 | { |
| 285 | 285 | $this->setError( |
| 286 | 286 | t('Negative values cannot be used as size.'), |
@@ -20,24 +20,24 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | class URLInfo_Parser |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | 26 | protected $url; |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var bool |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var bool |
|
| 30 | + */ |
|
| 31 | 31 | protected $isValid = false; |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 33 | + /** |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | 36 | protected $info; |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @var array|NULL |
|
| 40 | - */ |
|
| 38 | + /** |
|
| 39 | + * @var array|NULL |
|
| 40 | + */ |
|
| 41 | 41 | protected $error; |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -177,11 +177,11 @@ discard block |
||
| 177 | 177 | return false; |
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - /** |
|
| 181 | - * Goes through all information in the parse_url result |
|
| 182 | - * array, and attempts to fix any user errors in formatting |
|
| 183 | - * that can be recovered from, mostly regarding stray spaces. |
|
| 184 | - */ |
|
| 180 | + /** |
|
| 181 | + * Goes through all information in the parse_url result |
|
| 182 | + * array, and attempts to fix any user errors in formatting |
|
| 183 | + * that can be recovered from, mostly regarding stray spaces. |
|
| 184 | + */ |
|
| 185 | 185 | protected function filterParsed() |
| 186 | 186 | { |
| 187 | 187 | foreach($this->info as $key => $val) |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | $this->parse(); |
| 61 | 61 | |
| 62 | - if(!$this->detectType()) { |
|
| 62 | + if (!$this->detectType()) { |
|
| 63 | 63 | $this->validate(); |
| 64 | 64 | } |
| 65 | 65 | } |
@@ -93,11 +93,11 @@ discard block |
||
| 93 | 93 | 'phoneLink' |
| 94 | 94 | ); |
| 95 | 95 | |
| 96 | - foreach($types as $type) |
|
| 96 | + foreach ($types as $type) |
|
| 97 | 97 | { |
| 98 | 98 | $method = 'detectType_'.$type; |
| 99 | 99 | |
| 100 | - if($this->$method() === true) |
|
| 100 | + if ($this->$method() === true) |
|
| 101 | 101 | { |
| 102 | 102 | $this->isValid = true; |
| 103 | 103 | return true; |
@@ -115,11 +115,11 @@ discard block |
||
| 115 | 115 | 'hostIsPresent' |
| 116 | 116 | ); |
| 117 | 117 | |
| 118 | - foreach($validations as $validation) |
|
| 118 | + foreach ($validations as $validation) |
|
| 119 | 119 | { |
| 120 | 120 | $method = 'validate_'.$validation; |
| 121 | 121 | |
| 122 | - if($this->$method() !== true) { |
|
| 122 | + if ($this->$method() !== true) { |
|
| 123 | 123 | return; |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -132,13 +132,13 @@ discard block |
||
| 132 | 132 | // every link needs a host. This case can happen for ex, if |
| 133 | 133 | // the link starts with a typo with only one slash, like: |
| 134 | 134 | // "http:/hostname" |
| 135 | - if(isset($this->info['host'])) { |
|
| 135 | + if (isset($this->info['host'])) { |
|
| 136 | 136 | return true; |
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | $this->setError( |
| 140 | 140 | URLInfo::ERROR_MISSING_HOST, |
| 141 | - t('Cannot determine the link\'s host name.') . ' ' . |
|
| 141 | + t('Cannot determine the link\'s host name.').' '. |
|
| 142 | 142 | t('This usually happens when there\'s a typo somewhere.') |
| 143 | 143 | ); |
| 144 | 144 | |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | |
| 148 | 148 | protected function validate_schemeIsSet() : bool |
| 149 | 149 | { |
| 150 | - if(isset($this->info['scheme'])) { |
|
| 150 | + if (isset($this->info['scheme'])) { |
|
| 151 | 151 | return true; |
| 152 | 152 | } |
| 153 | 153 | |
@@ -164,13 +164,13 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | protected function validate_schemeIsKnown() : bool |
| 166 | 166 | { |
| 167 | - if(in_array($this->info['scheme'], $this->knownSchemes)) { |
|
| 167 | + if (in_array($this->info['scheme'], $this->knownSchemes)) { |
|
| 168 | 168 | return true; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | 171 | $this->setError( |
| 172 | 172 | URLInfo::ERROR_INVALID_SCHEME, |
| 173 | - t('The scheme %1$s is not supported for links.', $this->info['scheme']) . ' ' . |
|
| 173 | + t('The scheme %1$s is not supported for links.', $this->info['scheme']).' '. |
|
| 174 | 174 | t('Valid schemes are: %1$s.', implode(', ', $this->knownSchemes)) |
| 175 | 175 | ); |
| 176 | 176 | |
@@ -184,9 +184,9 @@ discard block |
||
| 184 | 184 | */ |
| 185 | 185 | protected function filterParsed() |
| 186 | 186 | { |
| 187 | - foreach($this->info as $key => $val) |
|
| 187 | + foreach ($this->info as $key => $val) |
|
| 188 | 188 | { |
| 189 | - if(is_string($val)) { |
|
| 189 | + if (is_string($val)) { |
|
| 190 | 190 | $this->info[$key] = trim($val); |
| 191 | 191 | } |
| 192 | 192 | } |
@@ -194,15 +194,15 @@ discard block |
||
| 194 | 194 | $this->info['params'] = array(); |
| 195 | 195 | $this->info['type'] = URLInfo::TYPE_URL; |
| 196 | 196 | |
| 197 | - if(isset($this->info['host'])) { |
|
| 197 | + if (isset($this->info['host'])) { |
|
| 198 | 198 | $this->info['host'] = str_replace(' ', '', $this->info['host']); |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - if(isset($this->info['path'])) { |
|
| 201 | + if (isset($this->info['path'])) { |
|
| 202 | 202 | $this->info['path'] = str_replace(' ', '', $this->info['path']); |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | - if(isset($this->info['query']) && !empty($this->info['query'])) |
|
| 205 | + if (isset($this->info['query']) && !empty($this->info['query'])) |
|
| 206 | 206 | { |
| 207 | 207 | $this->info['params'] = \AppUtils\ConvertHelper::parseQueryString($this->info['query']); |
| 208 | 208 | ksort($this->info['params']); |
@@ -211,12 +211,12 @@ discard block |
||
| 211 | 211 | |
| 212 | 212 | protected function detectType_email() : bool |
| 213 | 213 | { |
| 214 | - if(isset($this->info['scheme']) && $this->info['scheme'] == 'mailto') { |
|
| 214 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'mailto') { |
|
| 215 | 215 | $this->info['type'] = URLInfo::TYPE_EMAIL; |
| 216 | 216 | return true; |
| 217 | 217 | } |
| 218 | 218 | |
| 219 | - if(isset($this->info['path']) && preg_match(\AppUtils\RegexHelper::REGEX_EMAIL, $this->info['path'])) |
|
| 219 | + if (isset($this->info['path']) && preg_match(\AppUtils\RegexHelper::REGEX_EMAIL, $this->info['path'])) |
|
| 220 | 220 | { |
| 221 | 221 | $this->info['scheme'] = 'mailto'; |
| 222 | 222 | $this->info['type'] = URLInfo::TYPE_EMAIL; |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | protected function detectType_fragmentLink() : bool |
| 230 | 230 | { |
| 231 | - if(isset($this->info['fragment']) && !isset($this->info['scheme'])) { |
|
| 231 | + if (isset($this->info['fragment']) && !isset($this->info['scheme'])) { |
|
| 232 | 232 | $this->info['type'] = URLInfo::TYPE_FRAGMENT; |
| 233 | 233 | return true; |
| 234 | 234 | } |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | |
| 239 | 239 | protected function detectType_phoneLink() : bool |
| 240 | 240 | { |
| 241 | - if(isset($this->info['scheme']) && $this->info['scheme'] == 'tel') { |
|
| 241 | + if (isset($this->info['scheme']) && $this->info['scheme'] == 'tel') { |
|
| 242 | 242 | $this->info['type'] = URLInfo::TYPE_PHONE; |
| 243 | 243 | return true; |
| 244 | 244 | } |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | public function getErrorMessage() : string |
| 265 | 265 | { |
| 266 | - if(isset($this->error)) { |
|
| 266 | + if (isset($this->error)) { |
|
| 267 | 267 | return $this->error['message']; |
| 268 | 268 | } |
| 269 | 269 | |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | |
| 273 | 273 | public function getErrorCode() : int |
| 274 | 274 | { |
| 275 | - if(isset($this->error)) { |
|
| 275 | + if (isset($this->error)) { |
|
| 276 | 276 | return $this->error['code']; |
| 277 | 277 | } |
| 278 | 278 | |
@@ -20,9 +20,9 @@ |
||
| 20 | 20 | */ |
| 21 | 21 | class URLInfo_Highlighter |
| 22 | 22 | { |
| 23 | - /** |
|
| 24 | - * @var URLInfo |
|
| 25 | - */ |
|
| 23 | + /** |
|
| 24 | + * @var URLInfo |
|
| 25 | + */ |
|
| 26 | 26 | protected $info; |
| 27 | 27 | |
| 28 | 28 | public function __construct(URLInfo $info) |
@@ -204,13 +204,11 @@ |
||
| 204 | 204 | $tooltip, |
| 205 | 205 | $parts |
| 206 | 206 | ); |
| 207 | - } |
|
| 208 | - else |
|
| 207 | + } else |
|
| 209 | 208 | { |
| 210 | 209 | continue; |
| 211 | 210 | } |
| 212 | - } |
|
| 213 | - else |
|
| 211 | + } else |
|
| 214 | 212 | { |
| 215 | 213 | $tag = sprintf( |
| 216 | 214 | '<span class="link-param">%s</span>', |
@@ -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 | |
@@ -162,19 +162,19 @@ discard block |
||
| 162 | 162 | { |
| 163 | 163 | $params = $this->info->getParams(); |
| 164 | 164 | |
| 165 | - if(empty($params)) { |
|
| 165 | + if (empty($params)) { |
|
| 166 | 166 | return ''; |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | $tokens = array(); |
| 170 | 170 | $excluded = array(); |
| 171 | 171 | |
| 172 | - if($this->info->isParamExclusionEnabled()) |
|
| 172 | + if ($this->info->isParamExclusionEnabled()) |
|
| 173 | 173 | { |
| 174 | 174 | $excluded = $this->info->getExcludedParams(); |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - foreach($params as $param => $value) |
|
| 177 | + foreach ($params as $param => $value) |
|
| 178 | 178 | { |
| 179 | 179 | $parts = sprintf( |
| 180 | 180 | '<span class="link-param-name">%s</span>'. |
@@ -192,10 +192,10 @@ discard block |
||
| 192 | 192 | $tag = ''; |
| 193 | 193 | |
| 194 | 194 | // is parameter exclusion enabled, and is this an excluded parameter? |
| 195 | - if(isset($excluded[$param])) |
|
| 195 | + if (isset($excluded[$param])) |
|
| 196 | 196 | { |
| 197 | 197 | // display the excluded parameter, but highlight it |
| 198 | - if($this->info->isHighlightExcludeEnabled()) |
|
| 198 | + if ($this->info->isHighlightExcludeEnabled()) |
|
| 199 | 199 | { |
| 200 | 200 | $tooltip = $excluded[$param]; |
| 201 | 201 | |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | protected function render_fragment() : string |
| 230 | 230 | { |
| 231 | - if(!$this->info->hasFragment()) { |
|
| 231 | + if (!$this->info->hasFragment()) { |
|
| 232 | 232 | return ''; |
| 233 | 233 | } |
| 234 | 234 | |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | { |
| 244 | 244 | $cssFolder = realpath(__DIR__.'/../../css'); |
| 245 | 245 | |
| 246 | - if($cssFolder === false) { |
|
| 246 | + if ($cssFolder === false) { |
|
| 247 | 247 | throw new BaseException( |
| 248 | 248 | 'Cannot find package CSS folder.', |
| 249 | 249 | null, |
@@ -37,42 +37,42 @@ discard block |
||
| 37 | 37 | const TYPE_PHONE = 'phone'; |
| 38 | 38 | const TYPE_URL = 'url'; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * The original URL that was passed to the constructor. |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 40 | + /** |
|
| 41 | + * The original URL that was passed to the constructor. |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | 44 | protected $rawURL; |
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * @var array |
|
| 48 | - */ |
|
| 46 | + /** |
|
| 47 | + * @var array |
|
| 48 | + */ |
|
| 49 | 49 | protected $info; |
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * @var string[] |
|
| 53 | - */ |
|
| 51 | + /** |
|
| 52 | + * @var string[] |
|
| 53 | + */ |
|
| 54 | 54 | protected $excludedParams = array(); |
| 55 | 55 | |
| 56 | - /** |
|
| 57 | - * @var bool |
|
| 58 | - * @see URLInfo::setParamExclusion() |
|
| 59 | - */ |
|
| 56 | + /** |
|
| 57 | + * @var bool |
|
| 58 | + * @see URLInfo::setParamExclusion() |
|
| 59 | + */ |
|
| 60 | 60 | protected $paramExclusion = false; |
| 61 | 61 | |
| 62 | - /** |
|
| 63 | - * @var array |
|
| 64 | - * @see URLInfo::getTypeLabel() |
|
| 65 | - */ |
|
| 62 | + /** |
|
| 63 | + * @var array |
|
| 64 | + * @see URLInfo::getTypeLabel() |
|
| 65 | + */ |
|
| 66 | 66 | protected static $typeLabels; |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @var bool |
|
| 70 | - */ |
|
| 68 | + /** |
|
| 69 | + * @var bool |
|
| 70 | + */ |
|
| 71 | 71 | protected $highlightExcluded = false; |
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @var array |
|
| 75 | - */ |
|
| 73 | + /** |
|
| 74 | + * @var array |
|
| 75 | + */ |
|
| 76 | 76 | protected $infoKeys = array( |
| 77 | 77 | 'scheme', |
| 78 | 78 | 'host', |
@@ -84,19 +84,19 @@ discard block |
||
| 84 | 84 | 'fragment' |
| 85 | 85 | ); |
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * @var string |
|
| 89 | - */ |
|
| 87 | + /** |
|
| 88 | + * @var string |
|
| 89 | + */ |
|
| 90 | 90 | protected $url; |
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @var URLInfo_Parser |
|
| 94 | - */ |
|
| 92 | + /** |
|
| 93 | + * @var URLInfo_Parser |
|
| 94 | + */ |
|
| 95 | 95 | protected $parser; |
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @var URLInfo_Normalizer |
|
| 99 | - */ |
|
| 97 | + /** |
|
| 98 | + * @var URLInfo_Normalizer |
|
| 99 | + */ |
|
| 100 | 100 | protected $normalizer; |
| 101 | 101 | |
| 102 | 102 | public function __construct(string $url) |
@@ -108,13 +108,13 @@ discard block |
||
| 108 | 108 | $this->info = $this->parser->getInfo(); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Filters an URL: removes control characters and the |
|
| 113 | - * like to have a clean URL to work with. |
|
| 114 | - * |
|
| 115 | - * @param string $url |
|
| 116 | - * @return string |
|
| 117 | - */ |
|
| 111 | + /** |
|
| 112 | + * Filters an URL: removes control characters and the |
|
| 113 | + * like to have a clean URL to work with. |
|
| 114 | + * |
|
| 115 | + * @param string $url |
|
| 116 | + * @return string |
|
| 117 | + */ |
|
| 118 | 118 | public static function filterURL(string $url) |
| 119 | 119 | { |
| 120 | 120 | return URLInfo_Filter::filter($url); |
@@ -144,12 +144,12 @@ discard block |
||
| 144 | 144 | return $this->info['type'] === self::TYPE_PHONE; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Whether the URL is a regular URL, not one of the |
|
| 149 | - * other types like a phone number or email address. |
|
| 150 | - * |
|
| 151 | - * @return bool |
|
| 152 | - */ |
|
| 147 | + /** |
|
| 148 | + * Whether the URL is a regular URL, not one of the |
|
| 149 | + * other types like a phone number or email address. |
|
| 150 | + * |
|
| 151 | + * @return bool |
|
| 152 | + */ |
|
| 153 | 153 | public function isURL() : bool |
| 154 | 154 | { |
| 155 | 155 | $host = $this->getHost(); |
@@ -161,20 +161,20 @@ discard block |
||
| 161 | 161 | return $this->parser->isValid(); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Retrieves the host name, or an empty string if none is present. |
|
| 166 | - * |
|
| 167 | - * @return string |
|
| 168 | - */ |
|
| 164 | + /** |
|
| 165 | + * Retrieves the host name, or an empty string if none is present. |
|
| 166 | + * |
|
| 167 | + * @return string |
|
| 168 | + */ |
|
| 169 | 169 | public function getHost() : string |
| 170 | 170 | { |
| 171 | 171 | return $this->getInfoKey('host'); |
| 172 | 172 | } |
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * Retrieves the path, or an empty string if none is present. |
|
| 176 | - * @return string |
|
| 177 | - */ |
|
| 174 | + /** |
|
| 175 | + * Retrieves the path, or an empty string if none is present. |
|
| 176 | + * @return string |
|
| 177 | + */ |
|
| 178 | 178 | public function getPath() : string |
| 179 | 179 | { |
| 180 | 180 | return $this->getInfoKey('path'); |
@@ -190,10 +190,10 @@ discard block |
||
| 190 | 190 | return $this->getInfoKey('scheme'); |
| 191 | 191 | } |
| 192 | 192 | |
| 193 | - /** |
|
| 194 | - * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
| 195 | - * @return int |
|
| 196 | - */ |
|
| 193 | + /** |
|
| 194 | + * Retrieves the port specified in the URL, or -1 if none is preseent. |
|
| 195 | + * @return int |
|
| 196 | + */ |
|
| 197 | 197 | public function getPort() : int |
| 198 | 198 | { |
| 199 | 199 | $port = $this->getInfoKey('port'); |
@@ -205,13 +205,13 @@ discard block |
||
| 205 | 205 | return -1; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - /** |
|
| 209 | - * Retrieves the raw query string, or an empty string if none is present. |
|
| 210 | - * |
|
| 211 | - * @return string |
|
| 212 | - * |
|
| 213 | - * @see URLInfo::getParams() |
|
| 214 | - */ |
|
| 208 | + /** |
|
| 209 | + * Retrieves the raw query string, or an empty string if none is present. |
|
| 210 | + * |
|
| 211 | + * @return string |
|
| 212 | + * |
|
| 213 | + * @see URLInfo::getParams() |
|
| 214 | + */ |
|
| 215 | 215 | public function getQuery() : string |
| 216 | 216 | { |
| 217 | 217 | return $this->getInfoKey('query'); |
@@ -227,20 +227,20 @@ discard block |
||
| 227 | 227 | return $this->getInfoKey('pass'); |
| 228 | 228 | } |
| 229 | 229 | |
| 230 | - /** |
|
| 231 | - * Whether the URL contains a port number. |
|
| 232 | - * @return bool |
|
| 233 | - */ |
|
| 230 | + /** |
|
| 231 | + * Whether the URL contains a port number. |
|
| 232 | + * @return bool |
|
| 233 | + */ |
|
| 234 | 234 | public function hasPort() : bool |
| 235 | 235 | { |
| 236 | 236 | return $this->getPort() !== -1; |
| 237 | 237 | } |
| 238 | 238 | |
| 239 | - /** |
|
| 240 | - * Alias for the hasParams() method. |
|
| 241 | - * @return bool |
|
| 242 | - * @see URLInfo::hasParams() |
|
| 243 | - */ |
|
| 239 | + /** |
|
| 240 | + * Alias for the hasParams() method. |
|
| 241 | + * @return bool |
|
| 242 | + * @see URLInfo::hasParams() |
|
| 243 | + */ |
|
| 244 | 244 | public function hasQuery() : bool |
| 245 | 245 | { |
| 246 | 246 | return $this->hasParams(); |
@@ -298,25 +298,25 @@ discard block |
||
| 298 | 298 | return $this->normalizer->normalize(); |
| 299 | 299 | } |
| 300 | 300 | |
| 301 | - /** |
|
| 302 | - * Creates a hash of the URL, which can be used for comparisons. |
|
| 303 | - * Since any parameters in the URL's query are sorted alphabetically, |
|
| 304 | - * the same links with a different parameter order will have the |
|
| 305 | - * same hash. |
|
| 306 | - * |
|
| 307 | - * @return string |
|
| 308 | - */ |
|
| 301 | + /** |
|
| 302 | + * Creates a hash of the URL, which can be used for comparisons. |
|
| 303 | + * Since any parameters in the URL's query are sorted alphabetically, |
|
| 304 | + * the same links with a different parameter order will have the |
|
| 305 | + * same hash. |
|
| 306 | + * |
|
| 307 | + * @return string |
|
| 308 | + */ |
|
| 309 | 309 | public function getHash() |
| 310 | 310 | { |
| 311 | 311 | return \AppUtils\ConvertHelper::string2shortHash($this->getNormalized()); |
| 312 | 312 | } |
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * Highlights the URL using HTML tags with specific highlighting |
|
| 316 | - * class names. |
|
| 317 | - * |
|
| 318 | - * @return string Will return an empty string if the URL is not valid. |
|
| 319 | - */ |
|
| 314 | + /** |
|
| 315 | + * Highlights the URL using HTML tags with specific highlighting |
|
| 316 | + * class names. |
|
| 317 | + * |
|
| 318 | + * @return string Will return an empty string if the URL is not valid. |
|
| 319 | + */ |
|
| 320 | 320 | public function getHighlighted() : string |
| 321 | 321 | { |
| 322 | 322 | if(!$this->isValid()) { |
@@ -350,15 +350,15 @@ discard block |
||
| 350 | 350 | return count($params); |
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - /** |
|
| 354 | - * Retrieves all parameters specified in the url, |
|
| 355 | - * if any, as an associative array. |
|
| 356 | - * |
|
| 357 | - * NOTE: Ignores parameters that have been added |
|
| 358 | - * to the excluded parameters list. |
|
| 359 | - * |
|
| 360 | - * @return array |
|
| 361 | - */ |
|
| 353 | + /** |
|
| 354 | + * Retrieves all parameters specified in the url, |
|
| 355 | + * if any, as an associative array. |
|
| 356 | + * |
|
| 357 | + * NOTE: Ignores parameters that have been added |
|
| 358 | + * to the excluded parameters list. |
|
| 359 | + * |
|
| 360 | + * @return array |
|
| 361 | + */ |
|
| 362 | 362 | public function getParams() : array |
| 363 | 363 | { |
| 364 | 364 | if(!$this->paramExclusion || empty($this->excludedParams)) { |
@@ -376,22 +376,22 @@ discard block |
||
| 376 | 376 | return $keep; |
| 377 | 377 | } |
| 378 | 378 | |
| 379 | - /** |
|
| 380 | - * Retrieves the names of all parameters present in the URL, if any. |
|
| 381 | - * @return string[] |
|
| 382 | - */ |
|
| 379 | + /** |
|
| 380 | + * Retrieves the names of all parameters present in the URL, if any. |
|
| 381 | + * @return string[] |
|
| 382 | + */ |
|
| 383 | 383 | public function getParamNames() : array |
| 384 | 384 | { |
| 385 | 385 | $params = $this->getParams(); |
| 386 | 386 | return array_keys($params); |
| 387 | 387 | } |
| 388 | 388 | |
| 389 | - /** |
|
| 390 | - * Retrieves a specific parameter value from the URL. |
|
| 391 | - * |
|
| 392 | - * @param string $name |
|
| 393 | - * @return string The parameter value, or an empty string if it does not exist. |
|
| 394 | - */ |
|
| 389 | + /** |
|
| 390 | + * Retrieves a specific parameter value from the URL. |
|
| 391 | + * |
|
| 392 | + * @param string $name |
|
| 393 | + * @return string The parameter value, or an empty string if it does not exist. |
|
| 394 | + */ |
|
| 395 | 395 | public function getParam(string $name) : string |
| 396 | 396 | { |
| 397 | 397 | if(isset($this->info['params'][$name])) { |
@@ -401,16 +401,16 @@ discard block |
||
| 401 | 401 | return ''; |
| 402 | 402 | } |
| 403 | 403 | |
| 404 | - /** |
|
| 405 | - * Excludes an URL parameter entirely if present: |
|
| 406 | - * the parser will act as if the parameter was not |
|
| 407 | - * even present in the source URL, effectively |
|
| 408 | - * stripping it. |
|
| 409 | - * |
|
| 410 | - * @param string $name |
|
| 411 | - * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
| 412 | - * @return URLInfo |
|
| 413 | - */ |
|
| 404 | + /** |
|
| 405 | + * Excludes an URL parameter entirely if present: |
|
| 406 | + * the parser will act as if the parameter was not |
|
| 407 | + * even present in the source URL, effectively |
|
| 408 | + * stripping it. |
|
| 409 | + * |
|
| 410 | + * @param string $name |
|
| 411 | + * @param string $reason A human readable explanation why this is excluded - used when highlighting links. |
|
| 412 | + * @return URLInfo |
|
| 413 | + */ |
|
| 414 | 414 | public function excludeParam(string $name, string $reason) : URLInfo |
| 415 | 415 | { |
| 416 | 416 | if(!isset($this->excludedParams[$name])) |
@@ -463,25 +463,25 @@ discard block |
||
| 463 | 463 | return self::$typeLabels[$this->getType()]; |
| 464 | 464 | } |
| 465 | 465 | |
| 466 | - /** |
|
| 467 | - * Whether excluded parameters should be highlighted in |
|
| 468 | - * a different color in the URL when using the |
|
| 469 | - * {@link URLInfo::getHighlighted()} method. |
|
| 470 | - * |
|
| 471 | - * @param bool $highlight |
|
| 472 | - * @return URLInfo |
|
| 473 | - */ |
|
| 466 | + /** |
|
| 467 | + * Whether excluded parameters should be highlighted in |
|
| 468 | + * a different color in the URL when using the |
|
| 469 | + * {@link URLInfo::getHighlighted()} method. |
|
| 470 | + * |
|
| 471 | + * @param bool $highlight |
|
| 472 | + * @return URLInfo |
|
| 473 | + */ |
|
| 474 | 474 | public function setHighlightExcluded(bool $highlight=true) : URLInfo |
| 475 | 475 | { |
| 476 | 476 | $this->highlightExcluded = $highlight; |
| 477 | 477 | return $this; |
| 478 | 478 | } |
| 479 | 479 | |
| 480 | - /** |
|
| 481 | - * Returns an array with all relevant URL information. |
|
| 482 | - * |
|
| 483 | - * @return array |
|
| 484 | - */ |
|
| 480 | + /** |
|
| 481 | + * Returns an array with all relevant URL information. |
|
| 482 | + * |
|
| 483 | + * @return array |
|
| 484 | + */ |
|
| 485 | 485 | public function toArray() : array |
| 486 | 486 | { |
| 487 | 487 | return array( |
@@ -525,24 +525,24 @@ discard block |
||
| 525 | 525 | return $this; |
| 526 | 526 | } |
| 527 | 527 | |
| 528 | - /** |
|
| 529 | - * Whether the parameter exclusion mode is enabled: |
|
| 530 | - * In this case, if any parameters have been added to the |
|
| 531 | - * exclusion list, all relevant methods will exclude these. |
|
| 532 | - * |
|
| 533 | - * @return bool |
|
| 534 | - */ |
|
| 528 | + /** |
|
| 529 | + * Whether the parameter exclusion mode is enabled: |
|
| 530 | + * In this case, if any parameters have been added to the |
|
| 531 | + * exclusion list, all relevant methods will exclude these. |
|
| 532 | + * |
|
| 533 | + * @return bool |
|
| 534 | + */ |
|
| 535 | 535 | public function isParamExclusionEnabled() : bool |
| 536 | 536 | { |
| 537 | 537 | return $this->paramExclusion; |
| 538 | 538 | } |
| 539 | 539 | |
| 540 | - /** |
|
| 541 | - * Checks whether the link contains any parameters that |
|
| 542 | - * are on the list of excluded parameters. |
|
| 543 | - * |
|
| 544 | - * @return bool |
|
| 545 | - */ |
|
| 540 | + /** |
|
| 541 | + * Checks whether the link contains any parameters that |
|
| 542 | + * are on the list of excluded parameters. |
|
| 543 | + * |
|
| 544 | + * @return bool |
|
| 545 | + */ |
|
| 546 | 546 | public function containsExcludedParams() : bool |
| 547 | 547 | { |
| 548 | 548 | if(empty($this->excludedParams)) { |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | { |
| 199 | 199 | $port = $this->getInfoKey('port'); |
| 200 | 200 | |
| 201 | - if(!empty($port)) { |
|
| 201 | + if (!empty($port)) { |
|
| 202 | 202 | return (int)$port; |
| 203 | 203 | } |
| 204 | 204 | |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | |
| 279 | 279 | protected function getInfoKey(string $name) : string |
| 280 | 280 | { |
| 281 | - if(isset($this->info[$name])) { |
|
| 281 | + if (isset($this->info[$name])) { |
|
| 282 | 282 | return (string)$this->info[$name]; |
| 283 | 283 | } |
| 284 | 284 | |
@@ -287,11 +287,11 @@ discard block |
||
| 287 | 287 | |
| 288 | 288 | public function getNormalized() : string |
| 289 | 289 | { |
| 290 | - if(!$this->isValid()) { |
|
| 290 | + if (!$this->isValid()) { |
|
| 291 | 291 | return ''; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - if(!isset($this->normalizer)) { |
|
| 294 | + if (!isset($this->normalizer)) { |
|
| 295 | 295 | $this->normalizer = new URLInfo_Normalizer($this); |
| 296 | 296 | } |
| 297 | 297 | |
@@ -319,7 +319,7 @@ discard block |
||
| 319 | 319 | */ |
| 320 | 320 | public function getHighlighted() : string |
| 321 | 321 | { |
| 322 | - if(!$this->isValid()) { |
|
| 322 | + if (!$this->isValid()) { |
|
| 323 | 323 | return ''; |
| 324 | 324 | } |
| 325 | 325 | |
@@ -361,14 +361,14 @@ discard block |
||
| 361 | 361 | */ |
| 362 | 362 | public function getParams() : array |
| 363 | 363 | { |
| 364 | - if(!$this->paramExclusion || empty($this->excludedParams)) { |
|
| 364 | + if (!$this->paramExclusion || empty($this->excludedParams)) { |
|
| 365 | 365 | return $this->info['params']; |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | $keep = array(); |
| 369 | - foreach($this->info['params'] as $name => $value) |
|
| 369 | + foreach ($this->info['params'] as $name => $value) |
|
| 370 | 370 | { |
| 371 | - if(!isset($this->excludedParams[$name])) { |
|
| 371 | + if (!isset($this->excludedParams[$name])) { |
|
| 372 | 372 | $keep[$name] = $value; |
| 373 | 373 | } |
| 374 | 374 | } |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | */ |
| 395 | 395 | public function getParam(string $name) : string |
| 396 | 396 | { |
| 397 | - if(isset($this->info['params'][$name])) { |
|
| 397 | + if (isset($this->info['params'][$name])) { |
|
| 398 | 398 | return $this->info['params'][$name]; |
| 399 | 399 | } |
| 400 | 400 | |
@@ -413,7 +413,7 @@ discard block |
||
| 413 | 413 | */ |
| 414 | 414 | public function excludeParam(string $name, string $reason) : URLInfo |
| 415 | 415 | { |
| 416 | - if(!isset($this->excludedParams[$name])) |
|
| 416 | + if (!isset($this->excludedParams[$name])) |
|
| 417 | 417 | { |
| 418 | 418 | $this->excludedParams[$name] = $reason; |
| 419 | 419 | $this->setParamExclusion(); |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | |
| 440 | 440 | public function getTypeLabel() : string |
| 441 | 441 | { |
| 442 | - if(!isset(self::$typeLabels)) |
|
| 442 | + if (!isset(self::$typeLabels)) |
|
| 443 | 443 | { |
| 444 | 444 | self::$typeLabels = array( |
| 445 | 445 | self::TYPE_EMAIL => t('Email'), |
@@ -451,7 +451,7 @@ discard block |
||
| 451 | 451 | |
| 452 | 452 | $type = $this->getType(); |
| 453 | 453 | |
| 454 | - if(!isset(self::$typeLabels[$type])) |
|
| 454 | + if (!isset(self::$typeLabels[$type])) |
|
| 455 | 455 | { |
| 456 | 456 | throw new BaseException( |
| 457 | 457 | sprintf('Unknown URL type label for type [%s].', $type), |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | * @param bool $highlight |
| 472 | 472 | * @return URLInfo |
| 473 | 473 | */ |
| 474 | - public function setHighlightExcluded(bool $highlight=true) : URLInfo |
|
| 474 | + public function setHighlightExcluded(bool $highlight = true) : URLInfo |
|
| 475 | 475 | { |
| 476 | 476 | $this->highlightExcluded = $highlight; |
| 477 | 477 | return $this; |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | * @see URLInfo::isParamExclusionEnabled() |
| 520 | 520 | * @see URLInfo::setHighlightExcluded() |
| 521 | 521 | */ |
| 522 | - public function setParamExclusion(bool $enabled=true) : URLInfo |
|
| 522 | + public function setParamExclusion(bool $enabled = true) : URLInfo |
|
| 523 | 523 | { |
| 524 | 524 | $this->paramExclusion = $enabled; |
| 525 | 525 | return $this; |
@@ -545,13 +545,13 @@ discard block |
||
| 545 | 545 | */ |
| 546 | 546 | public function containsExcludedParams() : bool |
| 547 | 547 | { |
| 548 | - if(empty($this->excludedParams)) { |
|
| 548 | + if (empty($this->excludedParams)) { |
|
| 549 | 549 | return false; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | 552 | $names = array_keys($this->info['params']); |
| 553 | - foreach($names as $name) { |
|
| 554 | - if(isset($this->excludedParams[$name])) { |
|
| 553 | + foreach ($names as $name) { |
|
| 554 | + if (isset($this->excludedParams[$name])) { |
|
| 555 | 555 | return true; |
| 556 | 556 | } |
| 557 | 557 | } |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | |
| 568 | 568 | public function offsetSet($offset, $value) |
| 569 | 569 | { |
| 570 | - if(in_array($offset, $this->infoKeys)) { |
|
| 570 | + if (in_array($offset, $this->infoKeys)) { |
|
| 571 | 571 | $this->info[$offset] = $value; |
| 572 | 572 | } |
| 573 | 573 | } |
@@ -584,11 +584,11 @@ discard block |
||
| 584 | 584 | |
| 585 | 585 | public function offsetGet($offset) |
| 586 | 586 | { |
| 587 | - if($offset === 'port') { |
|
| 587 | + if ($offset === 'port') { |
|
| 588 | 588 | return $this->getPort(); |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - if(in_array($offset, $this->infoKeys)) { |
|
| 591 | + if (in_array($offset, $this->infoKeys)) { |
|
| 592 | 592 | return $this->getInfoKey($offset); |
| 593 | 593 | } |
| 594 | 594 | |