@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $amount = substr_count($line, "\t") - $min; |
58 | 58 | $line = trim($line); |
59 | 59 | if ($amount >= 1) { |
60 | - $line = str_repeat("\t", $amount) . $line; |
|
60 | + $line = str_repeat("\t", $amount).$line; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | $converted[] = $line; |
@@ -129,10 +129,10 @@ discard block |
||
129 | 129 | |
130 | 130 | // specifically handle zero |
131 | 131 | if ($seconds <= 0) { |
132 | - return '0 ' . t('seconds'); |
|
132 | + return '0 '.t('seconds'); |
|
133 | 133 | } |
134 | 134 | |
135 | - if($seconds < 1) { |
|
135 | + if ($seconds < 1) { |
|
136 | 136 | return t('less than a second'); |
137 | 137 | } |
138 | 138 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | foreach ($units as $def) { |
141 | 141 | $quot = intval($seconds / $def['value']); |
142 | 142 | if ($quot) { |
143 | - $item = $quot . ' '; |
|
143 | + $item = $quot.' '; |
|
144 | 144 | if (abs($quot) > 1) { |
145 | 145 | $item .= $def['plural']; |
146 | 146 | } else { |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | return $last; |
158 | 158 | } |
159 | 159 | |
160 | - return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
|
160 | + return implode(', ', $tokens).' '.t('and').' '.$last; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | */ |
175 | 175 | public static function duration2string($datefrom, $dateto = -1) |
176 | 176 | { |
177 | - if($datefrom instanceof \DateTime) { |
|
177 | + if ($datefrom instanceof \DateTime) { |
|
178 | 178 | $datefrom = ConvertHelper::date2timestamp($datefrom); |
179 | 179 | } |
180 | 180 | |
181 | - if($dateto instanceof \DateTime) { |
|
181 | + if ($dateto instanceof \DateTime) { |
|
182 | 182 | $dateto = ConvertHelper::date2timestamp($dateto); |
183 | 183 | } |
184 | 184 | |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $interval = ""; |
200 | 200 | |
201 | 201 | $future = false; |
202 | - if($difference < 0) { |
|
202 | + if ($difference < 0) { |
|
203 | 203 | $difference = $difference * -1; |
204 | 204 | $future = true; |
205 | 205 | } |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | $day = (int)date("j", $dateto); |
275 | 275 | $year = (int)date("Y", $datefrom); |
276 | 276 | |
277 | - while(mktime($hour, $min, $sec, $month + ($months_difference), $day, $year) < $dateto) |
|
277 | + while (mktime($hour, $min, $sec, $month + ($months_difference), $day, $year) < $dateto) |
|
278 | 278 | { |
279 | 279 | $months_difference++; |
280 | 280 | } |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | $datediff--; |
290 | 290 | } |
291 | 291 | |
292 | - if($future) { |
|
292 | + if ($future) { |
|
293 | 293 | $result = ($datediff == 1) ? t('In one month', $datediff) : t('In %1s months', $datediff); |
294 | 294 | } else { |
295 | 295 | $result = ($datediff == 1) ? t('One month ago', $datediff) : t('%1s months ago', $datediff); |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | |
299 | 299 | case "y": |
300 | 300 | $datediff = floor($difference / 60 / 60 / 24 / 365); |
301 | - if($future) { |
|
301 | + if ($future) { |
|
302 | 302 | $result = ($datediff == 1) ? t('In one year', $datediff) : t('In %1s years', $datediff); |
303 | 303 | } else { |
304 | 304 | $result = ($datediff == 1) ? t('One year ago', $datediff) : t('%1s years ago', $datediff); |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | |
308 | 308 | case "d": |
309 | 309 | $datediff = floor($difference / 60 / 60 / 24); |
310 | - if($future) { |
|
310 | + if ($future) { |
|
311 | 311 | $result = ($datediff == 1) ? t('In one day', $datediff) : t('In %1s days', $datediff); |
312 | 312 | } else { |
313 | 313 | $result = ($datediff == 1) ? t('One day ago', $datediff) : t('%1s days ago', $datediff); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | |
317 | 317 | case "ww": |
318 | 318 | $datediff = floor($difference / 60 / 60 / 24 / 7); |
319 | - if($future) { |
|
319 | + if ($future) { |
|
320 | 320 | $result = ($datediff == 1) ? t('In one week', $datediff) : t('In %1s weeks', $datediff); |
321 | 321 | } else { |
322 | 322 | $result = ($datediff == 1) ? t('One week ago', $datediff) : t('%1s weeks ago', $datediff); |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | |
326 | 326 | case "h": |
327 | 327 | $datediff = floor($difference / 60 / 60); |
328 | - if($future) { |
|
328 | + if ($future) { |
|
329 | 329 | $result = ($datediff == 1) ? t('In one hour', $datediff) : t('In %1s hours', $datediff); |
330 | 330 | } else { |
331 | 331 | $result = ($datediff == 1) ? t('One hour ago', $datediff) : t('%1s hours ago', $datediff); |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | |
335 | 335 | case "n": |
336 | 336 | $datediff = floor($difference / 60); |
337 | - if($future) { |
|
337 | + if ($future) { |
|
338 | 338 | $result = ($datediff == 1) ? t('In one minute', $datediff) : t('In %1s minutes', $datediff); |
339 | 339 | } else { |
340 | 340 | $result = ($datediff == 1) ? t('One minute ago', $datediff) : t('%1s minutes ago', $datediff); |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | |
344 | 344 | case "s": |
345 | 345 | $datediff = $difference; |
346 | - if($future) { |
|
346 | + if ($future) { |
|
347 | 347 | $result = ($datediff == 1) ? t('In one second', $datediff) : t('In %1s seconds', $datediff); |
348 | 348 | } else { |
349 | 349 | $result = ($datediff == 1) ? t('One second ago', $datediff) : t('%1s seconds ago', $datediff); |
@@ -366,9 +366,9 @@ discard block |
||
366 | 366 | return $geshi->parse_code(); |
367 | 367 | } |
368 | 368 | |
369 | - public static function highlight_xml($xml, $formatSource=false) |
|
369 | + public static function highlight_xml($xml, $formatSource = false) |
|
370 | 370 | { |
371 | - if($formatSource) |
|
371 | + if ($formatSource) |
|
372 | 372 | { |
373 | 373 | $dom = new \DOMDocument(); |
374 | 374 | $dom->loadXML($xml); |
@@ -406,22 +406,22 @@ discard block |
||
406 | 406 | $terabyte = $gigabyte * 1024; |
407 | 407 | |
408 | 408 | if (($bytes >= 0) && ($bytes < $kilobyte)) { |
409 | - return $bytes . ' ' . t('B'); |
|
409 | + return $bytes.' '.t('B'); |
|
410 | 410 | |
411 | 411 | } elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) { |
412 | - return round($bytes / $kilobyte, $precision) . ' ' . t('Kb'); |
|
412 | + return round($bytes / $kilobyte, $precision).' '.t('Kb'); |
|
413 | 413 | |
414 | 414 | } elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) { |
415 | - return round($bytes / $megabyte, $precision) . ' ' . t('Mb'); |
|
415 | + return round($bytes / $megabyte, $precision).' '.t('Mb'); |
|
416 | 416 | |
417 | 417 | } elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) { |
418 | - return round($bytes / $gigabyte, $precision) . ' ' . t('Gb'); |
|
418 | + return round($bytes / $gigabyte, $precision).' '.t('Gb'); |
|
419 | 419 | |
420 | 420 | } elseif ($bytes >= $terabyte) { |
421 | - return round($bytes / $gigabyte, $precision) . ' ' . t('Tb'); |
|
421 | + return round($bytes / $gigabyte, $precision).' '.t('Tb'); |
|
422 | 422 | } |
423 | 423 | |
424 | - return $bytes . ' ' . t('B'); |
|
424 | + return $bytes.' '.t('B'); |
|
425 | 425 | } |
426 | 426 | |
427 | 427 | /** |
@@ -441,34 +441,34 @@ discard block |
||
441 | 441 | return $text; |
442 | 442 | } |
443 | 443 | |
444 | - $text = trim(mb_substr($text, 0, $targetLength)) . $append; |
|
444 | + $text = trim(mb_substr($text, 0, $targetLength)).$append; |
|
445 | 445 | |
446 | 446 | return $text; |
447 | 447 | } |
448 | 448 | |
449 | - public static function var_dump($var, $html=true) |
|
449 | + public static function var_dump($var, $html = true) |
|
450 | 450 | { |
451 | 451 | $info = parseVariable($var); |
452 | 452 | |
453 | - if($html) { |
|
453 | + if ($html) { |
|
454 | 454 | return $info->toHTML(); |
455 | 455 | } |
456 | 456 | |
457 | 457 | return $info->toString(); |
458 | 458 | } |
459 | 459 | |
460 | - public static function print_r($var, $return=false, $html=true) |
|
460 | + public static function print_r($var, $return = false, $html = true) |
|
461 | 461 | { |
462 | 462 | $result = self::var_dump($var, $html); |
463 | 463 | |
464 | - if($html) { |
|
464 | + if ($html) { |
|
465 | 465 | $result = |
466 | 466 | '<pre style="background:#fff;color:#333;padding:16px;border:solid 1px #bbb;border-radius:4px">'. |
467 | 467 | $result. |
468 | 468 | '</pre>'; |
469 | 469 | } |
470 | 470 | |
471 | - if($return) { |
|
471 | + if ($return) { |
|
472 | 472 | return $result; |
473 | 473 | } |
474 | 474 | |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | |
489 | 489 | public static function string2bool($string) |
490 | 490 | { |
491 | - if($string === '' || $string === null) { |
|
491 | + if ($string === '' || $string === null) { |
|
492 | 492 | return false; |
493 | 493 | } |
494 | 494 | |
@@ -543,10 +543,10 @@ discard block |
||
543 | 543 | public static function date2listLabel(\DateTime $date, $includeTime = false, $shortMonth = false) |
544 | 544 | { |
545 | 545 | $today = new \DateTime(); |
546 | - if($date->format('d.m.Y') == $today->format('d.m.Y')) { |
|
546 | + if ($date->format('d.m.Y') == $today->format('d.m.Y')) { |
|
547 | 547 | $label = t('Today'); |
548 | 548 | } else { |
549 | - $label = $date->format('d') . '. ' . self::month2string((int)$date->format('m'), $shortMonth) . ' '; |
|
549 | + $label = $date->format('d').'. '.self::month2string((int)$date->format('m'), $shortMonth).' '; |
|
550 | 550 | if ($date->format('Y') != date('Y')) { |
551 | 551 | $label .= $date->format('Y'); |
552 | 552 | } |
@@ -637,28 +637,28 @@ discard block |
||
637 | 637 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
638 | 638 | |
639 | 639 | $stack = array(); |
640 | - foreach(self::$controlChars as $char) |
|
640 | + foreach (self::$controlChars as $char) |
|
641 | 641 | { |
642 | 642 | $tokens = explode('-', $char); |
643 | 643 | $start = $tokens[0]; |
644 | 644 | $end = $tokens[1]; |
645 | 645 | $prefix = substr($start, 0, 3); |
646 | 646 | $range = array(); |
647 | - foreach($hexAlphabet as $number) { |
|
647 | + foreach ($hexAlphabet as $number) { |
|
648 | 648 | $range[] = $prefix.$number; |
649 | 649 | } |
650 | 650 | |
651 | 651 | $use = false; |
652 | - foreach($range as $number) { |
|
653 | - if($number == $start) { |
|
652 | + foreach ($range as $number) { |
|
653 | + if ($number == $start) { |
|
654 | 654 | $use = true; |
655 | 655 | } |
656 | 656 | |
657 | - if($use) { |
|
657 | + if ($use) { |
|
658 | 658 | $stack[] = $number; |
659 | 659 | } |
660 | 660 | |
661 | - if($number == $end) { |
|
661 | + if ($number == $end) { |
|
662 | 662 | break; |
663 | 663 | } |
664 | 664 | } |
@@ -679,7 +679,7 @@ discard block |
||
679 | 679 | $chars = self::getControlCharactersAsHex(); |
680 | 680 | |
681 | 681 | $result = array(); |
682 | - foreach($chars as $char) { |
|
682 | + foreach ($chars as $char) { |
|
683 | 683 | $result[] = hex2bin($char); |
684 | 684 | } |
685 | 685 | |
@@ -697,14 +697,14 @@ discard block |
||
697 | 697 | $chars = self::getControlCharactersAsHex(); |
698 | 698 | |
699 | 699 | $result = array(); |
700 | - foreach($chars as $char) { |
|
700 | + foreach ($chars as $char) { |
|
701 | 701 | $result[] = '\u'.strtolower($char); |
702 | 702 | } |
703 | 703 | |
704 | 704 | return $result; |
705 | 705 | } |
706 | 706 | |
707 | - protected static $controlChars = array( |
|
707 | + protected static $controlChars = array( |
|
708 | 708 | '0000-0008', // control chars |
709 | 709 | '000E-000F', // control chars |
710 | 710 | '0010-001F', // control chars |
@@ -726,19 +726,19 @@ discard block |
||
726 | 726 | */ |
727 | 727 | public static function stripControlCharacters(string $string) : string |
728 | 728 | { |
729 | - if(empty($string)) { |
|
729 | + if (empty($string)) { |
|
730 | 730 | return $string; |
731 | 731 | } |
732 | 732 | |
733 | 733 | // create the regex from the unicode characters list |
734 | - if(!isset(self::$controlCharsRegex)) |
|
734 | + if (!isset(self::$controlCharsRegex)) |
|
735 | 735 | { |
736 | 736 | $chars = self::getControlCharactersAsHex(); |
737 | 737 | |
738 | 738 | // we use the notation \x{0000} to specify the unicode character key |
739 | 739 | // in the regular expression. |
740 | 740 | $stack = array(); |
741 | - foreach($chars as $char) { |
|
741 | + foreach ($chars as $char) { |
|
742 | 742 | $stack[] = '\x{'.$char.'}'; |
743 | 743 | } |
744 | 744 | |
@@ -772,7 +772,7 @@ discard block |
||
772 | 772 | $ordInt = ord($octet); |
773 | 773 | // Convert from int (base 10) to hex (base 16), for PHP \x syntax |
774 | 774 | $ordHex = base_convert($ordInt, 10, 16); |
775 | - $output .= '\x' . $ordHex; |
|
775 | + $output .= '\x'.$ordHex; |
|
776 | 776 | } |
777 | 777 | return $output; |
778 | 778 | } |
@@ -804,19 +804,19 @@ discard block |
||
804 | 804 | |
805 | 805 | protected static function convertScalarForComparison($scalar) |
806 | 806 | { |
807 | - if($scalar === '' || is_null($scalar)) { |
|
807 | + if ($scalar === '' || is_null($scalar)) { |
|
808 | 808 | return null; |
809 | 809 | } |
810 | 810 | |
811 | - if(is_bool($scalar)) { |
|
811 | + if (is_bool($scalar)) { |
|
812 | 812 | return self::bool2string($scalar); |
813 | 813 | } |
814 | 814 | |
815 | - if(is_array($scalar)) { |
|
815 | + if (is_array($scalar)) { |
|
816 | 816 | $scalar = md5(serialize($scalar)); |
817 | 817 | } |
818 | 818 | |
819 | - if($scalar !== null && !is_scalar($scalar)) { |
|
819 | + if ($scalar !== null && !is_scalar($scalar)) { |
|
820 | 820 | throw new ConvertHelper_Exception( |
821 | 821 | 'Not a scalar value in comparison', |
822 | 822 | null, |
@@ -865,7 +865,7 @@ discard block |
||
865 | 865 | public static function bool2string($boolean, bool $yesno = false) : string |
866 | 866 | { |
867 | 867 | // allow 'yes', 'true', 'no', 'false' string notations as well |
868 | - if(!is_bool($boolean)) { |
|
868 | + if (!is_bool($boolean)) { |
|
869 | 869 | $boolean = self::string2bool($boolean); |
870 | 870 | } |
871 | 871 | |
@@ -906,15 +906,15 @@ discard block |
||
906 | 906 | public static function array2attributeString($array) |
907 | 907 | { |
908 | 908 | $tokens = array(); |
909 | - foreach($array as $attr => $value) { |
|
910 | - if($value == '' || $value == null) { |
|
909 | + foreach ($array as $attr => $value) { |
|
910 | + if ($value == '' || $value == null) { |
|
911 | 911 | continue; |
912 | 912 | } |
913 | 913 | |
914 | 914 | $tokens[] = $attr.'="'.$value.'"'; |
915 | 915 | } |
916 | 916 | |
917 | - if(empty($tokens)) { |
|
917 | + if (empty($tokens)) { |
|
918 | 918 | return ''; |
919 | 919 | } |
920 | 920 | |
@@ -929,10 +929,10 @@ discard block |
||
929 | 929 | * @param string $string |
930 | 930 | * @return string |
931 | 931 | */ |
932 | - public static function string2attributeJS($string, $quoted=true) |
|
932 | + public static function string2attributeJS($string, $quoted = true) |
|
933 | 933 | { |
934 | 934 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
935 | - if($quoted) { |
|
935 | + if ($quoted) { |
|
936 | 936 | $converted = "'".$converted."'"; |
937 | 937 | } |
938 | 938 | |
@@ -950,11 +950,11 @@ discard block |
||
950 | 950 | */ |
951 | 951 | public static function isBoolean($value) : bool |
952 | 952 | { |
953 | - if(is_bool($value)) { |
|
953 | + if (is_bool($value)) { |
|
954 | 954 | return true; |
955 | 955 | } |
956 | 956 | |
957 | - if(!is_scalar($value)) { |
|
957 | + if (!is_scalar($value)) { |
|
958 | 958 | return false; |
959 | 959 | } |
960 | 960 | |
@@ -970,7 +970,7 @@ discard block |
||
970 | 970 | public static function array2styleString(array $subject) : string |
971 | 971 | { |
972 | 972 | $tokens = array(); |
973 | - foreach($subject as $name => $value) { |
|
973 | + foreach ($subject as $name => $value) { |
|
974 | 974 | $tokens[] = $name.':'.$value; |
975 | 975 | } |
976 | 976 | |
@@ -1028,7 +1028,7 @@ discard block |
||
1028 | 1028 | * |
1029 | 1029 | * @see JSHelper::buildRegexStatement() |
1030 | 1030 | */ |
1031 | - public static function regex2js(string $regex, string $statementType=JSHelper::JS_REGEX_OBJECT) |
|
1031 | + public static function regex2js(string $regex, string $statementType = JSHelper::JS_REGEX_OBJECT) |
|
1032 | 1032 | { |
1033 | 1033 | return JSHelper::buildRegexStatement($regex, $statementType); |
1034 | 1034 | } |
@@ -1045,11 +1045,11 @@ discard block |
||
1045 | 1045 | * @throws ConvertHelper_Exception |
1046 | 1046 | * @return string |
1047 | 1047 | */ |
1048 | - public static function var2json($variable, int $options=0, int $depth=512) : string |
|
1048 | + public static function var2json($variable, int $options = 0, int $depth = 512) : string |
|
1049 | 1049 | { |
1050 | 1050 | $result = json_encode($variable, $options, $depth); |
1051 | 1051 | |
1052 | - if($result !== false) { |
|
1052 | + if ($result !== false) { |
|
1053 | 1053 | return $result; |
1054 | 1054 | } |
1055 | 1055 | |
@@ -1074,10 +1074,10 @@ discard block |
||
1074 | 1074 | public static function stripUTFBom($string) |
1075 | 1075 | { |
1076 | 1076 | $boms = FileHelper::getUTFBOMs(); |
1077 | - foreach($boms as $bomChars) { |
|
1077 | + foreach ($boms as $bomChars) { |
|
1078 | 1078 | $length = mb_strlen($bomChars); |
1079 | 1079 | $text = mb_substr($string, 0, $length); |
1080 | - if($text==$bomChars) { |
|
1080 | + if ($text == $bomChars) { |
|
1081 | 1081 | return mb_substr($string, $length); |
1082 | 1082 | } |
1083 | 1083 | } |
@@ -1094,7 +1094,7 @@ discard block |
||
1094 | 1094 | */ |
1095 | 1095 | public static function string2utf8($string) |
1096 | 1096 | { |
1097 | - if(!self::isStringASCII($string)) { |
|
1097 | + if (!self::isStringASCII($string)) { |
|
1098 | 1098 | return \ForceUTF8\Encoding::toUTF8($string); |
1099 | 1099 | } |
1100 | 1100 | |
@@ -1112,11 +1112,11 @@ discard block |
||
1112 | 1112 | */ |
1113 | 1113 | public static function isStringASCII($string) |
1114 | 1114 | { |
1115 | - if($string === '' || $string === NULL) { |
|
1115 | + if ($string === '' || $string === NULL) { |
|
1116 | 1116 | return true; |
1117 | 1117 | } |
1118 | 1118 | |
1119 | - if(!is_string($string)) { |
|
1119 | + if (!is_string($string)) { |
|
1120 | 1120 | return false; |
1121 | 1121 | } |
1122 | 1122 | |
@@ -1150,7 +1150,7 @@ discard block |
||
1150 | 1150 | * @param array $options |
1151 | 1151 | * @return float |
1152 | 1152 | */ |
1153 | - public static function matchString($source, $target, $options=array()) |
|
1153 | + public static function matchString($source, $target, $options = array()) |
|
1154 | 1154 | { |
1155 | 1155 | $defaults = array( |
1156 | 1156 | 'maxLevenshtein' => 10, |
@@ -1160,12 +1160,12 @@ discard block |
||
1160 | 1160 | $options = array_merge($defaults, $options); |
1161 | 1161 | |
1162 | 1162 | // avoid doing this via levenshtein |
1163 | - if($source == $target) { |
|
1163 | + if ($source == $target) { |
|
1164 | 1164 | return 100; |
1165 | 1165 | } |
1166 | 1166 | |
1167 | 1167 | $diff = levenshtein($source, $target); |
1168 | - if($diff > $options['maxLevenshtein']) { |
|
1168 | + if ($diff > $options['maxLevenshtein']) { |
|
1169 | 1169 | return 0; |
1170 | 1170 | } |
1171 | 1171 | |
@@ -1179,8 +1179,8 @@ discard block |
||
1179 | 1179 | |
1180 | 1180 | $offset = 0; |
1181 | 1181 | $keep = array(); |
1182 | - foreach($tokens as $token) { |
|
1183 | - if($interval->$token > 0) { |
|
1182 | + foreach ($tokens as $token) { |
|
1183 | + if ($interval->$token > 0) { |
|
1184 | 1184 | $keep = array_slice($tokens, $offset); |
1185 | 1185 | break; |
1186 | 1186 | } |
@@ -1189,16 +1189,16 @@ discard block |
||
1189 | 1189 | } |
1190 | 1190 | |
1191 | 1191 | $parts = array(); |
1192 | - foreach($keep as $token) |
|
1192 | + foreach ($keep as $token) |
|
1193 | 1193 | { |
1194 | 1194 | $value = $interval->$token; |
1195 | 1195 | $label = ''; |
1196 | 1196 | |
1197 | 1197 | $suffix = 'p'; |
1198 | - if($value == 1) { $suffix = 's'; } |
|
1198 | + if ($value == 1) { $suffix = 's'; } |
|
1199 | 1199 | $token .= $suffix; |
1200 | 1200 | |
1201 | - switch($token) { |
|
1201 | + switch ($token) { |
|
1202 | 1202 | case 'ys': $label = t('1 year'); break; |
1203 | 1203 | case 'yp': $label = t('%1$s years', $value); break; |
1204 | 1204 | case 'ms': $label = t('1 month'); break; |
@@ -1216,7 +1216,7 @@ discard block |
||
1216 | 1216 | $parts[] = $label; |
1217 | 1217 | } |
1218 | 1218 | |
1219 | - if(count($parts) == 1) { |
|
1219 | + if (count($parts) == 1) { |
|
1220 | 1220 | return $parts[0]; |
1221 | 1221 | } |
1222 | 1222 | |
@@ -1287,24 +1287,24 @@ discard block |
||
1287 | 1287 | * @see ConvertHelper::INTERVAL_HOURS |
1288 | 1288 | * @see ConvertHelper::INTERVAL_DAYS |
1289 | 1289 | */ |
1290 | - public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) : int |
|
1290 | + public static function interval2total(\DateInterval $interval, $unit = self::INTERVAL_SECONDS) : int |
|
1291 | 1291 | { |
1292 | 1292 | $total = $interval->format('%a'); |
1293 | 1293 | if ($unit == self::INTERVAL_DAYS) { |
1294 | 1294 | return (int)$total; |
1295 | 1295 | } |
1296 | 1296 | |
1297 | - $total = ($total * 24) + ($interval->h ); |
|
1297 | + $total = ($total * 24) + ($interval->h); |
|
1298 | 1298 | if ($unit == self::INTERVAL_HOURS) { |
1299 | 1299 | return (int)$total; |
1300 | 1300 | } |
1301 | 1301 | |
1302 | - $total = ($total * 60) + ($interval->i ); |
|
1302 | + $total = ($total * 60) + ($interval->i); |
|
1303 | 1303 | if ($unit == self::INTERVAL_MINUTES) { |
1304 | 1304 | return (int)$total; |
1305 | 1305 | } |
1306 | 1306 | |
1307 | - $total = ($total * 60) + ($interval->s ); |
|
1307 | + $total = ($total * 60) + ($interval->s); |
|
1308 | 1308 | if ($unit == self::INTERVAL_SECONDS) { |
1309 | 1309 | return (int)$total; |
1310 | 1310 | } |
@@ -1333,13 +1333,13 @@ discard block |
||
1333 | 1333 | * @param string $short |
1334 | 1334 | * @return string|NULL |
1335 | 1335 | */ |
1336 | - public static function date2dayName(\DateTime $date, $short=false) |
|
1336 | + public static function date2dayName(\DateTime $date, $short = false) |
|
1337 | 1337 | { |
1338 | 1338 | $day = $date->format('l'); |
1339 | 1339 | $invariant = self::getDayNamesInvariant(); |
1340 | 1340 | |
1341 | 1341 | $idx = array_search($day, $invariant); |
1342 | - if($idx !== false) { |
|
1342 | + if ($idx !== false) { |
|
1343 | 1343 | $localized = self::getDayNames($short); |
1344 | 1344 | return $localized[$idx]; |
1345 | 1345 | } |
@@ -1362,10 +1362,10 @@ discard block |
||
1362 | 1362 | * @param string $short |
1363 | 1363 | * @return string[] |
1364 | 1364 | */ |
1365 | - public static function getDayNames($short=false) |
|
1365 | + public static function getDayNames($short = false) |
|
1366 | 1366 | { |
1367 | - if($short) { |
|
1368 | - if(!isset(self::$daysShort)) { |
|
1367 | + if ($short) { |
|
1368 | + if (!isset(self::$daysShort)) { |
|
1369 | 1369 | self::$daysShort = array( |
1370 | 1370 | t('Mon'), |
1371 | 1371 | t('Tue'), |
@@ -1380,7 +1380,7 @@ discard block |
||
1380 | 1380 | return self::$daysShort; |
1381 | 1381 | } |
1382 | 1382 | |
1383 | - if(!isset(self::$days)) { |
|
1383 | + if (!isset(self::$days)) { |
|
1384 | 1384 | self::$days = array( |
1385 | 1385 | t('Monday'), |
1386 | 1386 | t('Tuesday'), |
@@ -1405,17 +1405,17 @@ discard block |
||
1405 | 1405 | */ |
1406 | 1406 | public static function implodeWithAnd(array $list, $sep = ', ', $conjunction = null) |
1407 | 1407 | { |
1408 | - if(empty($list)) { |
|
1408 | + if (empty($list)) { |
|
1409 | 1409 | return ''; |
1410 | 1410 | } |
1411 | 1411 | |
1412 | - if(empty($conjunction)) { |
|
1412 | + if (empty($conjunction)) { |
|
1413 | 1413 | $conjunction = t('and'); |
1414 | 1414 | } |
1415 | 1415 | |
1416 | 1416 | $last = array_pop($list); |
1417 | - if($list) { |
|
1418 | - return implode($sep, $list) . $conjunction . ' ' . $last; |
|
1417 | + if ($list) { |
|
1418 | + return implode($sep, $list).$conjunction.' '.$last; |
|
1419 | 1419 | } |
1420 | 1420 | |
1421 | 1421 | return $last; |
@@ -1434,7 +1434,7 @@ discard block |
||
1434 | 1434 | public static function string2array(string $string) : array |
1435 | 1435 | { |
1436 | 1436 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
1437 | - if($result !== false) { |
|
1437 | + if ($result !== false) { |
|
1438 | 1438 | return $result; |
1439 | 1439 | } |
1440 | 1440 | |
@@ -1449,12 +1449,12 @@ discard block |
||
1449 | 1449 | */ |
1450 | 1450 | public static function isStringHTML(string $string) : bool |
1451 | 1451 | { |
1452 | - if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
|
1452 | + if (preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
|
1453 | 1453 | return true; |
1454 | 1454 | } |
1455 | 1455 | |
1456 | 1456 | $decoded = html_entity_decode($string); |
1457 | - if($decoded !== $string) { |
|
1457 | + if ($decoded !== $string) { |
|
1458 | 1458 | return true; |
1459 | 1459 | } |
1460 | 1460 | |
@@ -1591,7 +1591,7 @@ discard block |
||
1591 | 1591 | // extract parameter names from the query string |
1592 | 1592 | $result = array(); |
1593 | 1593 | preg_match_all('/&?([^&]+)=.*/sixU', $queryString, $result, PREG_PATTERN_ORDER); |
1594 | - if(isset($result[1])) { |
|
1594 | + if (isset($result[1])) { |
|
1595 | 1595 | $paramNames = $result[1]; |
1596 | 1596 | } |
1597 | 1597 | |
@@ -1614,11 +1614,11 @@ discard block |
||
1614 | 1614 | // possible naming conflicts like having both parameters "foo.bar" |
1615 | 1615 | // and "foo_bar" in the query string: since "foo.bar" would be converted |
1616 | 1616 | // to "foo_bar", one of the two would be replaced. |
1617 | - if($fixRequired) |
|
1617 | + if ($fixRequired) |
|
1618 | 1618 | { |
1619 | 1619 | $counter = 1; |
1620 | 1620 | $placeholders = array(); |
1621 | - foreach($paramNames as $paramName) |
|
1621 | + foreach ($paramNames as $paramName) |
|
1622 | 1622 | { |
1623 | 1623 | // create a unique placeholder name |
1624 | 1624 | $placeholder = '__PLACEHOLDER'.$counter.'__'; |
@@ -1648,13 +1648,13 @@ discard block |
||
1648 | 1648 | parse_str($queryString, $parsed); |
1649 | 1649 | |
1650 | 1650 | // do any of the parameter names need to be fixed? |
1651 | - if(!$fixRequired) { |
|
1651 | + if (!$fixRequired) { |
|
1652 | 1652 | return $parsed; |
1653 | 1653 | } |
1654 | 1654 | |
1655 | 1655 | $keep = array(); |
1656 | 1656 | |
1657 | - foreach($parsed as $name => $value) |
|
1657 | + foreach ($parsed as $name => $value) |
|
1658 | 1658 | { |
1659 | 1659 | $keep[$table[$name]] = $value; |
1660 | 1660 | } |
@@ -1673,14 +1673,14 @@ discard block |
||
1673 | 1673 | * @param bool $caseInsensitive |
1674 | 1674 | * @return ConvertHelper_StringMatch[] |
1675 | 1675 | */ |
1676 | - public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
|
1676 | + public static function findString(string $needle, string $haystack, bool $caseInsensitive = false) |
|
1677 | 1677 | { |
1678 | - if($needle === '') { |
|
1678 | + if ($needle === '') { |
|
1679 | 1679 | return array(); |
1680 | 1680 | } |
1681 | 1681 | |
1682 | 1682 | $function = 'mb_strpos'; |
1683 | - if($caseInsensitive) { |
|
1683 | + if ($caseInsensitive) { |
|
1684 | 1684 | $function = 'mb_stripos'; |
1685 | 1685 | } |
1686 | 1686 | |
@@ -1688,7 +1688,7 @@ discard block |
||
1688 | 1688 | $positions = array(); |
1689 | 1689 | $length = mb_strlen($needle); |
1690 | 1690 | |
1691 | - while( ($pos = $function($haystack, $needle, $pos)) !== false) |
|
1691 | + while (($pos = $function($haystack, $needle, $pos)) !== false) |
|
1692 | 1692 | { |
1693 | 1693 | $match = mb_substr($haystack, $pos, $length); |
1694 | 1694 | $positions[] = new ConvertHelper_StringMatch($pos, $match); |
@@ -1708,7 +1708,7 @@ discard block |
||
1708 | 1708 | */ |
1709 | 1709 | public static function explodeTrim(string $delimiter, string $string) : array |
1710 | 1710 | { |
1711 | - if(empty($string) || empty($delimiter)) { |
|
1711 | + if (empty($string) || empty($delimiter)) { |
|
1712 | 1712 | return array(); |
1713 | 1713 | } |
1714 | 1714 | |
@@ -1716,8 +1716,8 @@ discard block |
||
1716 | 1716 | $tokens = array_map('trim', $tokens); |
1717 | 1717 | |
1718 | 1718 | $keep = array(); |
1719 | - foreach($tokens as $token) { |
|
1720 | - if($token !== '') { |
|
1719 | + foreach ($tokens as $token) { |
|
1720 | + if ($token !== '') { |
|
1721 | 1721 | $keep[] = $token; |
1722 | 1722 | } |
1723 | 1723 | } |
@@ -1735,11 +1735,11 @@ discard block |
||
1735 | 1735 | */ |
1736 | 1736 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
1737 | 1737 | { |
1738 | - if(empty($subjectString)) { |
|
1738 | + if (empty($subjectString)) { |
|
1739 | 1739 | return null; |
1740 | 1740 | } |
1741 | 1741 | |
1742 | - if(!isset(self::$eolChars)) |
|
1742 | + if (!isset(self::$eolChars)) |
|
1743 | 1743 | { |
1744 | 1744 | $cr = chr((int)hexdec('0d')); |
1745 | 1745 | $lf = chr((int)hexdec('0a')); |
@@ -1770,18 +1770,18 @@ discard block |
||
1770 | 1770 | |
1771 | 1771 | $max = 0; |
1772 | 1772 | $results = array(); |
1773 | - foreach(self::$eolChars as $def) |
|
1773 | + foreach (self::$eolChars as $def) |
|
1774 | 1774 | { |
1775 | 1775 | $amount = substr_count($subjectString, $def['char']); |
1776 | 1776 | |
1777 | - if($amount > $max) |
|
1777 | + if ($amount > $max) |
|
1778 | 1778 | { |
1779 | 1779 | $max = $amount; |
1780 | 1780 | $results[] = $def; |
1781 | 1781 | } |
1782 | 1782 | } |
1783 | 1783 | |
1784 | - if(empty($results)) { |
|
1784 | + if (empty($results)) { |
|
1785 | 1785 | return null; |
1786 | 1786 | } |
1787 | 1787 | |
@@ -1801,9 +1801,9 @@ discard block |
||
1801 | 1801 | */ |
1802 | 1802 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
1803 | 1803 | { |
1804 | - foreach($keys as $key) |
|
1804 | + foreach ($keys as $key) |
|
1805 | 1805 | { |
1806 | - if(array_key_exists($key, $array)) { |
|
1806 | + if (array_key_exists($key, $array)) { |
|
1807 | 1807 | unset($array[$key]); |
1808 | 1808 | } |
1809 | 1809 | } |
@@ -1818,17 +1818,17 @@ discard block |
||
1818 | 1818 | */ |
1819 | 1819 | public static function isInteger($value) : bool |
1820 | 1820 | { |
1821 | - if(is_int($value)) { |
|
1821 | + if (is_int($value)) { |
|
1822 | 1822 | return true; |
1823 | 1823 | } |
1824 | 1824 | |
1825 | 1825 | // booleans get converted to numbers, so they would |
1826 | 1826 | // actually match the regex. |
1827 | - if(is_bool($value)) { |
|
1827 | + if (is_bool($value)) { |
|
1828 | 1828 | return false; |
1829 | 1829 | } |
1830 | 1830 | |
1831 | - if(is_string($value) && $value !== '') { |
|
1831 | + if (is_string($value) && $value !== '') { |
|
1832 | 1832 | return preg_match('/\A-?\d+\z/', $value) === 1; |
1833 | 1833 | } |
1834 | 1834 |
@@ -95,20 +95,20 @@ discard block |
||
95 | 95 | $quoteStyle = array_shift($params); |
96 | 96 | $method = array_shift($params); |
97 | 97 | |
98 | - $call = $method . '('; |
|
98 | + $call = $method.'('; |
|
99 | 99 | |
100 | 100 | $total = count($params); |
101 | - if($total > 0) { |
|
102 | - for($i=0; $i < $total; $i++) |
|
101 | + if ($total > 0) { |
|
102 | + for ($i = 0; $i < $total; $i++) |
|
103 | 103 | { |
104 | 104 | $call .= self::phpVariable2JS($params[$i], $quoteStyle); |
105 | - if($i < ($total-1)) { |
|
105 | + if ($i < ($total - 1)) { |
|
106 | 106 | $call .= ','; |
107 | 107 | } |
108 | 108 | } |
109 | 109 | } |
110 | 110 | |
111 | - return $call . ');'; |
|
111 | + return $call.');'; |
|
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | */ |
133 | 133 | public static function buildVariable(string $varName, $varValue) : string |
134 | 134 | { |
135 | - return $varName . "=" . self::phpVariable2JS($varValue) . ';'; |
|
135 | + return $varName."=".self::phpVariable2JS($varValue).';'; |
|
136 | 136 | } |
137 | 137 | |
138 | 138 | /** |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | * @param int $quoteStyle The quote style to use for strings |
145 | 145 | * @return string |
146 | 146 | */ |
147 | - public static function phpVariable2JS($variable, int $quoteStyle=self::QUOTE_STYLE_DOUBLE) : string |
|
147 | + public static function phpVariable2JS($variable, int $quoteStyle = self::QUOTE_STYLE_DOUBLE) : string |
|
148 | 148 | { |
149 | 149 | // after much profiling, this variant of the method offers |
150 | 150 | // the best performance. Repeat scalar values are cached |
@@ -152,22 +152,22 @@ discard block |
||
152 | 152 | |
153 | 153 | $type = gettype($variable); |
154 | 154 | $hash = null; |
155 | - if(is_scalar($variable) === true) |
|
155 | + if (is_scalar($variable) === true) |
|
156 | 156 | { |
157 | 157 | $hash = $variable; |
158 | 158 | |
159 | - if($hash === true) |
|
159 | + if ($hash === true) |
|
160 | 160 | { |
161 | 161 | $hash = 'true'; |
162 | 162 | } |
163 | - else if($hash === false) |
|
163 | + else if ($hash === false) |
|
164 | 164 | { |
165 | 165 | $hash = 'false'; |
166 | 166 | } |
167 | 167 | |
168 | 168 | $hash .= '-'.$quoteStyle.'-'.$type; |
169 | 169 | |
170 | - if(isset(self::$variableCache[$hash])) { |
|
170 | + if (isset(self::$variableCache[$hash])) { |
|
171 | 171 | return self::$variableCache[$hash]; |
172 | 172 | } |
173 | 173 | } |
@@ -175,19 +175,19 @@ discard block |
||
175 | 175 | $result = 'null'; |
176 | 176 | |
177 | 177 | // one gettype call is better than a strict if-else. |
178 | - switch($type) |
|
178 | + switch ($type) |
|
179 | 179 | { |
180 | 180 | case 'double': |
181 | 181 | case 'string': |
182 | 182 | $string = json_encode($variable); |
183 | 183 | |
184 | - if($string === false) |
|
184 | + if ($string === false) |
|
185 | 185 | { |
186 | 186 | $string = ''; |
187 | 187 | } |
188 | - else if($quoteStyle === self::QUOTE_STYLE_SINGLE) |
|
188 | + else if ($quoteStyle === self::QUOTE_STYLE_SINGLE) |
|
189 | 189 | { |
190 | - $string = mb_substr($string, 1, mb_strlen($string)-2); |
|
190 | + $string = mb_substr($string, 1, mb_strlen($string) - 2); |
|
191 | 191 | $string = "'".str_replace("'", "\'", $string)."'"; |
192 | 192 | } |
193 | 193 | |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | break; |
196 | 196 | |
197 | 197 | case 'boolean': |
198 | - if($variable === true) { |
|
198 | + if ($variable === true) { |
|
199 | 199 | $result = 'true'; |
200 | 200 | } else { |
201 | 201 | $result = 'false'; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | } |
214 | 214 | |
215 | 215 | // cache cacheable values |
216 | - if($hash !== null) |
|
216 | + if ($hash !== null) |
|
217 | 217 | { |
218 | 218 | self::$variableCache[$hash] = $result; |
219 | 219 | } |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | { |
246 | 246 | self::$elementCounter++; |
247 | 247 | |
248 | - return self::$idPrefix . self::$elementCounter; |
|
248 | + return self::$idPrefix.self::$elementCounter; |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | /** |
@@ -319,7 +319,7 @@ discard block |
||
319 | 319 | * @see JSHelper::JS_REGEX_OBJECT |
320 | 320 | * @see JSHelper::JS_REGEX_JSON |
321 | 321 | */ |
322 | - public static function buildRegexStatement(string $regex, string $statementType=self::JS_REGEX_OBJECT) : string |
|
322 | + public static function buildRegexStatement(string $regex, string $statementType = self::JS_REGEX_OBJECT) : string |
|
323 | 323 | { |
324 | 324 | $regex = trim($regex); |
325 | 325 | $separator = substr($regex, 0, 1); |
@@ -327,7 +327,7 @@ discard block |
||
327 | 327 | array_shift($parts); |
328 | 328 | |
329 | 329 | $modifiers = array_pop($parts); |
330 | - if($modifiers == $separator) { |
|
330 | + if ($modifiers == $separator) { |
|
331 | 331 | $modifiers = ''; |
332 | 332 | } |
333 | 333 | |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | // convert the anchors that are not supported in js regexes |
344 | 344 | $format = str_replace(array('\\A', '\\Z', '\\z'), array('^', '$', ''), $format); |
345 | 345 | |
346 | - if($statementType==self::JS_REGEX_JSON) |
|
346 | + if ($statementType == self::JS_REGEX_JSON) |
|
347 | 347 | { |
348 | 348 | return ConvertHelper::var2json(array( |
349 | 349 | 'format' => $format, |
@@ -351,7 +351,7 @@ discard block |
||
351 | 351 | )); |
352 | 352 | } |
353 | 353 | |
354 | - if(!empty($modifiers)) { |
|
354 | + if (!empty($modifiers)) { |
|
355 | 355 | return sprintf( |
356 | 356 | 'new RegExp(%s, %s)', |
357 | 357 | ConvertHelper::var2json($format), |