Passed
Push — master ( 2dea8c...1a0534 )
by Sebastian
02:34
created
src/ConvertHelper.php 3 patches
Indentation   +371 added lines, -371 removed lines patch added patch discarded remove patch
@@ -424,16 +424,16 @@  discard block
 block discarded – undo
424 424
         return $bytes . ' ' . t('B');
425 425
     }
426 426
 
427
-   /**
428
-    * Cuts a text to the specified length if it is longer than the
429
-    * target length. Appends a text to signify it has been cut at 
430
-    * the end of the string.
431
-    * 
432
-    * @param string $text
433
-    * @param int $targetLength
434
-    * @param string $append
435
-    * @return string
436
-    */
427
+    /**
428
+     * Cuts a text to the specified length if it is longer than the
429
+     * target length. Appends a text to signify it has been cut at 
430
+     * the end of the string.
431
+     * 
432
+     * @param string $text
433
+     * @param int $targetLength
434
+     * @param string $append
435
+     * @return string
436
+     */
437 437
     public static function text_cut(string $text, int $targetLength, string $append = '...') : string
438 438
     {
439 439
         $length = mb_strlen($text);
@@ -503,27 +503,27 @@  discard block
 block discarded – undo
503 503
         return self::$booleanStrings[$string];
504 504
     }
505 505
     
506
-   /**
507
-    * Whether the specified string is a boolean string or boolean value.
508
-    * Alias for {@link ConvertHelper::isBoolean()}.
509
-    * 
510
-    * @param mixed $string
511
-    * @return bool
512
-    * @deprecated
513
-    * @see ConvertHelper::isBoolean()
514
-    */
506
+    /**
507
+     * Whether the specified string is a boolean string or boolean value.
508
+     * Alias for {@link ConvertHelper::isBoolean()}.
509
+     * 
510
+     * @param mixed $string
511
+     * @return bool
512
+     * @deprecated
513
+     * @see ConvertHelper::isBoolean()
514
+     */
515 515
     public static function isBooleanString($string) : bool
516 516
     {
517 517
         return self::isBoolean($string);
518 518
     }
519 519
 
520
-   /**
521
-    * Alias for the {@\AppUtils\XMLHelper::string2xml()} method.
522
-    * 
523
-    * @param string $text
524
-    * @return string
525
-    * @deprecated
526
-    */
520
+    /**
521
+     * Alias for the {@\AppUtils\XMLHelper::string2xml()} method.
522
+     * 
523
+     * @param string $text
524
+     * @return string
525
+     * @deprecated
526
+     */
527 527
     public static function text_makeXMLCompliant($text)
528 528
     {
529 529
         return XMLHelper::string2xml($text);
@@ -625,13 +625,13 @@  discard block
 block discarded – undo
625 625
         return $translit->convert($string);
626 626
     }
627 627
     
628
-   /**
629
-    * Retrieves the HEX character codes for all control
630
-    * characters that the {@link stripControlCharacters()} 
631
-    * method will remove.
632
-    * 
633
-    * @return string[]
634
-    */
628
+    /**
629
+     * Retrieves the HEX character codes for all control
630
+     * characters that the {@link stripControlCharacters()} 
631
+     * method will remove.
632
+     * 
633
+     * @return string[]
634
+     */
635 635
     public static function getControlCharactersAsHex()
636 636
     {
637 637
         $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
@@ -667,13 +667,13 @@  discard block
 block discarded – undo
667 667
         return $stack;
668 668
     }
669 669
     
670
-   /**
671
-    * Retrieves an array of all control characters that
672
-    * the {@link stripControlCharacters()} method will 
673
-    * remove, as the actual UTF-8 characters.
674
-    * 
675
-    * @return string[]
676
-    */
670
+    /**
671
+     * Retrieves an array of all control characters that
672
+     * the {@link stripControlCharacters()} method will 
673
+     * remove, as the actual UTF-8 characters.
674
+     * 
675
+     * @return string[]
676
+     */
677 677
     public static function getControlCharactersAsUTF8()
678 678
     {
679 679
         $chars = self::getControlCharactersAsHex();
@@ -686,12 +686,12 @@  discard block
 block discarded – undo
686 686
         return $result;
687 687
     }
688 688
     
689
-   /**
690
-    * Retrieves all control characters as JSON encoded
691
-    * characters, e.g. "\u200b".
692
-    * 
693
-    * @return string[]
694
-    */
689
+    /**
690
+     * Retrieves all control characters as JSON encoded
691
+     * characters, e.g. "\u200b".
692
+     * 
693
+     * @return string[]
694
+     */
695 695
     public static function getControlCharactersAsJSON()
696 696
     {
697 697
         $chars = self::getControlCharactersAsHex();
@@ -748,20 +748,20 @@  discard block
 block discarded – undo
748 748
         return preg_replace(self::$controlCharsRegex, '', $string);
749 749
     }
750 750
 
751
-   /**
752
-    * Converts a unicode character to the PHPO notation.
753
-    * 
754
-    * Example:
755
-    * 
756
-    * <pre>unicodeChar2php('"\u0000"')</pre>
757
-    * 
758
-    * Returns
759
-    * 
760
-    * <pre>\x0</pre>
761
-    * 
762
-    * @param string $unicodeChar
763
-    * @return string
764
-    */
751
+    /**
752
+     * Converts a unicode character to the PHPO notation.
753
+     * 
754
+     * Example:
755
+     * 
756
+     * <pre>unicodeChar2php('"\u0000"')</pre>
757
+     * 
758
+     * Returns
759
+     * 
760
+     * <pre>\x0</pre>
761
+     * 
762
+     * @param string $unicodeChar
763
+     * @return string
764
+     */
765 765
     public static function unicodeChar2php($unicodeChar) 
766 766
     {
767 767
         $unicodeChar = json_decode($unicodeChar);
@@ -884,25 +884,25 @@  discard block
 block discarded – undo
884 884
         return 'false';
885 885
     }
886 886
     
887
-   /**
888
-    * Converts an associative array with attribute name > value pairs
889
-    * to an attribute string that can be used in an HTML tag. Empty 
890
-    * attribute values are ignored.
891
-    * 
892
-    * Example:
893
-    * 
894
-    * array2attributeString(array(
895
-    *     'id' => 45,
896
-    *     'href' => 'http://www.mistralys.com'
897
-    * ));
898
-    * 
899
-    * Result:
900
-    * 
901
-    * id="45" href="http://www.mistralys.com"
902
-    * 
903
-    * @param array $array
904
-    * @return string
905
-    */
887
+    /**
888
+     * Converts an associative array with attribute name > value pairs
889
+     * to an attribute string that can be used in an HTML tag. Empty 
890
+     * attribute values are ignored.
891
+     * 
892
+     * Example:
893
+     * 
894
+     * array2attributeString(array(
895
+     *     'id' => 45,
896
+     *     'href' => 'http://www.mistralys.com'
897
+     * ));
898
+     * 
899
+     * Result:
900
+     * 
901
+     * id="45" href="http://www.mistralys.com"
902
+     * 
903
+     * @param array $array
904
+     * @return string
905
+     */
906 906
     public static function array2attributeString($array)
907 907
     {
908 908
         $tokens = array();
@@ -921,14 +921,14 @@  discard block
 block discarded – undo
921 921
         return ' '.implode(' ', $tokens);
922 922
     }
923 923
     
924
-   /**
925
-    * Converts a string so it can safely be used in a javascript
926
-    * statement in an HTML tag: uses single quotes around the string
927
-    * and encodes all special characters as needed.
928
-    * 
929
-    * @param string $string
930
-    * @return string
931
-    */
924
+    /**
925
+     * Converts a string so it can safely be used in a javascript
926
+     * statement in an HTML tag: uses single quotes around the string
927
+     * and encodes all special characters as needed.
928
+     * 
929
+     * @param string $string
930
+     * @return string
931
+     */
932 932
     public static function string2attributeJS($string, $quoted=true)
933 933
     {
934 934
         $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8'));
@@ -939,15 +939,15 @@  discard block
 block discarded – undo
939 939
         return $converted;
940 940
     }
941 941
     
942
-   /**
943
-    * Checks if the specified string is a boolean value, which
944
-    * includes string representations of boolean values, like 
945
-    * <code>yes</code> or <code>no</code>, and <code>true</code>
946
-    * or <code>false</code>.
947
-    * 
948
-    * @param mixed $value
949
-    * @return boolean
950
-    */
942
+    /**
943
+     * Checks if the specified string is a boolean value, which
944
+     * includes string representations of boolean values, like 
945
+     * <code>yes</code> or <code>no</code>, and <code>true</code>
946
+     * or <code>false</code>.
947
+     * 
948
+     * @param mixed $value
949
+     * @return boolean
950
+     */
951 951
     public static function isBoolean($value) : bool
952 952
     {
953 953
         if(is_bool($value)) {
@@ -961,12 +961,12 @@  discard block
 block discarded – undo
961 961
         return array_key_exists($value, self::$booleanStrings);
962 962
     }
963 963
     
964
-   /**
965
-    * Converts an associative array to an HTML style attribute value string.
966
-    * 
967
-    * @param array $subject
968
-    * @return string
969
-    */
964
+    /**
965
+     * Converts an associative array to an HTML style attribute value string.
966
+     * 
967
+     * @param array $subject
968
+     * @return string
969
+     */
970 970
     public static function array2styleString(array $subject) : string
971 971
     {
972 972
         $tokens = array();
@@ -977,23 +977,23 @@  discard block
 block discarded – undo
977 977
         return implode(';', $tokens);
978 978
     }
979 979
     
980
-   /**
981
-    * Converts a DateTime object to a timestamp, which
982
-    * is PHP 5.2 compatible.
983
-    * 
984
-    * @param \DateTime $date
985
-    * @return integer
986
-    */
980
+    /**
981
+     * Converts a DateTime object to a timestamp, which
982
+     * is PHP 5.2 compatible.
983
+     * 
984
+     * @param \DateTime $date
985
+     * @return integer
986
+     */
987 987
     public static function date2timestamp(\DateTime $date) : int
988 988
     {
989 989
         return (int)$date->format('U');
990 990
     }
991 991
     
992
-   /**
993
-    * Converts a timestamp into a DateTime instance.
994
-    * @param int $timestamp
995
-    * @return \DateTime
996
-    */
992
+    /**
993
+     * Converts a timestamp into a DateTime instance.
994
+     * @param int $timestamp
995
+     * @return \DateTime
996
+     */
997 997
     public static function timestamp2date(int $timestamp) : \DateTime
998 998
     {
999 999
         $date = new \DateTime();
@@ -1001,50 +1001,50 @@  discard block
 block discarded – undo
1001 1001
         return $date;
1002 1002
     }
1003 1003
     
1004
-   /**
1005
-    * Strips an absolute path to a file within the application
1006
-    * to make the path relative to the application root path.
1007
-    * 
1008
-    * @param string $path
1009
-    * @return string
1010
-    * 
1011
-    * @see FileHelper::relativizePath()
1012
-    * @see FileHelper::relativizePathByDepth()
1013
-    */
1004
+    /**
1005
+     * Strips an absolute path to a file within the application
1006
+     * to make the path relative to the application root path.
1007
+     * 
1008
+     * @param string $path
1009
+     * @return string
1010
+     * 
1011
+     * @see FileHelper::relativizePath()
1012
+     * @see FileHelper::relativizePathByDepth()
1013
+     */
1014 1014
     public static function fileRelativize(string $path) : string
1015 1015
     {
1016 1016
         return FileHelper::relativizePathByDepth($path);
1017 1017
     }
1018 1018
     
1019 1019
     /**
1020
-    * Converts a PHP regex to a javascript RegExp object statement.
1021
-    * 
1022
-    * NOTE: This is an alias for the JSHelper's `convertRegex` method. 
1023
-    * More details are available on its usage there.
1024
-    *
1025
-    * @param string $regex A PHP preg regex
1026
-    * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object.
1027
-    * @return array|string Depending on the specified return type.
1028
-    * 
1029
-    * @see JSHelper::buildRegexStatement()
1030
-    */
1020
+     * Converts a PHP regex to a javascript RegExp object statement.
1021
+     * 
1022
+     * NOTE: This is an alias for the JSHelper's `convertRegex` method. 
1023
+     * More details are available on its usage there.
1024
+     *
1025
+     * @param string $regex A PHP preg regex
1026
+     * @param string $statementType The type of statement to return: Defaults to a statement to create a RegExp object.
1027
+     * @return array|string Depending on the specified return type.
1028
+     * 
1029
+     * @see JSHelper::buildRegexStatement()
1030
+     */
1031 1031
     public static function regex2js(string $regex, string $statementType=JSHelper::JS_REGEX_OBJECT)
1032 1032
     {
1033 1033
         return JSHelper::buildRegexStatement($regex, $statementType);
1034 1034
     }
1035 1035
     
1036
-   /**
1037
-    * Converts the specified variable to JSON. Works just
1038
-    * like the native `json_encode` method, except that it
1039
-    * will trigger an exception on failure, which has the 
1040
-    * json error details included in its developer details.
1041
-    * 
1042
-    * @param mixed $variable
1043
-    * @param int|NULL $options JSON encode options.
1044
-    * @param int|NULL $depth 
1045
-    * @throws ConvertHelper_Exception
1046
-    * @return string
1047
-    */
1036
+    /**
1037
+     * Converts the specified variable to JSON. Works just
1038
+     * like the native `json_encode` method, except that it
1039
+     * will trigger an exception on failure, which has the 
1040
+     * json error details included in its developer details.
1041
+     * 
1042
+     * @param mixed $variable
1043
+     * @param int|NULL $options JSON encode options.
1044
+     * @param int|NULL $depth 
1045
+     * @throws ConvertHelper_Exception
1046
+     * @return string
1047
+     */
1048 1048
     public static function var2json($variable, int $options=0, int $depth=512) : string
1049 1049
     {
1050 1050
         $result = json_encode($variable, $options, $depth);
@@ -1065,12 +1065,12 @@  discard block
 block discarded – undo
1065 1065
         );
1066 1066
     }
1067 1067
     
1068
-   /**
1069
-    * Strips all known UTF byte order marks from the specified string.
1070
-    * 
1071
-    * @param string $string
1072
-    * @return string
1073
-    */
1068
+    /**
1069
+     * Strips all known UTF byte order marks from the specified string.
1070
+     * 
1071
+     * @param string $string
1072
+     * @return string
1073
+     */
1074 1074
     public static function stripUTFBom($string)
1075 1075
     {
1076 1076
         $boms = FileHelper::getUTFBOMs();
@@ -1085,13 +1085,13 @@  discard block
 block discarded – undo
1085 1085
         return $string;
1086 1086
     }
1087 1087
 
1088
-   /**
1089
-    * Converts a string to valid utf8, regardless
1090
-    * of the string's encoding(s).
1091
-    * 
1092
-    * @param string $string
1093
-    * @return string
1094
-    */
1088
+    /**
1089
+     * Converts a string to valid utf8, regardless
1090
+     * of the string's encoding(s).
1091
+     * 
1092
+     * @param string $string
1093
+     * @return string
1094
+     */
1095 1095
     public static function string2utf8($string)
1096 1096
     {
1097 1097
         if(!self::isStringASCII($string)) {
@@ -1101,15 +1101,15 @@  discard block
 block discarded – undo
1101 1101
         return $string;
1102 1102
     }
1103 1103
     
1104
-   /**
1105
-    * Checks whether the specified string is an ASCII
1106
-    * string, without any special or UTF8 characters.
1107
-    * Note: empty strings and NULL are considered ASCII.
1108
-    * Any variable types other than strings are not.
1109
-    * 
1110
-    * @param string $string
1111
-    * @return boolean
1112
-    */
1104
+    /**
1105
+     * Checks whether the specified string is an ASCII
1106
+     * string, without any special or UTF8 characters.
1107
+     * Note: empty strings and NULL are considered ASCII.
1108
+     * Any variable types other than strings are not.
1109
+     * 
1110
+     * @param string $string
1111
+     * @return boolean
1112
+     */
1113 1113
     public static function isStringASCII($string)
1114 1114
     {
1115 1115
         if($string === '' || $string === NULL) {
@@ -1134,22 +1134,22 @@  discard block
 block discarded – undo
1134 1134
         return $url;
1135 1135
     }
1136 1136
 
1137
-   /**
1138
-    * Calculates a percentage match of the source string with the target string.
1139
-    * 
1140
-    * Options are:
1141
-    * 
1142
-    * - maxLevenshtein, default: 10
1143
-    *   Any levenshtein results above this value are ignored.
1144
-    *   
1145
-    * - precision, default: 1
1146
-    *   The precision of the percentage float value
1147
-    * 
1148
-    * @param string $source
1149
-    * @param string $target
1150
-    * @param array $options
1151
-    * @return float
1152
-    */
1137
+    /**
1138
+     * Calculates a percentage match of the source string with the target string.
1139
+     * 
1140
+     * Options are:
1141
+     * 
1142
+     * - maxLevenshtein, default: 10
1143
+     *   Any levenshtein results above this value are ignored.
1144
+     *   
1145
+     * - precision, default: 1
1146
+     *   The precision of the percentage float value
1147
+     * 
1148
+     * @param string $source
1149
+     * @param string $target
1150
+     * @param array $options
1151
+     * @return float
1152
+     */
1153 1153
     public static function matchString($source, $target, $options=array())
1154 1154
     {
1155 1155
         $defaults = array(
@@ -1233,60 +1233,60 @@  discard block
 block discarded – undo
1233 1233
     
1234 1234
     const INTERVAL_SECONDS = 'seconds';
1235 1235
     
1236
-   /**
1237
-    * Converts an interval to its total amount of days.
1238
-    * @param \DateInterval $interval
1239
-    * @return int
1240
-    */
1236
+    /**
1237
+     * Converts an interval to its total amount of days.
1238
+     * @param \DateInterval $interval
1239
+     * @return int
1240
+     */
1241 1241
     public static function interval2days(\DateInterval $interval) : int
1242 1242
     {
1243 1243
         return self::interval2total($interval, self::INTERVAL_DAYS);
1244 1244
     }
1245 1245
 
1246
-   /**
1247
-    * Converts an interval to its total amount of hours.
1248
-    * @param \DateInterval $interval
1249
-    * @return int
1250
-    */
1246
+    /**
1247
+     * Converts an interval to its total amount of hours.
1248
+     * @param \DateInterval $interval
1249
+     * @return int
1250
+     */
1251 1251
     public static function interval2hours(\DateInterval $interval) : int
1252 1252
     {
1253 1253
         return self::interval2total($interval, self::INTERVAL_HOURS);
1254 1254
     }
1255 1255
     
1256
-   /**
1257
-    * Converts an interval to its total amount of minutes. 
1258
-    * @param \DateInterval $interval
1259
-    * @return int
1260
-    */
1256
+    /**
1257
+     * Converts an interval to its total amount of minutes. 
1258
+     * @param \DateInterval $interval
1259
+     * @return int
1260
+     */
1261 1261
     public static function interval2minutes(\DateInterval $interval) : int
1262 1262
     {
1263 1263
         return self::interval2total($interval, self::INTERVAL_MINUTES);
1264 1264
     }
1265 1265
     
1266
-   /**
1267
-    * Converts an interval to its total amount of seconds.
1268
-    * @param \DateInterval $interval
1269
-    * @return int
1270
-    */    
1266
+    /**
1267
+     * Converts an interval to its total amount of seconds.
1268
+     * @param \DateInterval $interval
1269
+     * @return int
1270
+     */    
1271 1271
     public static function interval2seconds(\DateInterval $interval) : int
1272 1272
     {
1273 1273
         return self::interval2total($interval, self::INTERVAL_SECONDS);
1274 1274
     }
1275 1275
     
1276
-   /**
1277
-    * Calculates the total amount of days / hours / minutes or seconds
1278
-    * of a date interval object (depending in the specified units), and 
1279
-    * returns the total amount.
1280
-    * 
1281
-    * @param \DateInterval $interval
1282
-    * @param string $unit What total value to calculate.
1283
-    * @return integer
1284
-    * 
1285
-    * @see ConvertHelper::INTERVAL_SECONDS
1286
-    * @see ConvertHelper::INTERVAL_MINUTES
1287
-    * @see ConvertHelper::INTERVAL_HOURS
1288
-    * @see ConvertHelper::INTERVAL_DAYS
1289
-    */
1276
+    /**
1277
+     * Calculates the total amount of days / hours / minutes or seconds
1278
+     * of a date interval object (depending in the specified units), and 
1279
+     * returns the total amount.
1280
+     * 
1281
+     * @param \DateInterval $interval
1282
+     * @param string $unit What total value to calculate.
1283
+     * @return integer
1284
+     * 
1285
+     * @see ConvertHelper::INTERVAL_SECONDS
1286
+     * @see ConvertHelper::INTERVAL_MINUTES
1287
+     * @see ConvertHelper::INTERVAL_HOURS
1288
+     * @see ConvertHelper::INTERVAL_DAYS
1289
+     */
1290 1290
     public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) : int
1291 1291
     {
1292 1292
         $total = $interval->format('%a');
@@ -1326,13 +1326,13 @@  discard block
 block discarded – undo
1326 1326
         'Sunday'
1327 1327
     );
1328 1328
     
1329
-   /**
1330
-    * Converts a date to the corresponding day name.
1331
-    * 
1332
-    * @param \DateTime $date
1333
-    * @param string $short
1334
-    * @return string|NULL
1335
-    */
1329
+    /**
1330
+     * Converts a date to the corresponding day name.
1331
+     * 
1332
+     * @param \DateTime $date
1333
+     * @param string $short
1334
+     * @return string|NULL
1335
+     */
1336 1336
     public static function date2dayName(\DateTime $date, $short=false)
1337 1337
     {
1338 1338
         $day = $date->format('l');
@@ -1347,21 +1347,21 @@  discard block
 block discarded – undo
1347 1347
         return null;
1348 1348
     }
1349 1349
     
1350
-   /**
1351
-    * Retrieves a list of english day names.
1352
-    * @return string[]
1353
-    */
1350
+    /**
1351
+     * Retrieves a list of english day names.
1352
+     * @return string[]
1353
+     */
1354 1354
     public static function getDayNamesInvariant()
1355 1355
     {
1356 1356
         return self::$daysInvariant;
1357 1357
     }
1358 1358
     
1359
-   /**
1360
-    * Retrieves the day names list for the current locale.
1361
-    * 
1362
-    * @param string $short
1363
-    * @return string[]
1364
-    */
1359
+    /**
1360
+     * Retrieves the day names list for the current locale.
1361
+     * 
1362
+     * @param string $short
1363
+     * @return string[]
1364
+     */
1365 1365
     public static function getDayNames($short=false)
1366 1366
     {
1367 1367
         if($short) {
@@ -1421,16 +1421,16 @@  discard block
 block discarded – undo
1421 1421
         return $last;
1422 1422
     }
1423 1423
     
1424
-   /**
1425
-    * Splits a string into an array of all characters it is composed of.
1426
-    * Unicode character safe.
1427
-    * 
1428
-    * NOTE: Spaces and newlines (both \r and \n) are also considered single
1429
-    * characters.
1430
-    * 
1431
-    * @param string $string
1432
-    * @return array
1433
-    */
1424
+    /**
1425
+     * Splits a string into an array of all characters it is composed of.
1426
+     * Unicode character safe.
1427
+     * 
1428
+     * NOTE: Spaces and newlines (both \r and \n) are also considered single
1429
+     * characters.
1430
+     * 
1431
+     * @param string $string
1432
+     * @return array
1433
+     */
1434 1434
     public static function string2array(string $string) : array
1435 1435
     {
1436 1436
         $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY);
@@ -1441,12 +1441,12 @@  discard block
 block discarded – undo
1441 1441
         return array();
1442 1442
     }
1443 1443
     
1444
-   /**
1445
-    * Checks whether the specified string contains HTML code.
1446
-    * 
1447
-    * @param string $string
1448
-    * @return boolean
1449
-    */
1444
+    /**
1445
+     * Checks whether the specified string contains HTML code.
1446
+     * 
1447
+     * @param string $string
1448
+     * @return boolean
1449
+     */
1450 1450
     public static function isStringHTML(string $string) : bool
1451 1451
     {
1452 1452
         if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) {
@@ -1461,18 +1461,18 @@  discard block
 block discarded – undo
1461 1461
         return false;
1462 1462
     }
1463 1463
     
1464
-   /**
1465
-    * UTF8-safe wordwrap method: works like the regular wordwrap
1466
-    * PHP function but compatible with UTF8. Otherwise the lengths
1467
-    * are no calculated correctly.
1468
-    * 
1469
-    * @param string $str
1470
-    * @param int $width
1471
-    * @param string $break
1472
-    * @param bool $cut
1473
-    * @return string
1474
-    * @see https://stackoverflow.com/a/4988494/2298192
1475
-    */
1464
+    /**
1465
+     * UTF8-safe wordwrap method: works like the regular wordwrap
1466
+     * PHP function but compatible with UTF8. Otherwise the lengths
1467
+     * are no calculated correctly.
1468
+     * 
1469
+     * @param string $str
1470
+     * @param int $width
1471
+     * @param string $break
1472
+     * @param bool $cut
1473
+     * @return string
1474
+     * @see https://stackoverflow.com/a/4988494/2298192
1475
+     */
1476 1476
     public static function wordwrap($str, $width = 75, $break = "\n", $cut = false) 
1477 1477
     {
1478 1478
         $lines = explode($break, $str);
@@ -1518,27 +1518,27 @@  discard block
 block discarded – undo
1518 1518
         return implode($break, $lines);
1519 1519
     }
1520 1520
     
1521
-   /**
1522
-    * Calculates the byte length of a string, taking into 
1523
-    * account any unicode characters.
1524
-    * 
1525
-    * @param string $string
1526
-    * @return int
1527
-    * @see https://stackoverflow.com/a/9718273/2298192
1528
-    */
1521
+    /**
1522
+     * Calculates the byte length of a string, taking into 
1523
+     * account any unicode characters.
1524
+     * 
1525
+     * @param string $string
1526
+     * @return int
1527
+     * @see https://stackoverflow.com/a/9718273/2298192
1528
+     */
1529 1529
     public static function string2bytes($string)
1530 1530
     {
1531 1531
         return mb_strlen($string, '8bit');
1532 1532
     }
1533 1533
     
1534
-   /**
1535
-    * Creates a short, 8-character long hash for the specified string.
1536
-    * 
1537
-    * WARNING: Not cryptographically safe.
1538
-    * 
1539
-    * @param string $string
1540
-    * @return string
1541
-    */
1534
+    /**
1535
+     * Creates a short, 8-character long hash for the specified string.
1536
+     * 
1537
+     * WARNING: Not cryptographically safe.
1538
+     * 
1539
+     * @param string $string
1540
+     * @return string
1541
+     */
1542 1542
     public static function string2shortHash($string)
1543 1543
     {
1544 1544
         return hash('crc32', $string, false);
@@ -1564,23 +1564,23 @@  discard block
 block discarded – undo
1564 1564
         return ConvertHelper_ThrowableInfo::fromThrowable($e);
1565 1565
     }
1566 1566
     
1567
-   /**
1568
-    * Parses the specified query string like the native 
1569
-    * function <code>parse_str</code>, without the key
1570
-    * naming limitations.
1571
-    * 
1572
-    * Using parse_str, dots or spaces in key names are 
1573
-    * replaced by underscores. This method keeps all names
1574
-    * intact.
1575
-    * 
1576
-    * It still uses the parse_str implementation as it 
1577
-    * is tested and tried, but fixes the parameter names
1578
-    * after parsing, as needed.
1579
-    * 
1580
-    * @param string $queryString
1581
-    * @return array
1582
-    * @see https://www.php.net/manual/en/function.parse-str.php
1583
-    */
1567
+    /**
1568
+     * Parses the specified query string like the native 
1569
+     * function <code>parse_str</code>, without the key
1570
+     * naming limitations.
1571
+     * 
1572
+     * Using parse_str, dots or spaces in key names are 
1573
+     * replaced by underscores. This method keeps all names
1574
+     * intact.
1575
+     * 
1576
+     * It still uses the parse_str implementation as it 
1577
+     * is tested and tried, but fixes the parameter names
1578
+     * after parsing, as needed.
1579
+     * 
1580
+     * @param string $queryString
1581
+     * @return array
1582
+     * @see https://www.php.net/manual/en/function.parse-str.php
1583
+     */
1584 1584
     public static function parseQueryString(string $queryString) : array
1585 1585
     {
1586 1586
         // allow HTML entities notation
@@ -1620,16 +1620,16 @@  discard block
 block discarded – undo
1620 1620
             $placeholders = array();
1621 1621
             foreach($paramNames as $paramName)
1622 1622
             {
1623
-                 // create a unique placeholder name
1624
-                 $placeholder = '__PLACEHOLDER'.$counter.'__';
1623
+                    // create a unique placeholder name
1624
+                    $placeholder = '__PLACEHOLDER'.$counter.'__';
1625 1625
                  
1626
-                 // store the placeholder name to replace later
1627
-                 $table[$placeholder] = $paramName;
1626
+                    // store the placeholder name to replace later
1627
+                    $table[$placeholder] = $paramName;
1628 1628
                  
1629
-                 // add the placeholder to replace in the query string before parsing
1630
-                 $placeholders[$paramName.'='] = $placeholder.'=';
1629
+                    // add the placeholder to replace in the query string before parsing
1630
+                    $placeholders[$paramName.'='] = $placeholder.'=';
1631 1631
                  
1632
-                 $counter++;
1632
+                    $counter++;
1633 1633
             }
1634 1634
             
1635 1635
             // next challenge: replacing the parameter names by placeholders
@@ -1656,23 +1656,23 @@  discard block
 block discarded – undo
1656 1656
         
1657 1657
         foreach($parsed as $name => $value)
1658 1658
         {
1659
-             $keep[$table[$name]] = $value;
1659
+                $keep[$table[$name]] = $value;
1660 1660
         }
1661 1661
         
1662 1662
         return $keep;
1663 1663
     }
1664 1664
 
1665
-   /**
1666
-    * Searches for needle in the specified string, and returns a list
1667
-    * of all occurrences, including the matched string. The matched 
1668
-    * string is useful when doing a case insensitive search, as it 
1669
-    * shows the exact matched case of needle.
1670
-    *   
1671
-    * @param string $needle
1672
-    * @param string $haystack
1673
-    * @param bool $caseInsensitive
1674
-    * @return ConvertHelper_StringMatch[]
1675
-    */
1665
+    /**
1666
+     * Searches for needle in the specified string, and returns a list
1667
+     * of all occurrences, including the matched string. The matched 
1668
+     * string is useful when doing a case insensitive search, as it 
1669
+     * shows the exact matched case of needle.
1670
+     *   
1671
+     * @param string $needle
1672
+     * @param string $haystack
1673
+     * @param bool $caseInsensitive
1674
+     * @return ConvertHelper_StringMatch[]
1675
+     */
1676 1676
     public static function findString(string $needle, string $haystack, bool $caseInsensitive=false)
1677 1677
     {
1678 1678
         if($needle === '') {
@@ -1698,14 +1698,14 @@  discard block
 block discarded – undo
1698 1698
         return $positions;
1699 1699
     }
1700 1700
     
1701
-   /**
1702
-    * Like explode, but trims all entries, and removes 
1703
-    * empty entries from the resulting array.
1704
-    * 
1705
-    * @param string $delimiter
1706
-    * @param string $string
1707
-    * @return string[]
1708
-    */
1701
+    /**
1702
+     * Like explode, but trims all entries, and removes 
1703
+     * empty entries from the resulting array.
1704
+     * 
1705
+     * @param string $delimiter
1706
+     * @param string $string
1707
+     * @return string[]
1708
+     */
1709 1709
     public static function explodeTrim(string $delimiter, string $string) : array
1710 1710
     {
1711 1711
         if(empty($string) || empty($delimiter)) {
@@ -1727,12 +1727,12 @@  discard block
 block discarded – undo
1727 1727
     
1728 1728
     protected static $eolChars;
1729 1729
 
1730
-   /**
1731
-    * Detects the most used end-of-line character in the subject string.
1732
-    * 
1733
-    * @param string $str The string to check.
1734
-    * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected.
1735
-    */
1730
+    /**
1731
+     * Detects the most used end-of-line character in the subject string.
1732
+     * 
1733
+     * @param string $str The string to check.
1734
+     * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected.
1735
+     */
1736 1736
     public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL
1737 1737
     {
1738 1738
         if(empty($subjectString)) {
@@ -1744,27 +1744,27 @@  discard block
 block discarded – undo
1744 1744
             $cr = chr((int)hexdec('0d'));
1745 1745
             $lf = chr((int)hexdec('0a'));
1746 1746
             
1747
-           self::$eolChars = array(
1748
-               array(
1749
-                   'char' => $cr.$lf,
1750
-                   'type' => ConvertHelper_EOL::TYPE_CRLF,
1751
-                   'description' => t('Carriage return followed by a line feed'),
1752
-               ),
1753
-               array(
1754
-                   'char' => $lf.$cr,
1755
-                   'type' => ConvertHelper_EOL::TYPE_LFCR,
1756
-                   'description' => t('Line feed followed by a carriage return'),
1757
-               ),
1758
-               array(
1759
-                  'char' => $lf,
1760
-                  'type' => ConvertHelper_EOL::TYPE_LF,
1761
-                  'description' => t('Line feed'),
1762
-               ),
1763
-               array(
1764
-                  'char' => $cr,
1765
-                  'type' => ConvertHelper_EOL::TYPE_CR,
1766
-                  'description' => t('Carriage Return'),
1767
-               ),
1747
+            self::$eolChars = array(
1748
+                array(
1749
+                    'char' => $cr.$lf,
1750
+                    'type' => ConvertHelper_EOL::TYPE_CRLF,
1751
+                    'description' => t('Carriage return followed by a line feed'),
1752
+                ),
1753
+                array(
1754
+                    'char' => $lf.$cr,
1755
+                    'type' => ConvertHelper_EOL::TYPE_LFCR,
1756
+                    'description' => t('Line feed followed by a carriage return'),
1757
+                ),
1758
+                array(
1759
+                    'char' => $lf,
1760
+                    'type' => ConvertHelper_EOL::TYPE_LF,
1761
+                    'description' => t('Line feed'),
1762
+                ),
1763
+                array(
1764
+                    'char' => $cr,
1765
+                    'type' => ConvertHelper_EOL::TYPE_CR,
1766
+                    'description' => t('Carriage Return'),
1767
+                ),
1768 1768
             );
1769 1769
         }
1770 1770
         
@@ -1792,13 +1792,13 @@  discard block
 block discarded – undo
1792 1792
         );
1793 1793
     }
1794 1794
 
1795
-   /**
1796
-    * Removes the specified keys from the target array,
1797
-    * if they exist.
1798
-    * 
1799
-    * @param array $array
1800
-    * @param array $keys
1801
-    */
1795
+    /**
1796
+     * Removes the specified keys from the target array,
1797
+     * if they exist.
1798
+     * 
1799
+     * @param array $array
1800
+     * @param array $keys
1801
+     */
1802 1802
     public static function arrayRemoveKeys(array &$array, array $keys) : void
1803 1803
     {
1804 1804
         foreach($keys as $key) 
@@ -1809,13 +1809,13 @@  discard block
 block discarded – undo
1809 1809
         }
1810 1810
     }
1811 1811
     
1812
-   /**
1813
-    * Checks if the specified variable is an integer or a string containing an integer.
1814
-    * Accepts both positive and negative integers.
1815
-    * 
1816
-    * @param mixed $value
1817
-    * @return bool
1818
-    */
1812
+    /**
1813
+     * Checks if the specified variable is an integer or a string containing an integer.
1814
+     * Accepts both positive and negative integers.
1815
+     * 
1816
+     * @param mixed $value
1817
+     * @return bool
1818
+     */
1819 1819
     public static function isInteger($value) : bool
1820 1820
     {
1821 1821
         if(is_int($value)) {
@@ -1835,12 +1835,12 @@  discard block
 block discarded – undo
1835 1835
         return false;    
1836 1836
     }
1837 1837
     
1838
-   /**
1839
-    * Converts an amount of seconds to a DateInterval object.
1840
-    * 
1841
-    * @param int $seconds
1842
-    * @return \DateInterval
1843
-    */
1838
+    /**
1839
+     * Converts an amount of seconds to a DateInterval object.
1840
+     * 
1841
+     * @param int $seconds
1842
+     * @return \DateInterval
1843
+     */
1844 1844
     public static function seconds2interval(int $seconds) : \DateInterval
1845 1845
     {
1846 1846
         // The DateInterval::format() method does not recalculate carry 
Please login to merge, or discard this patch.
Spacing   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1492,8 +1492,7 @@
 block discarded – undo
1492 1492
                 if (mb_strlen($actual.$word) <= $width) 
1493 1493
                 {
1494 1494
                     $actual .= $word.' ';
1495
-                } 
1496
-                else 
1495
+                } else 
1497 1496
                 {
1498 1497
                     if ($actual != '') {
1499 1498
                         $line .= rtrim($actual).$break;
Please login to merge, or discard this patch.
src/NumberInfo.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -38,24 +38,24 @@  discard block
 block discarded – undo
38 38
  */
39 39
 class NumberInfo
40 40
 {
41
-   /**
42
-    * @var mixed
43
-    */
41
+    /**
42
+     * @var mixed
43
+     */
44 44
     protected $rawValue;
45 45
     
46
-   /**
47
-    * @var array
48
-    */
46
+    /**
47
+     * @var array
48
+     */
49 49
     protected $info;
50 50
     
51
-   /**
52
-    * @var bool
53
-    */
51
+    /**
52
+     * @var bool
53
+     */
54 54
     protected $empty = false;
55 55
     
56
-   /**
57
-    * @var array
58
-    */
56
+    /**
57
+     * @var array
58
+     */
59 59
     protected $knownUnits = array(
60 60
         '%' => true,
61 61
         'rem' => true,
@@ -95,21 +95,21 @@  discard block
 block discarded – undo
95 95
         return $this;
96 96
     }
97 97
     
98
-   /**
99
-    * Retrieves the raw, internal information array resulting
100
-    * from the parsing of the number.
101
-    *  
102
-    * @return array
103
-    */
98
+    /**
99
+     * Retrieves the raw, internal information array resulting
100
+     * from the parsing of the number.
101
+     *  
102
+     * @return array
103
+     */
104 104
     public function getRawInfo() : array
105 105
     {
106 106
         return $this->info;
107 107
     }
108 108
     
109
-   /**
110
-    * Whether the number was empty (null or empty string).
111
-    * @return boolean
112
-    */
109
+    /**
110
+     * Whether the number was empty (null or empty string).
111
+     * @return boolean
112
+     */
113 113
     public function isEmpty() : bool
114 114
     {
115 115
         return $this->empty;
@@ -590,59 +590,59 @@  discard block
 block discarded – undo
590 590
     
591 591
     protected $postProcess = false;
592 592
     
593
-   /**
594
-    * Called if explicitly enabled: allows filtering the 
595
-    * number after the detection process has completed.
596
-    * 
597
-    * @param string|NULL $number The adjusted number
598
-    * @param string $originalString The original value before it was parsed
599
-    * @return mixed
600
-    */
593
+    /**
594
+     * Called if explicitly enabled: allows filtering the 
595
+     * number after the detection process has completed.
596
+     * 
597
+     * @param string|NULL $number The adjusted number
598
+     * @param string $originalString The original value before it was parsed
599
+     * @return mixed
600
+     */
601 601
     protected function postProcess(?string $number, /** @scrutinizer ignore-unused */ string $originalString)
602 602
     {
603 603
         return $number;
604 604
     }
605 605
     
606
-   /**
607
-    * Filters the value before it is parsed, but only if it is a string.
608
-    * 
609
-    * NOTE: This may be overwritten in a subclass, to allow custom filtering
610
-    * the the values. An example of a use case would be a preprocessor for
611
-    * variables in a templating system.
612
-    * 
613
-    * @param string $trimmedString The trimmed value.
614
-    * @param array $cache The internal values cache array.
615
-    * @param string $originalValue The original value that the NumberInfo was created for.
616
-    * @return string
617
-    * 
618
-    * @see NumberInfo::enablePostProcess()
619
-    */
606
+    /**
607
+     * Filters the value before it is parsed, but only if it is a string.
608
+     * 
609
+     * NOTE: This may be overwritten in a subclass, to allow custom filtering
610
+     * the the values. An example of a use case would be a preprocessor for
611
+     * variables in a templating system.
612
+     * 
613
+     * @param string $trimmedString The trimmed value.
614
+     * @param array $cache The internal values cache array.
615
+     * @param string $originalValue The original value that the NumberInfo was created for.
616
+     * @return string
617
+     * 
618
+     * @see NumberInfo::enablePostProcess()
619
+     */
620 620
     protected function preProcess(string $trimmedString, /** @scrutinizer ignore-unused */ array &$cache, /** @scrutinizer ignore-unused */ string $originalValue) : string
621 621
     {
622 622
         return str_replace(',', '.', $trimmedString);
623 623
     }
624 624
     
625
-   /**
626
-    * Enables the post processing so the postProcess method gets called.
627
-    * This should be called in the {@link NumberInfo::preProcess()}
628
-    * method as needed.
629
-    * 
630
-    * @return NumberInfo
631
-    * @see NumberInfo::postProcess()
632
-    */
625
+    /**
626
+     * Enables the post processing so the postProcess method gets called.
627
+     * This should be called in the {@link NumberInfo::preProcess()}
628
+     * method as needed.
629
+     * 
630
+     * @return NumberInfo
631
+     * @see NumberInfo::postProcess()
632
+     */
633 633
     private function enablePostProcess() : NumberInfo
634 634
     {
635 635
         $this->postProcess = true;
636 636
         return $this;
637 637
     }
638 638
     
639
-   /**
640
-    * Filters the number info array to adjust the units
641
-    * and number according to the required rules.
642
-    * 
643
-    * @param array $info
644
-    * @return array
645
-    */
639
+    /**
640
+     * Filters the number info array to adjust the units
641
+     * and number according to the required rules.
642
+     * 
643
+     * @param array $info
644
+     * @return array
645
+     */
646 646
     protected function filterInfo(array $info) : array
647 647
     {
648 648
         $useUnits = 'px';
Please login to merge, or discard this patch.
src/JSHelper.php 1 patch
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -95,20 +95,20 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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),
Please login to merge, or discard this patch.