@@ -18,31 +18,35 @@ |
||
| 18 | 18 | trait TProperty { |
| 19 | 19 | |
| 20 | 20 | public function __get($name) { |
| 21 | - if (method_exists($this, ($method = 'get'.ucfirst($name)))) |
|
| 22 | - return $this->$method(); |
|
| 23 | - else |
|
| 24 | - throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 21 | + if (method_exists($this, ($method = 'get'.ucfirst($name)))) { |
|
| 22 | + return $this->$method(); |
|
| 23 | + } else { |
|
| 24 | + throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 25 | + } |
|
| 25 | 26 | } |
| 26 | 27 | |
| 27 | 28 | public function __isset($name) { |
| 28 | - if (method_exists($this, ($method = 'isset'.ucfirst($name)))) |
|
| 29 | - return $this->$method(); |
|
| 30 | - else |
|
| 31 | - throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 29 | + if (method_exists($this, ($method = 'isset'.ucfirst($name)))) { |
|
| 30 | + return $this->$method(); |
|
| 31 | + } else { |
|
| 32 | + throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 33 | + } |
|
| 32 | 34 | } |
| 33 | 35 | |
| 34 | 36 | public function __set($name, $value) { |
| 35 | - if (method_exists($this, ($method = 'set'.ucfirst($name)))) |
|
| 36 | - $this->$method($value); |
|
| 37 | - else |
|
| 38 | - throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 37 | + if (method_exists($this, ($method = 'set'.ucfirst($name)))) { |
|
| 38 | + $this->$method($value); |
|
| 39 | + } else { |
|
| 40 | + throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 41 | + } |
|
| 39 | 42 | } |
| 40 | 43 | |
| 41 | 44 | public function __unset($name) { |
| 42 | - if (method_exists($this, ($method = 'unset'.ucfirst($name)))) |
|
| 43 | - $this->$method(); |
|
| 44 | - else |
|
| 45 | - throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 45 | + if (method_exists($this, ($method = 'unset'.ucfirst($name)))) { |
|
| 46 | + $this->$method(); |
|
| 47 | + } else { |
|
| 48 | + throw new \BadMethodCallException("Method $method is not implemented for property $name."); |
|
| 49 | + } |
|
| 46 | 50 | } |
| 47 | 51 | |
| 48 | 52 | } |
| 49 | 53 | \ No newline at end of file |
@@ -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 fa"; |
|
| 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 fa"; |
|
| 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 |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | * @retval 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 | |
@@ -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 | |
@@ -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 | |
@@ -44,10 +44,11 @@ |
||
| 44 | 44 | * @retval 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 |
@@ -108,7 +108,7 @@ |
||
| 108 | 108 | * @param[in] integer $offset The offset to retrieve. |
| 109 | 109 | * @retval mixed Can return all value types. |
| 110 | 110 | */ |
| 111 | - public function offsetGet($offset) { |
|
| 111 | + public function offsetGet($offset) { |
|
| 112 | 112 | return $this->meta[$this->name][$offset]; |
| 113 | 113 | } |
| 114 | 114 | |
@@ -65,11 +65,13 @@ discard block |
||
| 65 | 65 | * @param[in] bool $allowNull When `true` allows a `null` value. |
| 66 | 66 | */ |
| 67 | 67 | public function setMetadata($name, $value, $override = TRUE, $allowNull = TRUE) { |
| 68 | - if (is_null($value) && !$allowNull) |
|
| 69 | - return; |
|
| 68 | + if (is_null($value) && !$allowNull) { |
|
| 69 | + return; |
|
| 70 | + } |
|
| 70 | 71 | |
| 71 | - if ($this->isMetadataPresent($name) && !$override) |
|
| 72 | - return; |
|
| 72 | + if ($this->isMetadataPresent($name) && !$override) { |
|
| 73 | + return; |
|
| 74 | + } |
|
| 73 | 75 | |
| 74 | 76 | $this->meta[$name] = $value; |
| 75 | 77 | } |
@@ -80,8 +82,9 @@ discard block |
||
| 80 | 82 | * @param[in] string $name The metadata name. |
| 81 | 83 | */ |
| 82 | 84 | public function unsetMetadata($name) { |
| 83 | - if (array_key_exists($name, $this->meta)) |
|
| 84 | - unset($this->meta[$name]); |
|
| 85 | + if (array_key_exists($name, $this->meta)) { |
|
| 86 | + unset($this->meta[$name]); |
|
| 87 | + } |
|
| 85 | 88 | } |
| 86 | 89 | |
| 87 | 90 | |
@@ -102,9 +105,9 @@ discard block |
||
| 102 | 105 | public function assignArray(array $array) { |
| 103 | 106 | if (ArrayHelper::isAssociative($array)) { |
| 104 | 107 | $this->meta = array_merge($this->meta, $array); |
| 108 | + } else { |
|
| 109 | + throw new \InvalidArgumentException("\$array must be an associative array."); |
|
| 105 | 110 | } |
| 106 | - else |
|
| 107 | - throw new \InvalidArgumentException("\$array must be an associative array."); |
|
| 108 | 111 | } |
| 109 | 112 | |
| 110 | 113 | |
@@ -128,8 +131,9 @@ discard block |
||
| 128 | 131 | JSON_PRESERVE_ZERO_FRACTION |
| 129 | 132 | ); |
| 130 | 133 | |
| 131 | - if ($json === FALSE) |
|
| 132 | - throw new JSONErrorException(json_last_error_msg()); |
|
| 134 | + if ($json === FALSE) { |
|
| 135 | + throw new JSONErrorException(json_last_error_msg()); |
|
| 136 | + } |
|
| 133 | 137 | |
| 134 | 138 | return $json; |
| 135 | 139 | } |