@@ -45,10 +45,11 @@ discard block |
||
45 | 45 | * @bug https://bugs.php.net/bug.php?id=64667 |
46 | 46 | */ |
47 | 47 | public static function convertCharset($text, $stripslashes = FALSE, $fromCharset = 'Windows-1252', $toCharset = 'UTF-8') { |
48 | - if ($stripslashes) |
|
49 | - return iconv($fromCharset, $toCharset, stripslashes($text)); |
|
50 | - else |
|
51 | - return iconv($fromCharset, $toCharset, $text); |
|
48 | + if ($stripslashes) { |
|
49 | + return iconv($fromCharset, $toCharset, stripslashes($text)); |
|
50 | + } else { |
|
51 | + return iconv($fromCharset, $toCharset, $text); |
|
52 | + } |
|
52 | 53 | } |
53 | 54 | |
54 | 55 | |
@@ -64,22 +65,25 @@ discard block |
||
64 | 65 | * @warning This function works with UTF-8 strings. |
65 | 66 | */ |
66 | 67 | public static function truncate($text, $length = 200, $etc = ' ...', $charset='UTF-8', $breakWords = FALSE, $middle = FALSE) { |
67 | - if ($length == 0) |
|
68 | - return ''; |
|
68 | + if ($length == 0) { |
|
69 | + return ''; |
|
70 | + } |
|
69 | 71 | |
70 | 72 | if (mb_strlen($text) > $length) { |
71 | 73 | $length -= min($length, mb_strlen($etc, $charset)); |
72 | 74 | |
73 | - if (!$breakWords && !$middle) |
|
74 | - $text = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($text, 0, $length+1, $charset)); |
|
75 | - |
|
76 | - if(!$middle) |
|
77 | - return mb_substr($text, 0, $length, $charset) . $etc; |
|
78 | - else |
|
79 | - return mb_substr($text, 0, $length/2, $charset) . $etc . mb_substr($text, -$length/2, (mb_strlen($text, $charset) - $length/2), $charset); |
|
75 | + if (!$breakWords && !$middle) { |
|
76 | + $text = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($text, 0, $length+1, $charset)); |
|
77 | + } |
|
78 | + |
|
79 | + if(!$middle) { |
|
80 | + return mb_substr($text, 0, $length, $charset) . $etc; |
|
81 | + } else { |
|
82 | + return mb_substr($text, 0, $length/2, $charset) . $etc . mb_substr($text, -$length/2, (mb_strlen($text, $charset) - $length/2), $charset); |
|
83 | + } |
|
84 | + } else { |
|
85 | + return $text; |
|
80 | 86 | } |
81 | - else |
|
82 | - return $text; |
|
83 | 87 | } |
84 | 88 | |
85 | 89 | |
@@ -105,8 +109,9 @@ discard block |
||
105 | 109 | // Removes the content of <pre></pre>. |
106 | 110 | $temp = preg_replace('/<(pre)(?:(?!<\/\1).)*?<\/\1>/su', '', $text); |
107 | 111 | |
108 | - if (is_null($temp)) |
|
109 | - throw new \RuntimeException(array_flip(get_defined_constants(TRUE)['pcre'])[preg_last_error()]); |
|
112 | + if (is_null($temp)) { |
|
113 | + throw new \RuntimeException(array_flip(get_defined_constants(TRUE)['pcre'])[preg_last_error()]); |
|
114 | + } |
|
110 | 115 | |
111 | 116 | // Removes all the HTML tags. |
112 | 117 | $temp = strip_tags($temp); |
@@ -137,9 +142,12 @@ discard block |
||
137 | 142 | $length = mb_strlen($str, $charset); |
138 | 143 | |
139 | 144 | $subs = []; |
140 | - for ($i = 0; $i < $length; $i++) |
|
141 | - for ($j = 1; $j <= $length; $j++) |
|
142 | - $subs[] = mb_substr($str, $i, $j, $charset); |
|
145 | + for ($i = 0; $i < $length; $i++) { |
|
146 | + for ($j = 1; |
|
147 | + } |
|
148 | + $j <= $length; $j++) { |
|
149 | + $subs[] = mb_substr($str, $i, $j, $charset); |
|
150 | + } |
|
143 | 151 | |
144 | 152 | return array_unique($subs); |
145 | 153 | } |
@@ -236,25 +244,26 @@ discard block |
||
236 | 244 | if (mb_strpos($r[0], '.') === FALSE) { |
237 | 245 | $result['salutation'] = ''; |
238 | 246 | $result['first'] = $r[0]; |
239 | - } |
|
240 | - else { |
|
247 | + } else { |
|
241 | 248 | $result['salutation'] = $r[0]; |
242 | 249 | $result['first'] = $r[1]; |
243 | 250 | } |
244 | 251 | |
245 | 252 | // Checks last for period, assume suffix if so |
246 | - if (mb_strpos($r[$size - 1], '.') === FALSE) |
|
247 | - $result['suffix'] = ''; |
|
248 | - else |
|
249 | - $result['suffix'] = $r[$size - 1]; |
|
253 | + if (mb_strpos($r[$size - 1], '.') === FALSE) { |
|
254 | + $result['suffix'] = ''; |
|
255 | + } else { |
|
256 | + $result['suffix'] = $r[$size - 1]; |
|
257 | + } |
|
250 | 258 | |
251 | 259 | // Combines remains into last. |
252 | 260 | $start = ($result['salutation']) ? 2 : 1; |
253 | 261 | $end = ($result['suffix']) ? $size - 2 : $size - 1; |
254 | 262 | |
255 | 263 | $last = ''; |
256 | - for ($i = $start; $i <= $end; $i++) |
|
257 | - $last .= ' '.$r[$i]; |
|
264 | + for ($i = $start; $i <= $end; $i++) { |
|
265 | + $last .= ' '.$r[$i]; |
|
266 | + } |
|
258 | 267 | |
259 | 268 | $result['last'] = trim($last); |
260 | 269 |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | * @return string |
64 | 64 | * @warning This function works with UTF-8 strings. |
65 | 65 | */ |
66 | - public static function truncate($text, $length = 200, $etc = ' ...', $charset='UTF-8', $breakWords = FALSE, $middle = FALSE) { |
|
66 | + public static function truncate($text, $length = 200, $etc = ' ...', $charset = 'UTF-8', $breakWords = FALSE, $middle = FALSE) { |
|
67 | 67 | if ($length == 0) |
68 | 68 | return ''; |
69 | 69 | |
@@ -71,12 +71,12 @@ discard block |
||
71 | 71 | $length -= min($length, mb_strlen($etc, $charset)); |
72 | 72 | |
73 | 73 | if (!$breakWords && !$middle) |
74 | - $text = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($text, 0, $length+1, $charset)); |
|
74 | + $text = preg_replace('/\s+?(\S+)?$/u', '', mb_substr($text, 0, $length + 1, $charset)); |
|
75 | 75 | |
76 | - if(!$middle) |
|
77 | - return mb_substr($text, 0, $length, $charset) . $etc; |
|
76 | + if (!$middle) |
|
77 | + return mb_substr($text, 0, $length, $charset).$etc; |
|
78 | 78 | else |
79 | - return mb_substr($text, 0, $length/2, $charset) . $etc . mb_substr($text, -$length/2, (mb_strlen($text, $charset) - $length/2), $charset); |
|
79 | + return mb_substr($text, 0, $length / 2, $charset).$etc.mb_substr($text, -$length / 2, (mb_strlen($text, $charset) - $length / 2), $charset); |
|
80 | 80 | } |
81 | 81 | else |
82 | 82 | return $text; |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | * @warning This function works with UTF-8 strings. |
92 | 92 | */ |
93 | 93 | public static function capitalize($text, $charset = 'UTF-8') { |
94 | - return mb_strtoupper(mb_substr($text, 0, 1, $charset), $charset) . mb_strtolower(mb_substr($text, 1, mb_strlen($text, $charset), $charset), $charset); |
|
94 | + return mb_strtoupper(mb_substr($text, 0, 1, $charset), $charset).mb_strtolower(mb_substr($text, 1, mb_strlen($text, $charset), $charset), $charset); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 |
@@ -50,10 +50,11 @@ discard block |
||
50 | 50 | public static function fromJson($json, $assoc) { |
51 | 51 | $data = json_decode((string)$json, $assoc); |
52 | 52 | |
53 | - if (is_null($data)) |
|
54 | - switch (json_last_error()) { |
|
53 | + if (is_null($data)) { |
|
54 | + switch (json_last_error()) { |
|
55 | 55 | case JSON_ERROR_DEPTH: |
56 | 56 | throw new JSONErrorException("Unable to parse the given JSON, the maximum stack depth has been exceeded."); |
57 | + } |
|
57 | 58 | break; |
58 | 59 | case JSON_ERROR_STATE_MISMATCH: |
59 | 60 | throw new JSONErrorException("Unable to parse the given JSON, invalid or malformed JSON."); |
@@ -92,10 +93,11 @@ discard block |
||
92 | 93 | */ |
93 | 94 | public static function value($key, array $array) { |
94 | 95 | |
95 | - if (array_key_exists($key, $array)) |
|
96 | - return $array[$key]; |
|
97 | - else |
|
98 | - return FALSE; |
|
96 | + if (array_key_exists($key, $array)) { |
|
97 | + return $array[$key]; |
|
98 | + } else { |
|
99 | + return FALSE; |
|
100 | + } |
|
99 | 101 | } |
100 | 102 | |
101 | 103 | |
@@ -107,10 +109,11 @@ discard block |
||
107 | 109 | */ |
108 | 110 | public static function key($key, array $array) { |
109 | 111 | |
110 | - if (array_key_exists($key, $array)) |
|
111 | - return $key; |
|
112 | - else |
|
113 | - return FALSE; |
|
112 | + if (array_key_exists($key, $array)) { |
|
113 | + return $key; |
|
114 | + } else { |
|
115 | + return FALSE; |
|
116 | + } |
|
114 | 117 | } |
115 | 118 | |
116 | 119 |
@@ -155,7 +155,7 @@ |
||
155 | 155 | // An array with the used keys. |
156 | 156 | $keys = []; |
157 | 157 | |
158 | - foreach($array as $value) { |
|
158 | + foreach ($array as $value) { |
|
159 | 159 | |
160 | 160 | if (!in_array($value[$key], $keys)) { |
161 | 161 | $keys[$i] = $value[$key]; |
@@ -69,8 +69,7 @@ discard block |
||
69 | 69 | |
70 | 70 | // Converts microseconds in seconds. |
71 | 71 | $seconds = floor($microseconds / $microsecondsInASecond); |
72 | - } |
|
73 | - else { |
|
72 | + } else { |
|
74 | 73 | // Calculates difference in seconds. |
75 | 74 | $seconds = time() - $timestamp; |
76 | 75 | } |
@@ -125,25 +124,29 @@ discard block |
||
125 | 124 | if ($today == date('Ymd', $timestamp)) { |
126 | 125 | $time = self::since($timestamp); |
127 | 126 | |
128 | - if ($time['hours'] > 1) |
|
129 | - return sprintf('%d hours ago', $time['hours']); |
|
130 | - elseif ($time['hours'] == 1) |
|
131 | - return "one hour ago"; |
|
132 | - elseif ($time['minutes'] > 1) |
|
133 | - return sprintf('%d minutes ago', $time['minutes']); |
|
134 | - elseif ($time['minutes'] == 1) |
|
135 | - return "one minute ago"; |
|
136 | - elseif ($time['seconds'] > 1) |
|
137 | - return sprintf('%d seconds ago', $time['seconds']); |
|
138 | - else // $time['seconds'] == 1 |
|
127 | + if ($time['hours'] > 1) { |
|
128 | + return sprintf('%d hours ago', $time['hours']); |
|
129 | + } elseif ($time['hours'] == 1) { |
|
130 | + return "one hour ago"; |
|
131 | + } elseif ($time['minutes'] > 1) { |
|
132 | + return sprintf('%d minutes ago', $time['minutes']); |
|
133 | + } elseif ($time['minutes'] == 1) { |
|
134 | + return "one minute ago"; |
|
135 | + } elseif ($time['seconds'] > 1) { |
|
136 | + return sprintf('%d seconds ago', $time['seconds']); |
|
137 | + } else { |
|
138 | + // $time['seconds'] == 1 |
|
139 | 139 | return "one second ago"; |
140 | + } |
|
140 | 141 | } |
141 | 142 | // Yesterday. |
142 | - elseif (strtotime('-1 day', $today) == date('Ymd', $timestamp)) |
|
143 | - return "yesterday"; |
|
143 | + elseif (strtotime('-1 day', $today) == date('Ymd', $timestamp)) { |
|
144 | + return "yesterday"; |
|
145 | + } |
|
144 | 146 | // In the past. |
145 | - else |
|
146 | - return $showTime ? date('d/m/Y H:i', $timestamp) : date('d/m/Y', $timestamp); |
|
147 | + else { |
|
148 | + return $showTime ? date('d/m/Y H:i', $timestamp) : date('d/m/Y', $timestamp); |
|
149 | + } |
|
147 | 150 | } |
148 | 151 | |
149 | 152 | |
@@ -257,12 +260,13 @@ discard block |
||
257 | 260 | $minDate = (new \DateTime())->setDate($aYear, $aMonth, $aDay)->modify('midnight'); |
258 | 261 | $maxDate = clone($minDate); |
259 | 262 | |
260 | - if (isset($day)) |
|
261 | - $maxDate->modify('tomorrow')->modify('last second'); |
|
262 | - elseif (isset($month)) |
|
263 | - $maxDate->modify('last day of this month')->modify('last second'); |
|
264 | - else |
|
265 | - $maxDate->setDate($aYear, 12, 31)->modify('last second'); |
|
263 | + if (isset($day)) { |
|
264 | + $maxDate->modify('tomorrow')->modify('last second'); |
|
265 | + } elseif (isset($month)) { |
|
266 | + $maxDate->modify('last day of this month')->modify('last second'); |
|
267 | + } else { |
|
268 | + $maxDate->setDate($aYear, 12, 31)->modify('last second'); |
|
269 | + } |
|
266 | 270 | } |
267 | 271 | |
268 | 272 | } |
269 | 273 | \ No newline at end of file |
@@ -44,10 +44,11 @@ |
||
44 | 44 | * @return string The namespace's root. |
45 | 45 | */ |
46 | 46 | public static function getClassRoot($namespace) { |
47 | - if (preg_match('/^(.*[\\\\])/', $namespace, $matches)) |
|
48 | - return $matches[0]; |
|
49 | - else |
|
50 | - return ""; |
|
47 | + if (preg_match('/^(.*[\\\\])/', $namespace, $matches)) { |
|
48 | + return $matches[0]; |
|
49 | + } else { |
|
50 | + return ""; |
|
51 | + } |
|
51 | 52 | } |
52 | 53 | |
53 | 54 | } |
54 | 55 | \ No newline at end of file |