@@ -162,41 +162,41 @@ discard block |
||
| 162 | 162 | return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | - /** |
|
| 166 | - * Converts a timestamp into an easily understandable |
|
| 167 | - * format, e.g. "2 hours", "1 day", "3 months" |
|
| 168 | - * |
|
| 169 | - * If you set the date to parameter, the difference |
|
| 170 | - * will be calculated between the two dates and not |
|
| 171 | - * the current time. |
|
| 172 | - * |
|
| 173 | - * @param integer|\DateTime $datefrom |
|
| 174 | - * @param integer|\DateTime $dateto |
|
| 175 | - * @return string |
|
| 176 | - */ |
|
| 165 | + /** |
|
| 166 | + * Converts a timestamp into an easily understandable |
|
| 167 | + * format, e.g. "2 hours", "1 day", "3 months" |
|
| 168 | + * |
|
| 169 | + * If you set the date to parameter, the difference |
|
| 170 | + * will be calculated between the two dates and not |
|
| 171 | + * the current time. |
|
| 172 | + * |
|
| 173 | + * @param integer|\DateTime $datefrom |
|
| 174 | + * @param integer|\DateTime $dateto |
|
| 175 | + * @return string |
|
| 176 | + */ |
|
| 177 | 177 | public static function duration2string($datefrom, $dateto = -1) : string |
| 178 | 178 | { |
| 179 | - $converter = new ConvertHelper_DurationConverter(); |
|
| 179 | + $converter = new ConvertHelper_DurationConverter(); |
|
| 180 | 180 | |
| 181 | - if($datefrom instanceof \DateTime) |
|
| 182 | - { |
|
| 183 | - $converter->setDateFrom($datefrom); |
|
| 184 | - } |
|
| 185 | - else |
|
| 186 | - { |
|
| 187 | - $converter->setDateFrom(self::timestamp2date($datefrom)); |
|
| 188 | - } |
|
| 181 | + if($datefrom instanceof \DateTime) |
|
| 182 | + { |
|
| 183 | + $converter->setDateFrom($datefrom); |
|
| 184 | + } |
|
| 185 | + else |
|
| 186 | + { |
|
| 187 | + $converter->setDateFrom(self::timestamp2date($datefrom)); |
|
| 188 | + } |
|
| 189 | 189 | |
| 190 | - if($dateto instanceof \DateTime) |
|
| 191 | - { |
|
| 192 | - $converter->setDateTo($dateto); |
|
| 193 | - } |
|
| 194 | - else if($dateto > 0) |
|
| 195 | - { |
|
| 196 | - $converter->setDateTo(self::timestamp2date($dateto)); |
|
| 197 | - } |
|
| 190 | + if($dateto instanceof \DateTime) |
|
| 191 | + { |
|
| 192 | + $converter->setDateTo($dateto); |
|
| 193 | + } |
|
| 194 | + else if($dateto > 0) |
|
| 195 | + { |
|
| 196 | + $converter->setDateTo(self::timestamp2date($dateto)); |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return $converter->convert(); |
|
| 199 | + return $converter->convert(); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -269,16 +269,16 @@ discard block |
||
| 269 | 269 | return $bytes . ' ' . t('B'); |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - /** |
|
| 273 | - * Cuts a text to the specified length if it is longer than the |
|
| 274 | - * target length. Appends a text to signify it has been cut at |
|
| 275 | - * the end of the string. |
|
| 276 | - * |
|
| 277 | - * @param string $text |
|
| 278 | - * @param int $targetLength |
|
| 279 | - * @param string $append |
|
| 280 | - * @return string |
|
| 281 | - */ |
|
| 272 | + /** |
|
| 273 | + * Cuts a text to the specified length if it is longer than the |
|
| 274 | + * target length. Appends a text to signify it has been cut at |
|
| 275 | + * the end of the string. |
|
| 276 | + * |
|
| 277 | + * @param string $text |
|
| 278 | + * @param int $targetLength |
|
| 279 | + * @param string $append |
|
| 280 | + * @return string |
|
| 281 | + */ |
|
| 282 | 282 | public static function text_cut(string $text, int $targetLength, string $append = '...') : string |
| 283 | 283 | { |
| 284 | 284 | $length = mb_strlen($text); |
@@ -348,27 +348,27 @@ discard block |
||
| 348 | 348 | return self::$booleanStrings[$string]; |
| 349 | 349 | } |
| 350 | 350 | |
| 351 | - /** |
|
| 352 | - * Whether the specified string is a boolean string or boolean value. |
|
| 353 | - * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 354 | - * |
|
| 355 | - * @param mixed $string |
|
| 356 | - * @return bool |
|
| 357 | - * @deprecated |
|
| 358 | - * @see ConvertHelper::isBoolean() |
|
| 359 | - */ |
|
| 351 | + /** |
|
| 352 | + * Whether the specified string is a boolean string or boolean value. |
|
| 353 | + * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 354 | + * |
|
| 355 | + * @param mixed $string |
|
| 356 | + * @return bool |
|
| 357 | + * @deprecated |
|
| 358 | + * @see ConvertHelper::isBoolean() |
|
| 359 | + */ |
|
| 360 | 360 | public static function isBooleanString($string) : bool |
| 361 | 361 | { |
| 362 | 362 | return self::isBoolean($string); |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - /** |
|
| 366 | - * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
| 367 | - * |
|
| 368 | - * @param string $text |
|
| 369 | - * @return string |
|
| 370 | - * @deprecated |
|
| 371 | - */ |
|
| 365 | + /** |
|
| 366 | + * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
| 367 | + * |
|
| 368 | + * @param string $text |
|
| 369 | + * @return string |
|
| 370 | + * @deprecated |
|
| 371 | + */ |
|
| 372 | 372 | public static function text_makeXMLCompliant($text) |
| 373 | 373 | { |
| 374 | 374 | return XMLHelper::string2xml($text); |
@@ -470,13 +470,13 @@ discard block |
||
| 470 | 470 | return $translit->convert($string); |
| 471 | 471 | } |
| 472 | 472 | |
| 473 | - /** |
|
| 474 | - * Retrieves the HEX character codes for all control |
|
| 475 | - * characters that the {@link stripControlCharacters()} |
|
| 476 | - * method will remove. |
|
| 477 | - * |
|
| 478 | - * @return string[] |
|
| 479 | - */ |
|
| 473 | + /** |
|
| 474 | + * Retrieves the HEX character codes for all control |
|
| 475 | + * characters that the {@link stripControlCharacters()} |
|
| 476 | + * method will remove. |
|
| 477 | + * |
|
| 478 | + * @return string[] |
|
| 479 | + */ |
|
| 480 | 480 | public static function getControlCharactersAsHex() |
| 481 | 481 | { |
| 482 | 482 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
@@ -512,13 +512,13 @@ discard block |
||
| 512 | 512 | return $stack; |
| 513 | 513 | } |
| 514 | 514 | |
| 515 | - /** |
|
| 516 | - * Retrieves an array of all control characters that |
|
| 517 | - * the {@link stripControlCharacters()} method will |
|
| 518 | - * remove, as the actual UTF-8 characters. |
|
| 519 | - * |
|
| 520 | - * @return string[] |
|
| 521 | - */ |
|
| 515 | + /** |
|
| 516 | + * Retrieves an array of all control characters that |
|
| 517 | + * the {@link stripControlCharacters()} method will |
|
| 518 | + * remove, as the actual UTF-8 characters. |
|
| 519 | + * |
|
| 520 | + * @return string[] |
|
| 521 | + */ |
|
| 522 | 522 | public static function getControlCharactersAsUTF8() |
| 523 | 523 | { |
| 524 | 524 | $chars = self::getControlCharactersAsHex(); |
@@ -531,12 +531,12 @@ discard block |
||
| 531 | 531 | return $result; |
| 532 | 532 | } |
| 533 | 533 | |
| 534 | - /** |
|
| 535 | - * Retrieves all control characters as JSON encoded |
|
| 536 | - * characters, e.g. "\u200b". |
|
| 537 | - * |
|
| 538 | - * @return string[] |
|
| 539 | - */ |
|
| 534 | + /** |
|
| 535 | + * Retrieves all control characters as JSON encoded |
|
| 536 | + * characters, e.g. "\u200b". |
|
| 537 | + * |
|
| 538 | + * @return string[] |
|
| 539 | + */ |
|
| 540 | 540 | public static function getControlCharactersAsJSON() |
| 541 | 541 | { |
| 542 | 542 | $chars = self::getControlCharactersAsHex(); |
@@ -593,20 +593,20 @@ discard block |
||
| 593 | 593 | return preg_replace(self::$controlCharsRegex, '', $string); |
| 594 | 594 | } |
| 595 | 595 | |
| 596 | - /** |
|
| 597 | - * Converts a unicode character to the PHPO notation. |
|
| 598 | - * |
|
| 599 | - * Example: |
|
| 600 | - * |
|
| 601 | - * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 602 | - * |
|
| 603 | - * Returns |
|
| 604 | - * |
|
| 605 | - * <pre>\x0</pre> |
|
| 606 | - * |
|
| 607 | - * @param string $unicodeChar |
|
| 608 | - * @return string |
|
| 609 | - */ |
|
| 596 | + /** |
|
| 597 | + * Converts a unicode character to the PHPO notation. |
|
| 598 | + * |
|
| 599 | + * Example: |
|
| 600 | + * |
|
| 601 | + * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 602 | + * |
|
| 603 | + * Returns |
|
| 604 | + * |
|
| 605 | + * <pre>\x0</pre> |
|
| 606 | + * |
|
| 607 | + * @param string $unicodeChar |
|
| 608 | + * @return string |
|
| 609 | + */ |
|
| 610 | 610 | public static function unicodeChar2php($unicodeChar) |
| 611 | 611 | { |
| 612 | 612 | $unicodeChar = json_decode($unicodeChar); |
@@ -729,25 +729,25 @@ discard block |
||
| 729 | 729 | return 'false'; |
| 730 | 730 | } |
| 731 | 731 | |
| 732 | - /** |
|
| 733 | - * Converts an associative array with attribute name > value pairs |
|
| 734 | - * to an attribute string that can be used in an HTML tag. Empty |
|
| 735 | - * attribute values are ignored. |
|
| 736 | - * |
|
| 737 | - * Example: |
|
| 738 | - * |
|
| 739 | - * array2attributeString(array( |
|
| 740 | - * 'id' => 45, |
|
| 741 | - * 'href' => 'http://www.mistralys.com' |
|
| 742 | - * )); |
|
| 743 | - * |
|
| 744 | - * Result: |
|
| 745 | - * |
|
| 746 | - * id="45" href="http://www.mistralys.com" |
|
| 747 | - * |
|
| 748 | - * @param array $array |
|
| 749 | - * @return string |
|
| 750 | - */ |
|
| 732 | + /** |
|
| 733 | + * Converts an associative array with attribute name > value pairs |
|
| 734 | + * to an attribute string that can be used in an HTML tag. Empty |
|
| 735 | + * attribute values are ignored. |
|
| 736 | + * |
|
| 737 | + * Example: |
|
| 738 | + * |
|
| 739 | + * array2attributeString(array( |
|
| 740 | + * 'id' => 45, |
|
| 741 | + * 'href' => 'http://www.mistralys.com' |
|
| 742 | + * )); |
|
| 743 | + * |
|
| 744 | + * Result: |
|
| 745 | + * |
|
| 746 | + * id="45" href="http://www.mistralys.com" |
|
| 747 | + * |
|
| 748 | + * @param array $array |
|
| 749 | + * @return string |
|
| 750 | + */ |
|
| 751 | 751 | public static function array2attributeString($array) |
| 752 | 752 | { |
| 753 | 753 | $tokens = array(); |
@@ -766,14 +766,14 @@ discard block |
||
| 766 | 766 | return ' '.implode(' ', $tokens); |
| 767 | 767 | } |
| 768 | 768 | |
| 769 | - /** |
|
| 770 | - * Converts a string so it can safely be used in a javascript |
|
| 771 | - * statement in an HTML tag: uses single quotes around the string |
|
| 772 | - * and encodes all special characters as needed. |
|
| 773 | - * |
|
| 774 | - * @param string $string |
|
| 775 | - * @return string |
|
| 776 | - */ |
|
| 769 | + /** |
|
| 770 | + * Converts a string so it can safely be used in a javascript |
|
| 771 | + * statement in an HTML tag: uses single quotes around the string |
|
| 772 | + * and encodes all special characters as needed. |
|
| 773 | + * |
|
| 774 | + * @param string $string |
|
| 775 | + * @return string |
|
| 776 | + */ |
|
| 777 | 777 | public static function string2attributeJS($string, $quoted=true) |
| 778 | 778 | { |
| 779 | 779 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
@@ -784,15 +784,15 @@ discard block |
||
| 784 | 784 | return $converted; |
| 785 | 785 | } |
| 786 | 786 | |
| 787 | - /** |
|
| 788 | - * Checks if the specified string is a boolean value, which |
|
| 789 | - * includes string representations of boolean values, like |
|
| 790 | - * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 791 | - * or <code>false</code>. |
|
| 792 | - * |
|
| 793 | - * @param mixed $value |
|
| 794 | - * @return boolean |
|
| 795 | - */ |
|
| 787 | + /** |
|
| 788 | + * Checks if the specified string is a boolean value, which |
|
| 789 | + * includes string representations of boolean values, like |
|
| 790 | + * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 791 | + * or <code>false</code>. |
|
| 792 | + * |
|
| 793 | + * @param mixed $value |
|
| 794 | + * @return boolean |
|
| 795 | + */ |
|
| 796 | 796 | public static function isBoolean($value) : bool |
| 797 | 797 | { |
| 798 | 798 | if(is_bool($value)) { |
@@ -806,12 +806,12 @@ discard block |
||
| 806 | 806 | return array_key_exists($value, self::$booleanStrings); |
| 807 | 807 | } |
| 808 | 808 | |
| 809 | - /** |
|
| 810 | - * Converts an associative array to an HTML style attribute value string. |
|
| 811 | - * |
|
| 812 | - * @param array $subject |
|
| 813 | - * @return string |
|
| 814 | - */ |
|
| 809 | + /** |
|
| 810 | + * Converts an associative array to an HTML style attribute value string. |
|
| 811 | + * |
|
| 812 | + * @param array $subject |
|
| 813 | + * @return string |
|
| 814 | + */ |
|
| 815 | 815 | public static function array2styleString(array $subject) : string |
| 816 | 816 | { |
| 817 | 817 | $tokens = array(); |
@@ -822,23 +822,23 @@ discard block |
||
| 822 | 822 | return implode(';', $tokens); |
| 823 | 823 | } |
| 824 | 824 | |
| 825 | - /** |
|
| 826 | - * Converts a DateTime object to a timestamp, which |
|
| 827 | - * is PHP 5.2 compatible. |
|
| 828 | - * |
|
| 829 | - * @param \DateTime $date |
|
| 830 | - * @return integer |
|
| 831 | - */ |
|
| 825 | + /** |
|
| 826 | + * Converts a DateTime object to a timestamp, which |
|
| 827 | + * is PHP 5.2 compatible. |
|
| 828 | + * |
|
| 829 | + * @param \DateTime $date |
|
| 830 | + * @return integer |
|
| 831 | + */ |
|
| 832 | 832 | public static function date2timestamp(\DateTime $date) : int |
| 833 | 833 | { |
| 834 | 834 | return (int)$date->format('U'); |
| 835 | 835 | } |
| 836 | 836 | |
| 837 | - /** |
|
| 838 | - * Converts a timestamp into a DateTime instance. |
|
| 839 | - * @param int $timestamp |
|
| 840 | - * @return \DateTime |
|
| 841 | - */ |
|
| 837 | + /** |
|
| 838 | + * Converts a timestamp into a DateTime instance. |
|
| 839 | + * @param int $timestamp |
|
| 840 | + * @return \DateTime |
|
| 841 | + */ |
|
| 842 | 842 | public static function timestamp2date(int $timestamp) : \DateTime |
| 843 | 843 | { |
| 844 | 844 | $date = new \DateTime(); |
@@ -846,50 +846,50 @@ discard block |
||
| 846 | 846 | return $date; |
| 847 | 847 | } |
| 848 | 848 | |
| 849 | - /** |
|
| 850 | - * Strips an absolute path to a file within the application |
|
| 851 | - * to make the path relative to the application root path. |
|
| 852 | - * |
|
| 853 | - * @param string $path |
|
| 854 | - * @return string |
|
| 855 | - * |
|
| 856 | - * @see FileHelper::relativizePath() |
|
| 857 | - * @see FileHelper::relativizePathByDepth() |
|
| 858 | - */ |
|
| 849 | + /** |
|
| 850 | + * Strips an absolute path to a file within the application |
|
| 851 | + * to make the path relative to the application root path. |
|
| 852 | + * |
|
| 853 | + * @param string $path |
|
| 854 | + * @return string |
|
| 855 | + * |
|
| 856 | + * @see FileHelper::relativizePath() |
|
| 857 | + * @see FileHelper::relativizePathByDepth() |
|
| 858 | + */ |
|
| 859 | 859 | public static function fileRelativize(string $path) : string |
| 860 | 860 | { |
| 861 | 861 | return FileHelper::relativizePathByDepth($path); |
| 862 | 862 | } |
| 863 | 863 | |
| 864 | 864 | /** |
| 865 | - * Converts a PHP regex to a javascript RegExp object statement. |
|
| 866 | - * |
|
| 867 | - * NOTE: This is an alias for the JSHelper's `convertRegex` method. |
|
| 868 | - * More details are available on its usage there. |
|
| 869 | - * |
|
| 870 | - * @param string $regex A PHP preg regex |
|
| 871 | - * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object. |
|
| 872 | - * @return array|string Depending on the specified return type. |
|
| 873 | - * |
|
| 874 | - * @see JSHelper::buildRegexStatement() |
|
| 875 | - */ |
|
| 865 | + * Converts a PHP regex to a javascript RegExp object statement. |
|
| 866 | + * |
|
| 867 | + * NOTE: This is an alias for the JSHelper's `convertRegex` method. |
|
| 868 | + * More details are available on its usage there. |
|
| 869 | + * |
|
| 870 | + * @param string $regex A PHP preg regex |
|
| 871 | + * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object. |
|
| 872 | + * @return array|string Depending on the specified return type. |
|
| 873 | + * |
|
| 874 | + * @see JSHelper::buildRegexStatement() |
|
| 875 | + */ |
|
| 876 | 876 | public static function regex2js(string $regex, string $statementType=JSHelper::JS_REGEX_OBJECT) |
| 877 | 877 | { |
| 878 | 878 | return JSHelper::buildRegexStatement($regex, $statementType); |
| 879 | 879 | } |
| 880 | 880 | |
| 881 | - /** |
|
| 882 | - * Converts the specified variable to JSON. Works just |
|
| 883 | - * like the native `json_encode` method, except that it |
|
| 884 | - * will trigger an exception on failure, which has the |
|
| 885 | - * json error details included in its developer details. |
|
| 886 | - * |
|
| 887 | - * @param mixed $variable |
|
| 888 | - * @param int|NULL $options JSON encode options. |
|
| 889 | - * @param int|NULL $depth |
|
| 890 | - * @throws ConvertHelper_Exception |
|
| 891 | - * @return string |
|
| 892 | - */ |
|
| 881 | + /** |
|
| 882 | + * Converts the specified variable to JSON. Works just |
|
| 883 | + * like the native `json_encode` method, except that it |
|
| 884 | + * will trigger an exception on failure, which has the |
|
| 885 | + * json error details included in its developer details. |
|
| 886 | + * |
|
| 887 | + * @param mixed $variable |
|
| 888 | + * @param int|NULL $options JSON encode options. |
|
| 889 | + * @param int|NULL $depth |
|
| 890 | + * @throws ConvertHelper_Exception |
|
| 891 | + * @return string |
|
| 892 | + */ |
|
| 893 | 893 | public static function var2json($variable, int $options=0, int $depth=512) : string |
| 894 | 894 | { |
| 895 | 895 | $result = json_encode($variable, $options, $depth); |
@@ -910,12 +910,12 @@ discard block |
||
| 910 | 910 | ); |
| 911 | 911 | } |
| 912 | 912 | |
| 913 | - /** |
|
| 914 | - * Strips all known UTF byte order marks from the specified string. |
|
| 915 | - * |
|
| 916 | - * @param string $string |
|
| 917 | - * @return string |
|
| 918 | - */ |
|
| 913 | + /** |
|
| 914 | + * Strips all known UTF byte order marks from the specified string. |
|
| 915 | + * |
|
| 916 | + * @param string $string |
|
| 917 | + * @return string |
|
| 918 | + */ |
|
| 919 | 919 | public static function stripUTFBom($string) |
| 920 | 920 | { |
| 921 | 921 | $boms = FileHelper::getUTFBOMs(); |
@@ -930,13 +930,13 @@ discard block |
||
| 930 | 930 | return $string; |
| 931 | 931 | } |
| 932 | 932 | |
| 933 | - /** |
|
| 934 | - * Converts a string to valid utf8, regardless |
|
| 935 | - * of the string's encoding(s). |
|
| 936 | - * |
|
| 937 | - * @param string $string |
|
| 938 | - * @return string |
|
| 939 | - */ |
|
| 933 | + /** |
|
| 934 | + * Converts a string to valid utf8, regardless |
|
| 935 | + * of the string's encoding(s). |
|
| 936 | + * |
|
| 937 | + * @param string $string |
|
| 938 | + * @return string |
|
| 939 | + */ |
|
| 940 | 940 | public static function string2utf8($string) |
| 941 | 941 | { |
| 942 | 942 | if(!self::isStringASCII($string)) { |
@@ -946,15 +946,15 @@ discard block |
||
| 946 | 946 | return $string; |
| 947 | 947 | } |
| 948 | 948 | |
| 949 | - /** |
|
| 950 | - * Checks whether the specified string is an ASCII |
|
| 951 | - * string, without any special or UTF8 characters. |
|
| 952 | - * Note: empty strings and NULL are considered ASCII. |
|
| 953 | - * Any variable types other than strings are not. |
|
| 954 | - * |
|
| 955 | - * @param mixed $string |
|
| 956 | - * @return boolean |
|
| 957 | - */ |
|
| 949 | + /** |
|
| 950 | + * Checks whether the specified string is an ASCII |
|
| 951 | + * string, without any special or UTF8 characters. |
|
| 952 | + * Note: empty strings and NULL are considered ASCII. |
|
| 953 | + * Any variable types other than strings are not. |
|
| 954 | + * |
|
| 955 | + * @param mixed $string |
|
| 956 | + * @return boolean |
|
| 957 | + */ |
|
| 958 | 958 | public static function isStringASCII($string) : bool |
| 959 | 959 | { |
| 960 | 960 | if($string === '' || $string === NULL) { |
@@ -979,22 +979,22 @@ discard block |
||
| 979 | 979 | return $url; |
| 980 | 980 | } |
| 981 | 981 | |
| 982 | - /** |
|
| 983 | - * Calculates a percentage match of the source string with the target string. |
|
| 984 | - * |
|
| 985 | - * Options are: |
|
| 986 | - * |
|
| 987 | - * - maxLevenshtein, default: 10 |
|
| 988 | - * Any levenshtein results above this value are ignored. |
|
| 989 | - * |
|
| 990 | - * - precision, default: 1 |
|
| 991 | - * The precision of the percentage float value |
|
| 992 | - * |
|
| 993 | - * @param string $source |
|
| 994 | - * @param string $target |
|
| 995 | - * @param array $options |
|
| 996 | - * @return float |
|
| 997 | - */ |
|
| 982 | + /** |
|
| 983 | + * Calculates a percentage match of the source string with the target string. |
|
| 984 | + * |
|
| 985 | + * Options are: |
|
| 986 | + * |
|
| 987 | + * - maxLevenshtein, default: 10 |
|
| 988 | + * Any levenshtein results above this value are ignored. |
|
| 989 | + * |
|
| 990 | + * - precision, default: 1 |
|
| 991 | + * The precision of the percentage float value |
|
| 992 | + * |
|
| 993 | + * @param string $source |
|
| 994 | + * @param string $target |
|
| 995 | + * @param array $options |
|
| 996 | + * @return float |
|
| 997 | + */ |
|
| 998 | 998 | public static function matchString($source, $target, $options=array()) |
| 999 | 999 | { |
| 1000 | 1000 | $defaults = array( |
@@ -1078,60 +1078,60 @@ discard block |
||
| 1078 | 1078 | |
| 1079 | 1079 | const INTERVAL_SECONDS = 'seconds'; |
| 1080 | 1080 | |
| 1081 | - /** |
|
| 1082 | - * Converts an interval to its total amount of days. |
|
| 1083 | - * @param \DateInterval $interval |
|
| 1084 | - * @return int |
|
| 1085 | - */ |
|
| 1081 | + /** |
|
| 1082 | + * Converts an interval to its total amount of days. |
|
| 1083 | + * @param \DateInterval $interval |
|
| 1084 | + * @return int |
|
| 1085 | + */ |
|
| 1086 | 1086 | public static function interval2days(\DateInterval $interval) : int |
| 1087 | 1087 | { |
| 1088 | 1088 | return self::interval2total($interval, self::INTERVAL_DAYS); |
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | - /** |
|
| 1092 | - * Converts an interval to its total amount of hours. |
|
| 1093 | - * @param \DateInterval $interval |
|
| 1094 | - * @return int |
|
| 1095 | - */ |
|
| 1091 | + /** |
|
| 1092 | + * Converts an interval to its total amount of hours. |
|
| 1093 | + * @param \DateInterval $interval |
|
| 1094 | + * @return int |
|
| 1095 | + */ |
|
| 1096 | 1096 | public static function interval2hours(\DateInterval $interval) : int |
| 1097 | 1097 | { |
| 1098 | 1098 | return self::interval2total($interval, self::INTERVAL_HOURS); |
| 1099 | 1099 | } |
| 1100 | 1100 | |
| 1101 | - /** |
|
| 1102 | - * Converts an interval to its total amount of minutes. |
|
| 1103 | - * @param \DateInterval $interval |
|
| 1104 | - * @return int |
|
| 1105 | - */ |
|
| 1101 | + /** |
|
| 1102 | + * Converts an interval to its total amount of minutes. |
|
| 1103 | + * @param \DateInterval $interval |
|
| 1104 | + * @return int |
|
| 1105 | + */ |
|
| 1106 | 1106 | public static function interval2minutes(\DateInterval $interval) : int |
| 1107 | 1107 | { |
| 1108 | 1108 | return self::interval2total($interval, self::INTERVAL_MINUTES); |
| 1109 | 1109 | } |
| 1110 | 1110 | |
| 1111 | - /** |
|
| 1112 | - * Converts an interval to its total amount of seconds. |
|
| 1113 | - * @param \DateInterval $interval |
|
| 1114 | - * @return int |
|
| 1115 | - */ |
|
| 1111 | + /** |
|
| 1112 | + * Converts an interval to its total amount of seconds. |
|
| 1113 | + * @param \DateInterval $interval |
|
| 1114 | + * @return int |
|
| 1115 | + */ |
|
| 1116 | 1116 | public static function interval2seconds(\DateInterval $interval) : int |
| 1117 | 1117 | { |
| 1118 | 1118 | return self::interval2total($interval, self::INTERVAL_SECONDS); |
| 1119 | 1119 | } |
| 1120 | 1120 | |
| 1121 | - /** |
|
| 1122 | - * Calculates the total amount of days / hours / minutes or seconds |
|
| 1123 | - * of a date interval object (depending in the specified units), and |
|
| 1124 | - * returns the total amount. |
|
| 1125 | - * |
|
| 1126 | - * @param \DateInterval $interval |
|
| 1127 | - * @param string $unit What total value to calculate. |
|
| 1128 | - * @return integer |
|
| 1129 | - * |
|
| 1130 | - * @see ConvertHelper::INTERVAL_SECONDS |
|
| 1131 | - * @see ConvertHelper::INTERVAL_MINUTES |
|
| 1132 | - * @see ConvertHelper::INTERVAL_HOURS |
|
| 1133 | - * @see ConvertHelper::INTERVAL_DAYS |
|
| 1134 | - */ |
|
| 1121 | + /** |
|
| 1122 | + * Calculates the total amount of days / hours / minutes or seconds |
|
| 1123 | + * of a date interval object (depending in the specified units), and |
|
| 1124 | + * returns the total amount. |
|
| 1125 | + * |
|
| 1126 | + * @param \DateInterval $interval |
|
| 1127 | + * @param string $unit What total value to calculate. |
|
| 1128 | + * @return integer |
|
| 1129 | + * |
|
| 1130 | + * @see ConvertHelper::INTERVAL_SECONDS |
|
| 1131 | + * @see ConvertHelper::INTERVAL_MINUTES |
|
| 1132 | + * @see ConvertHelper::INTERVAL_HOURS |
|
| 1133 | + * @see ConvertHelper::INTERVAL_DAYS |
|
| 1134 | + */ |
|
| 1135 | 1135 | public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) : int |
| 1136 | 1136 | { |
| 1137 | 1137 | $total = $interval->format('%a'); |
@@ -1171,13 +1171,13 @@ discard block |
||
| 1171 | 1171 | 'Sunday' |
| 1172 | 1172 | ); |
| 1173 | 1173 | |
| 1174 | - /** |
|
| 1175 | - * Converts a date to the corresponding day name. |
|
| 1176 | - * |
|
| 1177 | - * @param \DateTime $date |
|
| 1178 | - * @param string $short |
|
| 1179 | - * @return string|NULL |
|
| 1180 | - */ |
|
| 1174 | + /** |
|
| 1175 | + * Converts a date to the corresponding day name. |
|
| 1176 | + * |
|
| 1177 | + * @param \DateTime $date |
|
| 1178 | + * @param string $short |
|
| 1179 | + * @return string|NULL |
|
| 1180 | + */ |
|
| 1181 | 1181 | public static function date2dayName(\DateTime $date, $short=false) |
| 1182 | 1182 | { |
| 1183 | 1183 | $day = $date->format('l'); |
@@ -1192,21 +1192,21 @@ discard block |
||
| 1192 | 1192 | return null; |
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | - /** |
|
| 1196 | - * Retrieves a list of english day names. |
|
| 1197 | - * @return string[] |
|
| 1198 | - */ |
|
| 1195 | + /** |
|
| 1196 | + * Retrieves a list of english day names. |
|
| 1197 | + * @return string[] |
|
| 1198 | + */ |
|
| 1199 | 1199 | public static function getDayNamesInvariant() |
| 1200 | 1200 | { |
| 1201 | 1201 | return self::$daysInvariant; |
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | - /** |
|
| 1205 | - * Retrieves the day names list for the current locale. |
|
| 1206 | - * |
|
| 1207 | - * @param string $short |
|
| 1208 | - * @return string[] |
|
| 1209 | - */ |
|
| 1204 | + /** |
|
| 1205 | + * Retrieves the day names list for the current locale. |
|
| 1206 | + * |
|
| 1207 | + * @param string $short |
|
| 1208 | + * @return string[] |
|
| 1209 | + */ |
|
| 1210 | 1210 | public static function getDayNames($short=false) |
| 1211 | 1211 | { |
| 1212 | 1212 | if($short) { |
@@ -1266,16 +1266,16 @@ discard block |
||
| 1266 | 1266 | return $last; |
| 1267 | 1267 | } |
| 1268 | 1268 | |
| 1269 | - /** |
|
| 1270 | - * Splits a string into an array of all characters it is composed of. |
|
| 1271 | - * Unicode character safe. |
|
| 1272 | - * |
|
| 1273 | - * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
| 1274 | - * characters. |
|
| 1275 | - * |
|
| 1276 | - * @param string $string |
|
| 1277 | - * @return array |
|
| 1278 | - */ |
|
| 1269 | + /** |
|
| 1270 | + * Splits a string into an array of all characters it is composed of. |
|
| 1271 | + * Unicode character safe. |
|
| 1272 | + * |
|
| 1273 | + * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
| 1274 | + * characters. |
|
| 1275 | + * |
|
| 1276 | + * @param string $string |
|
| 1277 | + * @return array |
|
| 1278 | + */ |
|
| 1279 | 1279 | public static function string2array(string $string) : array |
| 1280 | 1280 | { |
| 1281 | 1281 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
@@ -1286,12 +1286,12 @@ discard block |
||
| 1286 | 1286 | return array(); |
| 1287 | 1287 | } |
| 1288 | 1288 | |
| 1289 | - /** |
|
| 1290 | - * Checks whether the specified string contains HTML code. |
|
| 1291 | - * |
|
| 1292 | - * @param string $string |
|
| 1293 | - * @return boolean |
|
| 1294 | - */ |
|
| 1289 | + /** |
|
| 1290 | + * Checks whether the specified string contains HTML code. |
|
| 1291 | + * |
|
| 1292 | + * @param string $string |
|
| 1293 | + * @return boolean |
|
| 1294 | + */ |
|
| 1295 | 1295 | public static function isStringHTML(string $string) : bool |
| 1296 | 1296 | { |
| 1297 | 1297 | if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
@@ -1306,17 +1306,17 @@ discard block |
||
| 1306 | 1306 | return false; |
| 1307 | 1307 | } |
| 1308 | 1308 | |
| 1309 | - /** |
|
| 1310 | - * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 1311 | - * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 1312 | - * are not calculated correctly. |
|
| 1313 | - * |
|
| 1314 | - * @param string $str |
|
| 1315 | - * @param int $width |
|
| 1316 | - * @param string $break |
|
| 1317 | - * @param bool $cut |
|
| 1318 | - * @return string |
|
| 1319 | - */ |
|
| 1309 | + /** |
|
| 1310 | + * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 1311 | + * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 1312 | + * are not calculated correctly. |
|
| 1313 | + * |
|
| 1314 | + * @param string $str |
|
| 1315 | + * @param int $width |
|
| 1316 | + * @param string $break |
|
| 1317 | + * @param bool $cut |
|
| 1318 | + * @return string |
|
| 1319 | + */ |
|
| 1320 | 1320 | public static function wordwrap(string $str, int $width = 75, string $break = "\n", bool $cut = false) : string |
| 1321 | 1321 | { |
| 1322 | 1322 | $wrapper = new ConvertHelper_WordWrapper(); |
@@ -1328,27 +1328,27 @@ discard block |
||
| 1328 | 1328 | ->wrapText($str); |
| 1329 | 1329 | } |
| 1330 | 1330 | |
| 1331 | - /** |
|
| 1332 | - * Calculates the byte length of a string, taking into |
|
| 1333 | - * account any unicode characters. |
|
| 1334 | - * |
|
| 1335 | - * @param string $string |
|
| 1336 | - * @return int |
|
| 1337 | - * @see https://stackoverflow.com/a/9718273/2298192 |
|
| 1338 | - */ |
|
| 1331 | + /** |
|
| 1332 | + * Calculates the byte length of a string, taking into |
|
| 1333 | + * account any unicode characters. |
|
| 1334 | + * |
|
| 1335 | + * @param string $string |
|
| 1336 | + * @return int |
|
| 1337 | + * @see https://stackoverflow.com/a/9718273/2298192 |
|
| 1338 | + */ |
|
| 1339 | 1339 | public static function string2bytes($string) |
| 1340 | 1340 | { |
| 1341 | 1341 | return mb_strlen($string, '8bit'); |
| 1342 | 1342 | } |
| 1343 | 1343 | |
| 1344 | - /** |
|
| 1345 | - * Creates a short, 8-character long hash for the specified string. |
|
| 1346 | - * |
|
| 1347 | - * WARNING: Not cryptographically safe. |
|
| 1348 | - * |
|
| 1349 | - * @param string $string |
|
| 1350 | - * @return string |
|
| 1351 | - */ |
|
| 1344 | + /** |
|
| 1345 | + * Creates a short, 8-character long hash for the specified string. |
|
| 1346 | + * |
|
| 1347 | + * WARNING: Not cryptographically safe. |
|
| 1348 | + * |
|
| 1349 | + * @param string $string |
|
| 1350 | + * @return string |
|
| 1351 | + */ |
|
| 1352 | 1352 | public static function string2shortHash($string) |
| 1353 | 1353 | { |
| 1354 | 1354 | return hash('crc32', $string, false); |
@@ -1374,40 +1374,40 @@ discard block |
||
| 1374 | 1374 | return ConvertHelper_ThrowableInfo::fromThrowable($e); |
| 1375 | 1375 | } |
| 1376 | 1376 | |
| 1377 | - /** |
|
| 1378 | - * Parses the specified query string like the native |
|
| 1379 | - * function <code>parse_str</code>, without the key |
|
| 1380 | - * naming limitations. |
|
| 1381 | - * |
|
| 1382 | - * Using parse_str, dots or spaces in key names are |
|
| 1383 | - * replaced by underscores. This method keeps all names |
|
| 1384 | - * intact. |
|
| 1385 | - * |
|
| 1386 | - * It still uses the parse_str implementation as it |
|
| 1387 | - * is tested and tried, but fixes the parameter names |
|
| 1388 | - * after parsing, as needed. |
|
| 1389 | - * |
|
| 1390 | - * @param string $queryString |
|
| 1391 | - * @return array |
|
| 1392 | - * @see ConvertHelper_QueryParser |
|
| 1393 | - */ |
|
| 1377 | + /** |
|
| 1378 | + * Parses the specified query string like the native |
|
| 1379 | + * function <code>parse_str</code>, without the key |
|
| 1380 | + * naming limitations. |
|
| 1381 | + * |
|
| 1382 | + * Using parse_str, dots or spaces in key names are |
|
| 1383 | + * replaced by underscores. This method keeps all names |
|
| 1384 | + * intact. |
|
| 1385 | + * |
|
| 1386 | + * It still uses the parse_str implementation as it |
|
| 1387 | + * is tested and tried, but fixes the parameter names |
|
| 1388 | + * after parsing, as needed. |
|
| 1389 | + * |
|
| 1390 | + * @param string $queryString |
|
| 1391 | + * @return array |
|
| 1392 | + * @see ConvertHelper_QueryParser |
|
| 1393 | + */ |
|
| 1394 | 1394 | public static function parseQueryString(string $queryString) : array |
| 1395 | 1395 | { |
| 1396 | 1396 | $parser = new ConvertHelper_QueryParser(); |
| 1397 | 1397 | return $parser->parse($queryString); |
| 1398 | 1398 | } |
| 1399 | 1399 | |
| 1400 | - /** |
|
| 1401 | - * Searches for needle in the specified string, and returns a list |
|
| 1402 | - * of all occurrences, including the matched string. The matched |
|
| 1403 | - * string is useful when doing a case insensitive search, as it |
|
| 1404 | - * shows the exact matched case of needle. |
|
| 1405 | - * |
|
| 1406 | - * @param string $needle |
|
| 1407 | - * @param string $haystack |
|
| 1408 | - * @param bool $caseInsensitive |
|
| 1409 | - * @return ConvertHelper_StringMatch[] |
|
| 1410 | - */ |
|
| 1400 | + /** |
|
| 1401 | + * Searches for needle in the specified string, and returns a list |
|
| 1402 | + * of all occurrences, including the matched string. The matched |
|
| 1403 | + * string is useful when doing a case insensitive search, as it |
|
| 1404 | + * shows the exact matched case of needle. |
|
| 1405 | + * |
|
| 1406 | + * @param string $needle |
|
| 1407 | + * @param string $haystack |
|
| 1408 | + * @param bool $caseInsensitive |
|
| 1409 | + * @return ConvertHelper_StringMatch[] |
|
| 1410 | + */ |
|
| 1411 | 1411 | public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
| 1412 | 1412 | { |
| 1413 | 1413 | if($needle === '') { |
@@ -1433,14 +1433,14 @@ discard block |
||
| 1433 | 1433 | return $positions; |
| 1434 | 1434 | } |
| 1435 | 1435 | |
| 1436 | - /** |
|
| 1437 | - * Like explode, but trims all entries, and removes |
|
| 1438 | - * empty entries from the resulting array. |
|
| 1439 | - * |
|
| 1440 | - * @param string $delimiter |
|
| 1441 | - * @param string $string |
|
| 1442 | - * @return string[] |
|
| 1443 | - */ |
|
| 1436 | + /** |
|
| 1437 | + * Like explode, but trims all entries, and removes |
|
| 1438 | + * empty entries from the resulting array. |
|
| 1439 | + * |
|
| 1440 | + * @param string $delimiter |
|
| 1441 | + * @param string $string |
|
| 1442 | + * @return string[] |
|
| 1443 | + */ |
|
| 1444 | 1444 | public static function explodeTrim(string $delimiter, string $string) : array |
| 1445 | 1445 | { |
| 1446 | 1446 | if(empty($string) || empty($delimiter)) { |
@@ -1462,12 +1462,12 @@ discard block |
||
| 1462 | 1462 | |
| 1463 | 1463 | protected static $eolChars; |
| 1464 | 1464 | |
| 1465 | - /** |
|
| 1466 | - * Detects the most used end-of-line character in the subject string. |
|
| 1467 | - * |
|
| 1468 | - * @param string $str The string to check. |
|
| 1469 | - * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1470 | - */ |
|
| 1465 | + /** |
|
| 1466 | + * Detects the most used end-of-line character in the subject string. |
|
| 1467 | + * |
|
| 1468 | + * @param string $str The string to check. |
|
| 1469 | + * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1470 | + */ |
|
| 1471 | 1471 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
| 1472 | 1472 | { |
| 1473 | 1473 | if(empty($subjectString)) { |
@@ -1479,27 +1479,27 @@ discard block |
||
| 1479 | 1479 | $cr = chr((int)hexdec('0d')); |
| 1480 | 1480 | $lf = chr((int)hexdec('0a')); |
| 1481 | 1481 | |
| 1482 | - self::$eolChars = array( |
|
| 1483 | - array( |
|
| 1484 | - 'char' => $cr.$lf, |
|
| 1485 | - 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
| 1486 | - 'description' => t('Carriage return followed by a line feed'), |
|
| 1487 | - ), |
|
| 1488 | - array( |
|
| 1489 | - 'char' => $lf.$cr, |
|
| 1490 | - 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
| 1491 | - 'description' => t('Line feed followed by a carriage return'), |
|
| 1492 | - ), |
|
| 1493 | - array( |
|
| 1494 | - 'char' => $lf, |
|
| 1495 | - 'type' => ConvertHelper_EOL::TYPE_LF, |
|
| 1496 | - 'description' => t('Line feed'), |
|
| 1497 | - ), |
|
| 1498 | - array( |
|
| 1499 | - 'char' => $cr, |
|
| 1500 | - 'type' => ConvertHelper_EOL::TYPE_CR, |
|
| 1501 | - 'description' => t('Carriage Return'), |
|
| 1502 | - ), |
|
| 1482 | + self::$eolChars = array( |
|
| 1483 | + array( |
|
| 1484 | + 'char' => $cr.$lf, |
|
| 1485 | + 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
| 1486 | + 'description' => t('Carriage return followed by a line feed'), |
|
| 1487 | + ), |
|
| 1488 | + array( |
|
| 1489 | + 'char' => $lf.$cr, |
|
| 1490 | + 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
| 1491 | + 'description' => t('Line feed followed by a carriage return'), |
|
| 1492 | + ), |
|
| 1493 | + array( |
|
| 1494 | + 'char' => $lf, |
|
| 1495 | + 'type' => ConvertHelper_EOL::TYPE_LF, |
|
| 1496 | + 'description' => t('Line feed'), |
|
| 1497 | + ), |
|
| 1498 | + array( |
|
| 1499 | + 'char' => $cr, |
|
| 1500 | + 'type' => ConvertHelper_EOL::TYPE_CR, |
|
| 1501 | + 'description' => t('Carriage Return'), |
|
| 1502 | + ), |
|
| 1503 | 1503 | ); |
| 1504 | 1504 | } |
| 1505 | 1505 | |
@@ -1527,13 +1527,13 @@ discard block |
||
| 1527 | 1527 | ); |
| 1528 | 1528 | } |
| 1529 | 1529 | |
| 1530 | - /** |
|
| 1531 | - * Removes the specified keys from the target array, |
|
| 1532 | - * if they exist. |
|
| 1533 | - * |
|
| 1534 | - * @param array $array |
|
| 1535 | - * @param array $keys |
|
| 1536 | - */ |
|
| 1530 | + /** |
|
| 1531 | + * Removes the specified keys from the target array, |
|
| 1532 | + * if they exist. |
|
| 1533 | + * |
|
| 1534 | + * @param array $array |
|
| 1535 | + * @param array $keys |
|
| 1536 | + */ |
|
| 1537 | 1537 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
| 1538 | 1538 | { |
| 1539 | 1539 | foreach($keys as $key) |
@@ -1544,13 +1544,13 @@ discard block |
||
| 1544 | 1544 | } |
| 1545 | 1545 | } |
| 1546 | 1546 | |
| 1547 | - /** |
|
| 1548 | - * Checks if the specified variable is an integer or a string containing an integer. |
|
| 1549 | - * Accepts both positive and negative integers. |
|
| 1550 | - * |
|
| 1551 | - * @param mixed $value |
|
| 1552 | - * @return bool |
|
| 1553 | - */ |
|
| 1547 | + /** |
|
| 1548 | + * Checks if the specified variable is an integer or a string containing an integer. |
|
| 1549 | + * Accepts both positive and negative integers. |
|
| 1550 | + * |
|
| 1551 | + * @param mixed $value |
|
| 1552 | + * @return bool |
|
| 1553 | + */ |
|
| 1554 | 1554 | public static function isInteger($value) : bool |
| 1555 | 1555 | { |
| 1556 | 1556 | if(is_int($value)) { |
@@ -1570,15 +1570,15 @@ discard block |
||
| 1570 | 1570 | return false; |
| 1571 | 1571 | } |
| 1572 | 1572 | |
| 1573 | - /** |
|
| 1574 | - * Converts an amount of seconds to a DateInterval object. |
|
| 1575 | - * |
|
| 1576 | - * @param int $seconds |
|
| 1577 | - * @return \DateInterval |
|
| 1578 | - * @throws ConvertHelper_Exception If the date interval cannot be created. |
|
| 1579 | - * |
|
| 1580 | - * @see ConvertHelper::ERROR_CANNOT_GET_DATE_DIFF |
|
| 1581 | - */ |
|
| 1573 | + /** |
|
| 1574 | + * Converts an amount of seconds to a DateInterval object. |
|
| 1575 | + * |
|
| 1576 | + * @param int $seconds |
|
| 1577 | + * @return \DateInterval |
|
| 1578 | + * @throws ConvertHelper_Exception If the date interval cannot be created. |
|
| 1579 | + * |
|
| 1580 | + * @see ConvertHelper::ERROR_CANNOT_GET_DATE_DIFF |
|
| 1581 | + */ |
|
| 1582 | 1582 | public static function seconds2interval(int $seconds) : \DateInterval |
| 1583 | 1583 | { |
| 1584 | 1584 | // The DateInterval::format() method does not recalculate carry |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | $amount = substr_count($line, "\t") - $min; |
| 60 | 60 | $line = trim($line); |
| 61 | 61 | if ($amount >= 1) { |
| 62 | - $line = str_repeat("\t", $amount) . $line; |
|
| 62 | + $line = str_repeat("\t", $amount).$line; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | $converted[] = $line; |
@@ -131,10 +131,10 @@ discard block |
||
| 131 | 131 | |
| 132 | 132 | // specifically handle zero |
| 133 | 133 | if ($seconds <= 0) { |
| 134 | - return '0 ' . t('seconds'); |
|
| 134 | + return '0 '.t('seconds'); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if($seconds < 1) { |
|
| 137 | + if ($seconds < 1) { |
|
| 138 | 138 | return t('less than a second'); |
| 139 | 139 | } |
| 140 | 140 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | foreach ($units as $def) { |
| 143 | 143 | $quot = intval($seconds / $def['value']); |
| 144 | 144 | if ($quot) { |
| 145 | - $item = $quot . ' '; |
|
| 145 | + $item = $quot.' '; |
|
| 146 | 146 | if (abs($quot) > 1) { |
| 147 | 147 | $item .= $def['plural']; |
| 148 | 148 | } else { |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | return $last; |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
|
| 162 | + return implode(', ', $tokens).' '.t('and').' '.$last; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | { |
| 179 | 179 | $converter = new ConvertHelper_DurationConverter(); |
| 180 | 180 | |
| 181 | - if($datefrom instanceof \DateTime) |
|
| 181 | + if ($datefrom instanceof \DateTime) |
|
| 182 | 182 | { |
| 183 | 183 | $converter->setDateFrom($datefrom); |
| 184 | 184 | } |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | $converter->setDateFrom(self::timestamp2date($datefrom)); |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - if($dateto instanceof \DateTime) |
|
| 190 | + if ($dateto instanceof \DateTime) |
|
| 191 | 191 | { |
| 192 | 192 | $converter->setDateTo($dateto); |
| 193 | 193 | } |
| 194 | - else if($dateto > 0) |
|
| 194 | + else if ($dateto > 0) |
|
| 195 | 195 | { |
| 196 | 196 | $converter->setDateTo(self::timestamp2date($dateto)); |
| 197 | 197 | } |
@@ -211,9 +211,9 @@ discard block |
||
| 211 | 211 | return $geshi->parse_code(); |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - public static function highlight_xml($xml, $formatSource=false) |
|
| 214 | + public static function highlight_xml($xml, $formatSource = false) |
|
| 215 | 215 | { |
| 216 | - if($formatSource) |
|
| 216 | + if ($formatSource) |
|
| 217 | 217 | { |
| 218 | 218 | $dom = new \DOMDocument(); |
| 219 | 219 | $dom->loadXML($xml); |
@@ -251,22 +251,22 @@ discard block |
||
| 251 | 251 | $terabyte = $gigabyte * 1024; |
| 252 | 252 | |
| 253 | 253 | if (($bytes >= 0) && ($bytes < $kilobyte)) { |
| 254 | - return $bytes . ' ' . t('B'); |
|
| 254 | + return $bytes.' '.t('B'); |
|
| 255 | 255 | |
| 256 | 256 | } elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) { |
| 257 | - return round($bytes / $kilobyte, $precision) . ' ' . t('Kb'); |
|
| 257 | + return round($bytes / $kilobyte, $precision).' '.t('Kb'); |
|
| 258 | 258 | |
| 259 | 259 | } elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) { |
| 260 | - return round($bytes / $megabyte, $precision) . ' ' . t('Mb'); |
|
| 260 | + return round($bytes / $megabyte, $precision).' '.t('Mb'); |
|
| 261 | 261 | |
| 262 | 262 | } elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) { |
| 263 | - return round($bytes / $gigabyte, $precision) . ' ' . t('Gb'); |
|
| 263 | + return round($bytes / $gigabyte, $precision).' '.t('Gb'); |
|
| 264 | 264 | |
| 265 | 265 | } elseif ($bytes >= $terabyte) { |
| 266 | - return round($bytes / $gigabyte, $precision) . ' ' . t('Tb'); |
|
| 266 | + return round($bytes / $gigabyte, $precision).' '.t('Tb'); |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - return $bytes . ' ' . t('B'); |
|
| 269 | + return $bytes.' '.t('B'); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -286,34 +286,34 @@ discard block |
||
| 286 | 286 | return $text; |
| 287 | 287 | } |
| 288 | 288 | |
| 289 | - $text = trim(mb_substr($text, 0, $targetLength)) . $append; |
|
| 289 | + $text = trim(mb_substr($text, 0, $targetLength)).$append; |
|
| 290 | 290 | |
| 291 | 291 | return $text; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - public static function var_dump($var, $html=true) |
|
| 294 | + public static function var_dump($var, $html = true) |
|
| 295 | 295 | { |
| 296 | 296 | $info = parseVariable($var); |
| 297 | 297 | |
| 298 | - if($html) { |
|
| 298 | + if ($html) { |
|
| 299 | 299 | return $info->toHTML(); |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | return $info->toString(); |
| 303 | 303 | } |
| 304 | 304 | |
| 305 | - public static function print_r($var, $return=false, $html=true) |
|
| 305 | + public static function print_r($var, $return = false, $html = true) |
|
| 306 | 306 | { |
| 307 | 307 | $result = self::var_dump($var, $html); |
| 308 | 308 | |
| 309 | - if($html) { |
|
| 309 | + if ($html) { |
|
| 310 | 310 | $result = |
| 311 | 311 | '<pre style="background:#fff;color:#333;padding:16px;border:solid 1px #bbb;border-radius:4px">'. |
| 312 | 312 | $result. |
| 313 | 313 | '</pre>'; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - if($return) { |
|
| 316 | + if ($return) { |
|
| 317 | 317 | return $result; |
| 318 | 318 | } |
| 319 | 319 | |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | |
| 334 | 334 | public static function string2bool($string) |
| 335 | 335 | { |
| 336 | - if($string === '' || $string === null) { |
|
| 336 | + if ($string === '' || $string === null) { |
|
| 337 | 337 | return false; |
| 338 | 338 | } |
| 339 | 339 | |
@@ -388,10 +388,10 @@ discard block |
||
| 388 | 388 | public static function date2listLabel(\DateTime $date, $includeTime = false, $shortMonth = false) |
| 389 | 389 | { |
| 390 | 390 | $today = new \DateTime(); |
| 391 | - if($date->format('d.m.Y') == $today->format('d.m.Y')) { |
|
| 391 | + if ($date->format('d.m.Y') == $today->format('d.m.Y')) { |
|
| 392 | 392 | $label = t('Today'); |
| 393 | 393 | } else { |
| 394 | - $label = $date->format('d') . '. ' . self::month2string((int)$date->format('m'), $shortMonth) . ' '; |
|
| 394 | + $label = $date->format('d').'. '.self::month2string((int)$date->format('m'), $shortMonth).' '; |
|
| 395 | 395 | if ($date->format('Y') != date('Y')) { |
| 396 | 396 | $label .= $date->format('Y'); |
| 397 | 397 | } |
@@ -482,28 +482,28 @@ discard block |
||
| 482 | 482 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
| 483 | 483 | |
| 484 | 484 | $stack = array(); |
| 485 | - foreach(self::$controlChars as $char) |
|
| 485 | + foreach (self::$controlChars as $char) |
|
| 486 | 486 | { |
| 487 | 487 | $tokens = explode('-', $char); |
| 488 | 488 | $start = $tokens[0]; |
| 489 | 489 | $end = $tokens[1]; |
| 490 | 490 | $prefix = substr($start, 0, 3); |
| 491 | 491 | $range = array(); |
| 492 | - foreach($hexAlphabet as $number) { |
|
| 492 | + foreach ($hexAlphabet as $number) { |
|
| 493 | 493 | $range[] = $prefix.$number; |
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | $use = false; |
| 497 | - foreach($range as $number) { |
|
| 498 | - if($number == $start) { |
|
| 497 | + foreach ($range as $number) { |
|
| 498 | + if ($number == $start) { |
|
| 499 | 499 | $use = true; |
| 500 | 500 | } |
| 501 | 501 | |
| 502 | - if($use) { |
|
| 502 | + if ($use) { |
|
| 503 | 503 | $stack[] = $number; |
| 504 | 504 | } |
| 505 | 505 | |
| 506 | - if($number == $end) { |
|
| 506 | + if ($number == $end) { |
|
| 507 | 507 | break; |
| 508 | 508 | } |
| 509 | 509 | } |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | $chars = self::getControlCharactersAsHex(); |
| 525 | 525 | |
| 526 | 526 | $result = array(); |
| 527 | - foreach($chars as $char) { |
|
| 527 | + foreach ($chars as $char) { |
|
| 528 | 528 | $result[] = hex2bin($char); |
| 529 | 529 | } |
| 530 | 530 | |
@@ -542,14 +542,14 @@ discard block |
||
| 542 | 542 | $chars = self::getControlCharactersAsHex(); |
| 543 | 543 | |
| 544 | 544 | $result = array(); |
| 545 | - foreach($chars as $char) { |
|
| 545 | + foreach ($chars as $char) { |
|
| 546 | 546 | $result[] = '\u'.strtolower($char); |
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | return $result; |
| 550 | 550 | } |
| 551 | 551 | |
| 552 | - protected static $controlChars = array( |
|
| 552 | + protected static $controlChars = array( |
|
| 553 | 553 | '0000-0008', // control chars |
| 554 | 554 | '000E-000F', // control chars |
| 555 | 555 | '0010-001F', // control chars |
@@ -571,19 +571,19 @@ discard block |
||
| 571 | 571 | */ |
| 572 | 572 | public static function stripControlCharacters(string $string) : string |
| 573 | 573 | { |
| 574 | - if(empty($string)) { |
|
| 574 | + if (empty($string)) { |
|
| 575 | 575 | return $string; |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | // create the regex from the unicode characters list |
| 579 | - if(!isset(self::$controlCharsRegex)) |
|
| 579 | + if (!isset(self::$controlCharsRegex)) |
|
| 580 | 580 | { |
| 581 | 581 | $chars = self::getControlCharactersAsHex(); |
| 582 | 582 | |
| 583 | 583 | // we use the notation \x{0000} to specify the unicode character key |
| 584 | 584 | // in the regular expression. |
| 585 | 585 | $stack = array(); |
| 586 | - foreach($chars as $char) { |
|
| 586 | + foreach ($chars as $char) { |
|
| 587 | 587 | $stack[] = '\x{'.$char.'}'; |
| 588 | 588 | } |
| 589 | 589 | |
@@ -617,7 +617,7 @@ discard block |
||
| 617 | 617 | $ordInt = ord($octet); |
| 618 | 618 | // Convert from int (base 10) to hex (base 16), for PHP \x syntax |
| 619 | 619 | $ordHex = base_convert($ordInt, 10, 16); |
| 620 | - $output .= '\x' . $ordHex; |
|
| 620 | + $output .= '\x'.$ordHex; |
|
| 621 | 621 | } |
| 622 | 622 | return $output; |
| 623 | 623 | } |
@@ -649,19 +649,19 @@ discard block |
||
| 649 | 649 | |
| 650 | 650 | protected static function convertScalarForComparison($scalar) |
| 651 | 651 | { |
| 652 | - if($scalar === '' || is_null($scalar)) { |
|
| 652 | + if ($scalar === '' || is_null($scalar)) { |
|
| 653 | 653 | return null; |
| 654 | 654 | } |
| 655 | 655 | |
| 656 | - if(is_bool($scalar)) { |
|
| 656 | + if (is_bool($scalar)) { |
|
| 657 | 657 | return self::bool2string($scalar); |
| 658 | 658 | } |
| 659 | 659 | |
| 660 | - if(is_array($scalar)) { |
|
| 660 | + if (is_array($scalar)) { |
|
| 661 | 661 | $scalar = md5(serialize($scalar)); |
| 662 | 662 | } |
| 663 | 663 | |
| 664 | - if($scalar !== null && !is_scalar($scalar)) { |
|
| 664 | + if ($scalar !== null && !is_scalar($scalar)) { |
|
| 665 | 665 | throw new ConvertHelper_Exception( |
| 666 | 666 | 'Not a scalar value in comparison', |
| 667 | 667 | null, |
@@ -710,7 +710,7 @@ discard block |
||
| 710 | 710 | public static function bool2string($boolean, bool $yesno = false) : string |
| 711 | 711 | { |
| 712 | 712 | // allow 'yes', 'true', 'no', 'false' string notations as well |
| 713 | - if(!is_bool($boolean)) { |
|
| 713 | + if (!is_bool($boolean)) { |
|
| 714 | 714 | $boolean = self::string2bool($boolean); |
| 715 | 715 | } |
| 716 | 716 | |
@@ -751,15 +751,15 @@ discard block |
||
| 751 | 751 | public static function array2attributeString($array) |
| 752 | 752 | { |
| 753 | 753 | $tokens = array(); |
| 754 | - foreach($array as $attr => $value) { |
|
| 755 | - if($value == '' || $value == null) { |
|
| 754 | + foreach ($array as $attr => $value) { |
|
| 755 | + if ($value == '' || $value == null) { |
|
| 756 | 756 | continue; |
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | $tokens[] = $attr.'="'.$value.'"'; |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - if(empty($tokens)) { |
|
| 762 | + if (empty($tokens)) { |
|
| 763 | 763 | return ''; |
| 764 | 764 | } |
| 765 | 765 | |
@@ -774,10 +774,10 @@ discard block |
||
| 774 | 774 | * @param string $string |
| 775 | 775 | * @return string |
| 776 | 776 | */ |
| 777 | - public static function string2attributeJS($string, $quoted=true) |
|
| 777 | + public static function string2attributeJS($string, $quoted = true) |
|
| 778 | 778 | { |
| 779 | 779 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
| 780 | - if($quoted) { |
|
| 780 | + if ($quoted) { |
|
| 781 | 781 | $converted = "'".$converted."'"; |
| 782 | 782 | } |
| 783 | 783 | |
@@ -795,11 +795,11 @@ discard block |
||
| 795 | 795 | */ |
| 796 | 796 | public static function isBoolean($value) : bool |
| 797 | 797 | { |
| 798 | - if(is_bool($value)) { |
|
| 798 | + if (is_bool($value)) { |
|
| 799 | 799 | return true; |
| 800 | 800 | } |
| 801 | 801 | |
| 802 | - if(!is_scalar($value)) { |
|
| 802 | + if (!is_scalar($value)) { |
|
| 803 | 803 | return false; |
| 804 | 804 | } |
| 805 | 805 | |
@@ -815,7 +815,7 @@ discard block |
||
| 815 | 815 | public static function array2styleString(array $subject) : string |
| 816 | 816 | { |
| 817 | 817 | $tokens = array(); |
| 818 | - foreach($subject as $name => $value) { |
|
| 818 | + foreach ($subject as $name => $value) { |
|
| 819 | 819 | $tokens[] = $name.':'.$value; |
| 820 | 820 | } |
| 821 | 821 | |
@@ -873,7 +873,7 @@ discard block |
||
| 873 | 873 | * |
| 874 | 874 | * @see JSHelper::buildRegexStatement() |
| 875 | 875 | */ |
| 876 | - public static function regex2js(string $regex, string $statementType=JSHelper::JS_REGEX_OBJECT) |
|
| 876 | + public static function regex2js(string $regex, string $statementType = JSHelper::JS_REGEX_OBJECT) |
|
| 877 | 877 | { |
| 878 | 878 | return JSHelper::buildRegexStatement($regex, $statementType); |
| 879 | 879 | } |
@@ -890,11 +890,11 @@ discard block |
||
| 890 | 890 | * @throws ConvertHelper_Exception |
| 891 | 891 | * @return string |
| 892 | 892 | */ |
| 893 | - public static function var2json($variable, int $options=0, int $depth=512) : string |
|
| 893 | + public static function var2json($variable, int $options = 0, int $depth = 512) : string |
|
| 894 | 894 | { |
| 895 | 895 | $result = json_encode($variable, $options, $depth); |
| 896 | 896 | |
| 897 | - if($result !== false) { |
|
| 897 | + if ($result !== false) { |
|
| 898 | 898 | return $result; |
| 899 | 899 | } |
| 900 | 900 | |
@@ -919,10 +919,10 @@ discard block |
||
| 919 | 919 | public static function stripUTFBom($string) |
| 920 | 920 | { |
| 921 | 921 | $boms = FileHelper::getUTFBOMs(); |
| 922 | - foreach($boms as $bomChars) { |
|
| 922 | + foreach ($boms as $bomChars) { |
|
| 923 | 923 | $length = mb_strlen($bomChars); |
| 924 | 924 | $text = mb_substr($string, 0, $length); |
| 925 | - if($text==$bomChars) { |
|
| 925 | + if ($text == $bomChars) { |
|
| 926 | 926 | return mb_substr($string, $length); |
| 927 | 927 | } |
| 928 | 928 | } |
@@ -939,7 +939,7 @@ discard block |
||
| 939 | 939 | */ |
| 940 | 940 | public static function string2utf8($string) |
| 941 | 941 | { |
| 942 | - if(!self::isStringASCII($string)) { |
|
| 942 | + if (!self::isStringASCII($string)) { |
|
| 943 | 943 | return \ForceUTF8\Encoding::toUTF8($string); |
| 944 | 944 | } |
| 945 | 945 | |
@@ -957,11 +957,11 @@ discard block |
||
| 957 | 957 | */ |
| 958 | 958 | public static function isStringASCII($string) : bool |
| 959 | 959 | { |
| 960 | - if($string === '' || $string === NULL) { |
|
| 960 | + if ($string === '' || $string === NULL) { |
|
| 961 | 961 | return true; |
| 962 | 962 | } |
| 963 | 963 | |
| 964 | - if(!is_string($string)) { |
|
| 964 | + if (!is_string($string)) { |
|
| 965 | 965 | return false; |
| 966 | 966 | } |
| 967 | 967 | |
@@ -995,7 +995,7 @@ discard block |
||
| 995 | 995 | * @param array $options |
| 996 | 996 | * @return float |
| 997 | 997 | */ |
| 998 | - public static function matchString($source, $target, $options=array()) |
|
| 998 | + public static function matchString($source, $target, $options = array()) |
|
| 999 | 999 | { |
| 1000 | 1000 | $defaults = array( |
| 1001 | 1001 | 'maxLevenshtein' => 10, |
@@ -1005,12 +1005,12 @@ discard block |
||
| 1005 | 1005 | $options = array_merge($defaults, $options); |
| 1006 | 1006 | |
| 1007 | 1007 | // avoid doing this via levenshtein |
| 1008 | - if($source == $target) { |
|
| 1008 | + if ($source == $target) { |
|
| 1009 | 1009 | return 100; |
| 1010 | 1010 | } |
| 1011 | 1011 | |
| 1012 | 1012 | $diff = levenshtein($source, $target); |
| 1013 | - if($diff > $options['maxLevenshtein']) { |
|
| 1013 | + if ($diff > $options['maxLevenshtein']) { |
|
| 1014 | 1014 | return 0; |
| 1015 | 1015 | } |
| 1016 | 1016 | |
@@ -1024,8 +1024,8 @@ discard block |
||
| 1024 | 1024 | |
| 1025 | 1025 | $offset = 0; |
| 1026 | 1026 | $keep = array(); |
| 1027 | - foreach($tokens as $token) { |
|
| 1028 | - if($interval->$token > 0) { |
|
| 1027 | + foreach ($tokens as $token) { |
|
| 1028 | + if ($interval->$token > 0) { |
|
| 1029 | 1029 | $keep = array_slice($tokens, $offset); |
| 1030 | 1030 | break; |
| 1031 | 1031 | } |
@@ -1034,16 +1034,16 @@ discard block |
||
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | $parts = array(); |
| 1037 | - foreach($keep as $token) |
|
| 1037 | + foreach ($keep as $token) |
|
| 1038 | 1038 | { |
| 1039 | 1039 | $value = $interval->$token; |
| 1040 | 1040 | $label = ''; |
| 1041 | 1041 | |
| 1042 | 1042 | $suffix = 'p'; |
| 1043 | - if($value == 1) { $suffix = 's'; } |
|
| 1043 | + if ($value == 1) { $suffix = 's'; } |
|
| 1044 | 1044 | $token .= $suffix; |
| 1045 | 1045 | |
| 1046 | - switch($token) { |
|
| 1046 | + switch ($token) { |
|
| 1047 | 1047 | case 'ys': $label = t('1 year'); break; |
| 1048 | 1048 | case 'yp': $label = t('%1$s years', $value); break; |
| 1049 | 1049 | case 'ms': $label = t('1 month'); break; |
@@ -1061,7 +1061,7 @@ discard block |
||
| 1061 | 1061 | $parts[] = $label; |
| 1062 | 1062 | } |
| 1063 | 1063 | |
| 1064 | - if(count($parts) == 1) { |
|
| 1064 | + if (count($parts) == 1) { |
|
| 1065 | 1065 | return $parts[0]; |
| 1066 | 1066 | } |
| 1067 | 1067 | |
@@ -1132,24 +1132,24 @@ discard block |
||
| 1132 | 1132 | * @see ConvertHelper::INTERVAL_HOURS |
| 1133 | 1133 | * @see ConvertHelper::INTERVAL_DAYS |
| 1134 | 1134 | */ |
| 1135 | - public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) : int |
|
| 1135 | + public static function interval2total(\DateInterval $interval, $unit = self::INTERVAL_SECONDS) : int |
|
| 1136 | 1136 | { |
| 1137 | 1137 | $total = $interval->format('%a'); |
| 1138 | 1138 | if ($unit == self::INTERVAL_DAYS) { |
| 1139 | 1139 | return (int)$total; |
| 1140 | 1140 | } |
| 1141 | 1141 | |
| 1142 | - $total = ($total * 24) + ($interval->h ); |
|
| 1142 | + $total = ($total * 24) + ($interval->h); |
|
| 1143 | 1143 | if ($unit == self::INTERVAL_HOURS) { |
| 1144 | 1144 | return (int)$total; |
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | - $total = ($total * 60) + ($interval->i ); |
|
| 1147 | + $total = ($total * 60) + ($interval->i); |
|
| 1148 | 1148 | if ($unit == self::INTERVAL_MINUTES) { |
| 1149 | 1149 | return (int)$total; |
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | - $total = ($total * 60) + ($interval->s ); |
|
| 1152 | + $total = ($total * 60) + ($interval->s); |
|
| 1153 | 1153 | if ($unit == self::INTERVAL_SECONDS) { |
| 1154 | 1154 | return (int)$total; |
| 1155 | 1155 | } |
@@ -1178,13 +1178,13 @@ discard block |
||
| 1178 | 1178 | * @param string $short |
| 1179 | 1179 | * @return string|NULL |
| 1180 | 1180 | */ |
| 1181 | - public static function date2dayName(\DateTime $date, $short=false) |
|
| 1181 | + public static function date2dayName(\DateTime $date, $short = false) |
|
| 1182 | 1182 | { |
| 1183 | 1183 | $day = $date->format('l'); |
| 1184 | 1184 | $invariant = self::getDayNamesInvariant(); |
| 1185 | 1185 | |
| 1186 | 1186 | $idx = array_search($day, $invariant); |
| 1187 | - if($idx !== false) { |
|
| 1187 | + if ($idx !== false) { |
|
| 1188 | 1188 | $localized = self::getDayNames($short); |
| 1189 | 1189 | return $localized[$idx]; |
| 1190 | 1190 | } |
@@ -1207,10 +1207,10 @@ discard block |
||
| 1207 | 1207 | * @param string $short |
| 1208 | 1208 | * @return string[] |
| 1209 | 1209 | */ |
| 1210 | - public static function getDayNames($short=false) |
|
| 1210 | + public static function getDayNames($short = false) |
|
| 1211 | 1211 | { |
| 1212 | - if($short) { |
|
| 1213 | - if(!isset(self::$daysShort)) { |
|
| 1212 | + if ($short) { |
|
| 1213 | + if (!isset(self::$daysShort)) { |
|
| 1214 | 1214 | self::$daysShort = array( |
| 1215 | 1215 | t('Mon'), |
| 1216 | 1216 | t('Tue'), |
@@ -1225,7 +1225,7 @@ discard block |
||
| 1225 | 1225 | return self::$daysShort; |
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | - if(!isset(self::$days)) { |
|
| 1228 | + if (!isset(self::$days)) { |
|
| 1229 | 1229 | self::$days = array( |
| 1230 | 1230 | t('Monday'), |
| 1231 | 1231 | t('Tuesday'), |
@@ -1250,17 +1250,17 @@ discard block |
||
| 1250 | 1250 | */ |
| 1251 | 1251 | public static function implodeWithAnd(array $list, $sep = ', ', $conjunction = null) |
| 1252 | 1252 | { |
| 1253 | - if(empty($list)) { |
|
| 1253 | + if (empty($list)) { |
|
| 1254 | 1254 | return ''; |
| 1255 | 1255 | } |
| 1256 | 1256 | |
| 1257 | - if(empty($conjunction)) { |
|
| 1257 | + if (empty($conjunction)) { |
|
| 1258 | 1258 | $conjunction = t('and'); |
| 1259 | 1259 | } |
| 1260 | 1260 | |
| 1261 | 1261 | $last = array_pop($list); |
| 1262 | - if($list) { |
|
| 1263 | - return implode($sep, $list) . $conjunction . ' ' . $last; |
|
| 1262 | + if ($list) { |
|
| 1263 | + return implode($sep, $list).$conjunction.' '.$last; |
|
| 1264 | 1264 | } |
| 1265 | 1265 | |
| 1266 | 1266 | return $last; |
@@ -1279,7 +1279,7 @@ discard block |
||
| 1279 | 1279 | public static function string2array(string $string) : array |
| 1280 | 1280 | { |
| 1281 | 1281 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
| 1282 | - if($result !== false) { |
|
| 1282 | + if ($result !== false) { |
|
| 1283 | 1283 | return $result; |
| 1284 | 1284 | } |
| 1285 | 1285 | |
@@ -1294,12 +1294,12 @@ discard block |
||
| 1294 | 1294 | */ |
| 1295 | 1295 | public static function isStringHTML(string $string) : bool |
| 1296 | 1296 | { |
| 1297 | - if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
|
| 1297 | + if (preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
|
| 1298 | 1298 | return true; |
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | 1301 | $decoded = html_entity_decode($string); |
| 1302 | - if($decoded !== $string) { |
|
| 1302 | + if ($decoded !== $string) { |
|
| 1303 | 1303 | return true; |
| 1304 | 1304 | } |
| 1305 | 1305 | |
@@ -1408,14 +1408,14 @@ discard block |
||
| 1408 | 1408 | * @param bool $caseInsensitive |
| 1409 | 1409 | * @return ConvertHelper_StringMatch[] |
| 1410 | 1410 | */ |
| 1411 | - public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
|
| 1411 | + public static function findString(string $needle, string $haystack, bool $caseInsensitive = false) |
|
| 1412 | 1412 | { |
| 1413 | - if($needle === '') { |
|
| 1413 | + if ($needle === '') { |
|
| 1414 | 1414 | return array(); |
| 1415 | 1415 | } |
| 1416 | 1416 | |
| 1417 | 1417 | $function = 'mb_strpos'; |
| 1418 | - if($caseInsensitive) { |
|
| 1418 | + if ($caseInsensitive) { |
|
| 1419 | 1419 | $function = 'mb_stripos'; |
| 1420 | 1420 | } |
| 1421 | 1421 | |
@@ -1423,7 +1423,7 @@ discard block |
||
| 1423 | 1423 | $positions = array(); |
| 1424 | 1424 | $length = mb_strlen($needle); |
| 1425 | 1425 | |
| 1426 | - while( ($pos = $function($haystack, $needle, $pos)) !== false) |
|
| 1426 | + while (($pos = $function($haystack, $needle, $pos)) !== false) |
|
| 1427 | 1427 | { |
| 1428 | 1428 | $match = mb_substr($haystack, $pos, $length); |
| 1429 | 1429 | $positions[] = new ConvertHelper_StringMatch($pos, $match); |
@@ -1443,7 +1443,7 @@ discard block |
||
| 1443 | 1443 | */ |
| 1444 | 1444 | public static function explodeTrim(string $delimiter, string $string) : array |
| 1445 | 1445 | { |
| 1446 | - if(empty($string) || empty($delimiter)) { |
|
| 1446 | + if (empty($string) || empty($delimiter)) { |
|
| 1447 | 1447 | return array(); |
| 1448 | 1448 | } |
| 1449 | 1449 | |
@@ -1451,8 +1451,8 @@ discard block |
||
| 1451 | 1451 | $tokens = array_map('trim', $tokens); |
| 1452 | 1452 | |
| 1453 | 1453 | $keep = array(); |
| 1454 | - foreach($tokens as $token) { |
|
| 1455 | - if($token !== '') { |
|
| 1454 | + foreach ($tokens as $token) { |
|
| 1455 | + if ($token !== '') { |
|
| 1456 | 1456 | $keep[] = $token; |
| 1457 | 1457 | } |
| 1458 | 1458 | } |
@@ -1470,11 +1470,11 @@ discard block |
||
| 1470 | 1470 | */ |
| 1471 | 1471 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
| 1472 | 1472 | { |
| 1473 | - if(empty($subjectString)) { |
|
| 1473 | + if (empty($subjectString)) { |
|
| 1474 | 1474 | return null; |
| 1475 | 1475 | } |
| 1476 | 1476 | |
| 1477 | - if(!isset(self::$eolChars)) |
|
| 1477 | + if (!isset(self::$eolChars)) |
|
| 1478 | 1478 | { |
| 1479 | 1479 | $cr = chr((int)hexdec('0d')); |
| 1480 | 1480 | $lf = chr((int)hexdec('0a')); |
@@ -1505,18 +1505,18 @@ discard block |
||
| 1505 | 1505 | |
| 1506 | 1506 | $max = 0; |
| 1507 | 1507 | $results = array(); |
| 1508 | - foreach(self::$eolChars as $def) |
|
| 1508 | + foreach (self::$eolChars as $def) |
|
| 1509 | 1509 | { |
| 1510 | 1510 | $amount = substr_count($subjectString, $def['char']); |
| 1511 | 1511 | |
| 1512 | - if($amount > $max) |
|
| 1512 | + if ($amount > $max) |
|
| 1513 | 1513 | { |
| 1514 | 1514 | $max = $amount; |
| 1515 | 1515 | $results[] = $def; |
| 1516 | 1516 | } |
| 1517 | 1517 | } |
| 1518 | 1518 | |
| 1519 | - if(empty($results)) { |
|
| 1519 | + if (empty($results)) { |
|
| 1520 | 1520 | return null; |
| 1521 | 1521 | } |
| 1522 | 1522 | |
@@ -1536,9 +1536,9 @@ discard block |
||
| 1536 | 1536 | */ |
| 1537 | 1537 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
| 1538 | 1538 | { |
| 1539 | - foreach($keys as $key) |
|
| 1539 | + foreach ($keys as $key) |
|
| 1540 | 1540 | { |
| 1541 | - if(array_key_exists($key, $array)) { |
|
| 1541 | + if (array_key_exists($key, $array)) { |
|
| 1542 | 1542 | unset($array[$key]); |
| 1543 | 1543 | } |
| 1544 | 1544 | } |
@@ -1553,17 +1553,17 @@ discard block |
||
| 1553 | 1553 | */ |
| 1554 | 1554 | public static function isInteger($value) : bool |
| 1555 | 1555 | { |
| 1556 | - if(is_int($value)) { |
|
| 1556 | + if (is_int($value)) { |
|
| 1557 | 1557 | return true; |
| 1558 | 1558 | } |
| 1559 | 1559 | |
| 1560 | 1560 | // booleans get converted to numbers, so they would |
| 1561 | 1561 | // actually match the regex. |
| 1562 | - if(is_bool($value)) { |
|
| 1562 | + if (is_bool($value)) { |
|
| 1563 | 1563 | return false; |
| 1564 | 1564 | } |
| 1565 | 1565 | |
| 1566 | - if(is_string($value) && $value !== '') { |
|
| 1566 | + if (is_string($value) && $value !== '') { |
|
| 1567 | 1567 | return preg_match('/\A-?\d+\z/', $value) === 1; |
| 1568 | 1568 | } |
| 1569 | 1569 | |
@@ -1590,7 +1590,7 @@ discard block |
||
| 1590 | 1590 | $d2->add(new \DateInterval('PT'.$seconds.'S')); |
| 1591 | 1591 | |
| 1592 | 1592 | $result = $d2->diff($d1); |
| 1593 | - if($result !== false) { |
|
| 1593 | + if ($result !== false) { |
|
| 1594 | 1594 | return $result; |
| 1595 | 1595 | } |
| 1596 | 1596 | |
@@ -181,8 +181,7 @@ discard block |
||
| 181 | 181 | if($datefrom instanceof \DateTime) |
| 182 | 182 | { |
| 183 | 183 | $converter->setDateFrom($datefrom); |
| 184 | - } |
|
| 185 | - else |
|
| 184 | + } else |
|
| 186 | 185 | { |
| 187 | 186 | $converter->setDateFrom(self::timestamp2date($datefrom)); |
| 188 | 187 | } |
@@ -190,8 +189,7 @@ discard block |
||
| 190 | 189 | if($dateto instanceof \DateTime) |
| 191 | 190 | { |
| 192 | 191 | $converter->setDateTo($dateto); |
| 193 | - } |
|
| 194 | - else if($dateto > 0) |
|
| 192 | + } else if($dateto > 0) |
|
| 195 | 193 | { |
| 196 | 194 | $converter->setDateTo(self::timestamp2date($dateto)); |
| 197 | 195 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | // extract parameter names from the query string |
| 38 | 38 | $result = array(); |
| 39 | 39 | preg_match_all('/&?([^&]+)=.*/sixU', $queryString, $result, PREG_PATTERN_ORDER); |
| 40 | - if(isset($result[1])) { |
|
| 40 | + if (isset($result[1])) { |
|
| 41 | 41 | $paramNames = $result[1]; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | // possible naming conflicts like having both parameters "foo.bar" |
| 61 | 61 | // and "foo_bar" in the query string: since "foo.bar" would be converted |
| 62 | 62 | // to "foo_bar", one of the two would be replaced. |
| 63 | - if($fixRequired) |
|
| 63 | + if ($fixRequired) |
|
| 64 | 64 | { |
| 65 | 65 | $counter = 1; |
| 66 | 66 | $placeholders = array(); |
| 67 | - foreach($paramNames as $paramName) |
|
| 67 | + foreach ($paramNames as $paramName) |
|
| 68 | 68 | { |
| 69 | 69 | // create a unique placeholder name |
| 70 | 70 | $placeholder = '__PLACEHOLDER'.$counter.'__'; |
@@ -94,13 +94,13 @@ discard block |
||
| 94 | 94 | parse_str($queryString, $parsed); |
| 95 | 95 | |
| 96 | 96 | // do any of the parameter names need to be fixed? |
| 97 | - if(!$fixRequired) { |
|
| 97 | + if (!$fixRequired) { |
|
| 98 | 98 | return $parsed; |
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | $keep = array(); |
| 102 | 102 | |
| 103 | - foreach($parsed as $name => $value) |
|
| 103 | + foreach ($parsed as $name => $value) |
|
| 104 | 104 | { |
| 105 | 105 | $keep[$table[$name]] = $value; |
| 106 | 106 | } |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | return $this->getBoolOption('cut'); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - public function setCuttingEnabled(bool $enabled=true) : ConvertHelper_WordWrapper |
|
| 66 | + public function setCuttingEnabled(bool $enabled = true) : ConvertHelper_WordWrapper |
|
| 67 | 67 | { |
| 68 | 68 | $this->setOption('cut', $enabled); |
| 69 | 69 | return $this; |
@@ -92,8 +92,7 @@ |
||
| 92 | 92 | if (mb_strlen($actual.$word) <= $width) |
| 93 | 93 | { |
| 94 | 94 | $actual .= $word.' '; |
| 95 | - } |
|
| 96 | - else |
|
| 95 | + } else |
|
| 97 | 96 | { |
| 98 | 97 | if ($actual != '') { |
| 99 | 98 | $line .= rtrim($actual).$break; |