@@ -105,7 +105,7 @@ |
||
| 105 | 105 | */ |
| 106 | 106 | public function pull($key, $default = null) |
| 107 | 107 | { |
| 108 | - return take($this->get($key, $default), function () use ($key) { |
|
| 108 | + return take($this->get($key, $default), function() use ($key) { |
|
| 109 | 109 | $this->delete($key); |
| 110 | 110 | }); |
| 111 | 111 | } |
@@ -66,12 +66,10 @@ |
||
| 66 | 66 | if ($time instanceof static) |
| 67 | 67 | { |
| 68 | 68 | $time = $time->toDateTime()->setTimezone(new DateTimeZone('UTC')); |
| 69 | - } |
|
| 70 | - elseif ($time instanceof DateTime) |
|
| 69 | + } elseif ($time instanceof DateTime) |
|
| 71 | 70 | { |
| 72 | 71 | $time = $time->setTimezone(new DateTimeZone('UTC')); |
| 73 | - } |
|
| 74 | - elseif (is_string($time)) |
|
| 72 | + } elseif (is_string($time)) |
|
| 75 | 73 | { |
| 76 | 74 | $timezone = $timezone ?: $this->timezone; |
| 77 | 75 | $timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone('UTC'); |
@@ -45,8 +45,8 @@ discard block |
||
| 45 | 45 | { |
| 46 | 46 | $testTime = $this->getConvertedUTC($time, $timezone); |
| 47 | 47 | $ourTime = $this->toDateTime() |
| 48 | - ->setTimezone(new DateTimeZone('UTC')) |
|
| 49 | - ->format('Y-m-d H:i:s'); |
|
| 48 | + ->setTimezone(new DateTimeZone('UTC')) |
|
| 49 | + ->format('Y-m-d H:i:s'); |
|
| 50 | 50 | |
| 51 | 51 | return $testTime->format('Y-m-d H:i:s') === $ourTime; |
| 52 | 52 | } |
@@ -68,15 +68,15 @@ discard block |
||
| 68 | 68 | return $testTime < $ourTime; |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Determines if the current instance's time is after test time, |
|
| 73 | - * after converting to UTC. |
|
| 74 | - * |
|
| 75 | - * @param \DateTime|string $time |
|
| 76 | - * @param \DatetimeZone|string|null $timezone |
|
| 77 | - * |
|
| 78 | - * @return bool |
|
| 79 | - */ |
|
| 71 | + /** |
|
| 72 | + * Determines if the current instance's time is after test time, |
|
| 73 | + * after converting to UTC. |
|
| 74 | + * |
|
| 75 | + * @param \DateTime|string $time |
|
| 76 | + * @param \DatetimeZone|string|null $timezone |
|
| 77 | + * |
|
| 78 | + * @return bool |
|
| 79 | + */ |
|
| 80 | 80 | public function isAfter($time, string $timezone = null) |
| 81 | 81 | { |
| 82 | 82 | $testTime = $this->getConvertedUTC($time, $timezone)->getTimestamp(); |
@@ -100,8 +100,7 @@ |
||
| 100 | 100 | if ($time instanceof DateTime) |
| 101 | 101 | { |
| 102 | 102 | $testTime = $time->format('Y-m-d H:i:s'); |
| 103 | - } |
|
| 104 | - elseif (is_string($time)) |
|
| 103 | + } elseif (is_string($time)) |
|
| 105 | 104 | { |
| 106 | 105 | $timezone = $timezone ?: $this->timezone; |
| 107 | 106 | $timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone); |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | $this->timezone = $timezone instanceof DateTimeZone ? $timezone : new DateTimeZone($timezone); |
| 62 | 62 | |
| 63 | 63 | if ( ! empty($time)) |
| 64 | - { |
|
| 65 | - if (is_string($time) && static::hasRelativeKeywords($time)) |
|
| 66 | - { |
|
| 67 | - $dateTime = new DateTime('now', $this->timezone); |
|
| 68 | - $dateTime->modify($time); |
|
| 64 | + { |
|
| 65 | + if (is_string($time) && static::hasRelativeKeywords($time)) |
|
| 66 | + { |
|
| 67 | + $dateTime = new DateTime('now', $this->timezone); |
|
| 68 | + $dateTime->modify($time); |
|
| 69 | 69 | |
| 70 | - $time = $dateTime->format('Y-m-d H:i:s'); |
|
| 71 | - } |
|
| 70 | + $time = $dateTime->format('Y-m-d H:i:s'); |
|
| 71 | + } |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | return parent::__construct($time, $this->timezone); |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | * @return \Syscodes\Support\Chronos\Time |
| 124 | 124 | */ |
| 125 | 125 | public static function yesterday($timezone = null, string $locale = null) |
| 126 | - { |
|
| 127 | - return static::parse(date('Y-m-d 00:00:00', strtotime('-1 day')), $timezone, $locale); |
|
| 126 | + { |
|
| 127 | + return static::parse(date('Y-m-d 00:00:00', strtotime('-1 day')), $timezone, $locale); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | /** |
@@ -136,8 +136,8 @@ discard block |
||
| 136 | 136 | * @return \Syscodes\Support\Chronos\Time |
| 137 | 137 | */ |
| 138 | 138 | public static function tomorrow($timezone = null, string $locale = null) |
| 139 | - { |
|
| 140 | - return static::parse(date('Y-m-d 00:00:00', strtotime('+1 day')), $timezone, $locale); |
|
| 139 | + { |
|
| 140 | + return static::parse(date('Y-m-d 00:00:00', strtotime('+1 day')), $timezone, $locale); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | |
| 270 | 270 | /** |
| 271 | 271 | * Creates an instance of Time that will be returned during testing |
| 272 | - * when calling 'Time::now' instead of the current time. |
|
| 272 | + * when calling 'Time::now' instead of the current time. |
|
| 273 | 273 | * |
| 274 | 274 | * @param \Syscodes\Support\Chronos\Time|string $datetime (null by default) |
| 275 | 275 | * @param string|null $timezone (null by default) |
@@ -289,8 +289,7 @@ |
||
| 289 | 289 | if (is_string($datetime)) |
| 290 | 290 | { |
| 291 | 291 | $time = static::parse($datetime, $timezone, $locale); |
| 292 | - } |
|
| 293 | - elseif ($datetime instanceof DateTime && ! $datetime instanceof static) |
|
| 292 | + } elseif ($datetime instanceof DateTime && ! $datetime instanceof static) |
|
| 294 | 293 | { |
| 295 | 294 | $time = static::parse($datetime->format('Y-m-d H:i:s'), $timezone); |
| 296 | 295 | } |
@@ -228,34 +228,28 @@ |
||
| 228 | 228 | { |
| 229 | 229 | $phrase = __('time.years', [abs($years)], $locale); |
| 230 | 230 | $before = $years < 0; |
| 231 | - } |
|
| 232 | - else if ($months !== 0) |
|
| 231 | + } else if ($months !== 0) |
|
| 233 | 232 | { |
| 234 | 233 | $phrase = __('time.months', [abs($months)], $locale); |
| 235 | 234 | $before = $months < 0; |
| 236 | - } |
|
| 237 | - else if ($days !== 0 && (abs($days) >= 7)) |
|
| 235 | + } else if ($days !== 0 && (abs($days) >= 7)) |
|
| 238 | 236 | { |
| 239 | 237 | $weeks = ceil($days / 7); |
| 240 | 238 | $phrase = __('time.weeks', [abs($weeks)], $locale); |
| 241 | 239 | $before = $days < 0; |
| 242 | - } |
|
| 243 | - else if ($days !== 0) |
|
| 240 | + } else if ($days !== 0) |
|
| 244 | 241 | { |
| 245 | 242 | $phrase = __('time.days', [abs($days)], $locale); |
| 246 | 243 | $before = $days < 0; |
| 247 | - } |
|
| 248 | - else if ($hours !== 0) |
|
| 244 | + } else if ($hours !== 0) |
|
| 249 | 245 | { |
| 250 | 246 | $phrase = __('time.hours', [abs($hours)], $locale); |
| 251 | 247 | $before = $hours < 0; |
| 252 | - } |
|
| 253 | - else if ($minutes !== 0) |
|
| 248 | + } else if ($minutes !== 0) |
|
| 254 | 249 | { |
| 255 | 250 | $phrase = __('time.minutes', [abs($minutes)], $locale); |
| 256 | 251 | $before = $minutes < 0; |
| 257 | - } |
|
| 258 | - else |
|
| 252 | + } else |
|
| 259 | 253 | { |
| 260 | 254 | return __('time.now', [], $locale); |
| 261 | 255 | } |
@@ -167,7 +167,7 @@ |
||
| 167 | 167 | { |
| 168 | 168 | if ($transition['time'] > $this->format('U')) |
| 169 | 169 | { |
| 170 | - $dayLightSaving = (bool) $transition['isdst'] ?? $dayLightSaving; |
|
| 170 | + $dayLightSaving = (bool) $transition['isdst'] ?? $dayLightSaving; |
|
| 171 | 171 | } |
| 172 | 172 | } |
| 173 | 173 | |
@@ -52,10 +52,10 @@ discard block |
||
| 52 | 52 | use Difference; |
| 53 | 53 | |
| 54 | 54 | /** |
| 55 | - * Used to check time string to determine if it is relative time or not. |
|
| 56 | - * |
|
| 57 | - * @var string $relativePattern |
|
| 58 | - */ |
|
| 55 | + * Used to check time string to determine if it is relative time or not. |
|
| 56 | + * |
|
| 57 | + * @var string $relativePattern |
|
| 58 | + */ |
|
| 59 | 59 | protected static $relativePattern = '/this|next|last|tomorrow|yesterday|midnight|today|[+-]|first|last|ago/i'; |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | 120 | * Returns boolean whether the passed timezone is the same as |
| 121 | - * the local timezone. |
|
| 121 | + * the local timezone. |
|
| 122 | 122 | * |
| 123 | 123 | * @return bool |
| 124 | 124 | */ |
@@ -219,13 +219,13 @@ discard block |
||
| 219 | 219 | return $this->toLocalizedFormatter('yyyy-MM-dd'); |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * Returns a localized version of the time in nicer date format. |
|
| 224 | - * |
|
| 225 | - * i.e. 10:20:33 |
|
| 226 | - * |
|
| 227 | - * @return string |
|
| 228 | - */ |
|
| 222 | + /** |
|
| 223 | + * Returns a localized version of the time in nicer date format. |
|
| 224 | + * |
|
| 225 | + * i.e. 10:20:33 |
|
| 226 | + * |
|
| 227 | + * @return string |
|
| 228 | + */ |
|
| 229 | 229 | public function toTimeString() |
| 230 | 230 | { |
| 231 | 231 | return $this->toLocalizedFormatter('HH:mm:ss'); |
@@ -274,19 +274,16 @@ discard block |
||
| 274 | 274 | { |
| 275 | 275 | $phrase = __('time.years', [abs($years)]); |
| 276 | 276 | $before = $years < 0; |
| 277 | - } |
|
| 278 | - elseif ($months !== 0) |
|
| 277 | + } elseif ($months !== 0) |
|
| 279 | 278 | { |
| 280 | 279 | $phrase = __('time.months', [abs($months)]); |
| 281 | 280 | $before = $months < 0; |
| 282 | - } |
|
| 283 | - elseif ($days !== 0 && (abs($days) >= 7)) |
|
| 281 | + } elseif ($days !== 0 && (abs($days) >= 7)) |
|
| 284 | 282 | { |
| 285 | 283 | $weeks = ceil($days / 7); |
| 286 | 284 | $phrase = __('time.weeks', [abs($weeks)]); |
| 287 | 285 | $before = $days < 0; |
| 288 | - } |
|
| 289 | - elseif ($days !== 0) |
|
| 286 | + } elseif ($days !== 0) |
|
| 290 | 287 | { |
| 291 | 288 | $before = $days < 0; |
| 292 | 289 | $phrase = __('time.days', [abs($days)]); |
@@ -295,23 +292,19 @@ discard block |
||
| 295 | 292 | if (abs($days) === 1) |
| 296 | 293 | { |
| 297 | 294 | return $before ? __('time.yesterday') : __('time.tomorrow'); |
| 298 | - } |
|
| 299 | - else |
|
| 295 | + } else |
|
| 300 | 296 | { |
| 301 | 297 | $phrase = __('time.days', [abs($days) + 1]); |
| 302 | 298 | } |
| 303 | - } |
|
| 304 | - elseif ($hours !== 0) |
|
| 299 | + } elseif ($hours !== 0) |
|
| 305 | 300 | { |
| 306 | 301 | // Display the actual time instead of a regular phrase. |
| 307 | 302 | return $this->format('g:i a'); |
| 308 | - } |
|
| 309 | - elseif ($minutes !== 0) |
|
| 303 | + } elseif ($minutes !== 0) |
|
| 310 | 304 | { |
| 311 | 305 | $phrase = __('time.minutes', [abs($minutes)]); |
| 312 | 306 | $before = $minutes < 0; |
| 313 | - } |
|
| 314 | - else |
|
| 307 | + } else |
|
| 315 | 308 | { |
| 316 | 309 | return __('time.now'); |
| 317 | 310 | } |
@@ -206,7 +206,9 @@ |
||
| 206 | 206 | */ |
| 207 | 207 | public static function limit($value, $limit, $end = '...') |
| 208 | 208 | { |
| 209 | - if (static::length($value) <= $limit) return $value; |
|
| 209 | + if (static::length($value) <= $limit) { |
|
| 210 | + return $value; |
|
| 211 | + } |
|
| 210 | 212 | |
| 211 | 213 | return rtrim(mb_substr($value, 0, $limit, 'UTF-8')).$end; |
| 212 | 214 | } |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | |
| 177 | 177 | if ( ! function_exists('str_underscore')) |
| 178 | 178 | { |
| 179 | - /** |
|
| 179 | + /** |
|
| 180 | 180 | * Replace in the string the spaces by low dashes. |
| 181 | 181 | * |
| 182 | 182 | * @param string $string |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | |
| 194 | 194 | if ( ! function_exists('studly_caps')) |
| 195 | 195 | { |
| 196 | - /** |
|
| 196 | + /** |
|
| 197 | 197 | * Convert the string with spaces or underscore in StudlyCaps. |
| 198 | 198 | * |
| 199 | 199 | * @param string $string |
@@ -69,7 +69,7 @@ |
||
| 69 | 69 | */ |
| 70 | 70 | function dd() |
| 71 | 71 | { |
| 72 | - array_map(function ($x) |
|
| 72 | + array_map(function($x) |
|
| 73 | 73 | { |
| 74 | 74 | var_dump($x); |
| 75 | 75 | }, func_get_args()); |