@@ -14,7 +14,7 @@ discard block |
||
| 14 | 14 | * @return DateTimeImmutable |
| 15 | 15 | */ |
| 16 | 16 | public static function getNext($interval, DateTimeInterface $now = null): DateTimeImmutable { |
| 17 | - if($now === null) { |
|
| 17 | + if ($now === null) { |
|
| 18 | 18 | try { |
| 19 | 19 | $now = new DateTimeImmutable(); |
| 20 | 20 | } catch (Throwable $e) { |
@@ -24,10 +24,10 @@ discard block |
||
| 24 | 24 | $now = DateTimeHelper::createImmutable($now); |
| 25 | 25 | } |
| 26 | 26 | $result = null; |
| 27 | - foreach(self::parse($interval, $now) as $date) { |
|
| 28 | - if($result === null) { |
|
| 27 | + foreach (self::parse($interval, $now) as $date) { |
|
| 28 | + if ($result === null) { |
|
| 29 | 29 | $result = $date; |
| 30 | - } elseif($date < $result) { |
|
| 30 | + } elseif ($date < $result) { |
|
| 31 | 31 | $result = $date; |
| 32 | 32 | } |
| 33 | 33 | } |
@@ -40,11 +40,11 @@ discard block |
||
| 40 | 40 | * @return Generator|DateTimeImmutable[] |
| 41 | 41 | */ |
| 42 | 42 | private static function parse($interval, DateTimeImmutable $now) { |
| 43 | - if(is_array($interval)) { |
|
| 44 | - foreach($interval as $inner) { |
|
| 43 | + if (is_array($interval)) { |
|
| 44 | + foreach ($interval as $inner) { |
|
| 45 | 45 | yield from self::parse($inner, $now); |
| 46 | 46 | } |
| 47 | - } elseif(preg_match('/^\\d+$/', $interval)) { |
|
| 47 | + } elseif (preg_match('/^\\d+$/', $interval)) { |
|
| 48 | 48 | yield self::parseInt($interval, $now); |
| 49 | 49 | } else { |
| 50 | 50 | yield self::parseString($interval, $now); |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | * @return DateTimeImmutable |
| 67 | 67 | */ |
| 68 | 68 | private static function parseString(string $interval, DateTimeImmutable $now): DateTimeImmutable { |
| 69 | - if(preg_match('/^(\\d{1,2}|\\*):(\\d{1,2}|\\*)(?::(\\d{1,2}|\\*))?$/', $interval, $matches)) { |
|
| 69 | + if (preg_match('/^(\\d{1,2}|\\*):(\\d{1,2}|\\*)(?::(\\d{1,2}|\\*))?$/', $interval, $matches)) { |
|
| 70 | 70 | $matches[] = 0; |
| 71 | 71 | [$hours, $minutes, $seconds] = array_slice($matches, 1); |
| 72 | 72 | $today = DateTimeHelper::createImmutable($now)->setTime((int) $hours, (int) $minutes, (int) $seconds); |
@@ -87,15 +87,15 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | private static function nearst(array $possibleDates, DateTimeImmutable $now) { |
| 89 | 89 | $current = null; |
| 90 | - foreach($possibleDates as $possibleDate) { |
|
| 91 | - if($now > $possibleDate) { // The current date is in the past |
|
| 90 | + foreach ($possibleDates as $possibleDate) { |
|
| 91 | + if ($now > $possibleDate) { // The current date is in the past |
|
| 92 | 92 | continue; |
| 93 | 93 | } |
| 94 | - if($current === null || $possibleDate < $current) { |
|
| 94 | + if ($current === null || $possibleDate < $current) { |
|
| 95 | 95 | $current = $possibleDate; |
| 96 | 96 | } |
| 97 | 97 | } |
| 98 | - if($current !== null) { |
|
| 98 | + if ($current !== null) { |
|
| 99 | 99 | return $current; |
| 100 | 100 | } |
| 101 | 101 | throw new RuntimeException('No alternative lays in the future'); |