@@ -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) { |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | } |
23 | 23 | } |
24 | 24 | $result = null; |
25 | - foreach(self::parse($interval, $now) as $date) { |
|
26 | - if($result === null) { |
|
25 | + foreach (self::parse($interval, $now) as $date) { |
|
26 | + if ($result === null) { |
|
27 | 27 | $result = $date; |
28 | - } elseif($date < $result) { |
|
28 | + } elseif ($date < $result) { |
|
29 | 29 | $result = $date; |
30 | 30 | } |
31 | 31 | } |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | * @return Generator|DateTimeImmutable |
39 | 39 | */ |
40 | 40 | private static function parse($interval, DateTimeInterface $now) { |
41 | - if(is_array($interval)) { |
|
42 | - foreach($interval as $inner) { |
|
41 | + if (is_array($interval)) { |
|
42 | + foreach ($interval as $inner) { |
|
43 | 43 | yield from self::parse($inner, $now); |
44 | 44 | } |
45 | - } elseif(ctype_digit($interval)) { |
|
45 | + } elseif (ctype_digit($interval)) { |
|
46 | 46 | yield self::parseInt($interval, $now); |
47 | 47 | } else { |
48 | 48 | yield self::parseString($interval, $now); |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | * @return DateTimeInterface |
65 | 65 | */ |
66 | 66 | private static function parseString(string $interval, DateTimeInterface $now): DateTimeInterface { |
67 | - if(preg_match('/^(\\d{1,2}|\\*):(\\d{1,2}|\\*)(?::(\\d{1,2}|\\*))?$/', $interval, $matches)) { |
|
67 | + if (preg_match('/^(\\d{1,2}|\\*):(\\d{1,2}|\\*)(?::(\\d{1,2}|\\*))?$/', $interval, $matches)) { |
|
68 | 68 | $matches[] = 0; |
69 | 69 | [$hours, $minutes, $seconds] = array_slice($matches, 1); |
70 | 70 | $today = DateTimeHelper::createImmutable($now)->setTime((int) $hours, (int) $minutes, (int) $seconds); |
@@ -85,15 +85,15 @@ discard block |
||
85 | 85 | */ |
86 | 86 | private static function nearst(array $possibleDates, DateTimeInterface $now) { |
87 | 87 | $current = null; |
88 | - foreach($possibleDates as $possibleDate) { |
|
89 | - if($now > $possibleDate) { // The current date is in the past |
|
88 | + foreach ($possibleDates as $possibleDate) { |
|
89 | + if ($now > $possibleDate) { // The current date is in the past |
|
90 | 90 | continue; |
91 | 91 | } |
92 | - if($current === null || $possibleDate < $current) { |
|
92 | + if ($current === null || $possibleDate < $current) { |
|
93 | 93 | $current = $possibleDate; |
94 | 94 | } |
95 | 95 | } |
96 | - if($current !== null) { |
|
96 | + if ($current !== null) { |
|
97 | 97 | return $current; |
98 | 98 | } |
99 | 99 | throw new RuntimeException('No alternative lays in the future'); |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | abstract class DateTimeHelper { |
12 | 12 | public static function create($init = null): DateTime { |
13 | 13 | try { |
14 | - if($init instanceof DateTimeInterface) { |
|
14 | + if ($init instanceof DateTimeInterface) { |
|
15 | 15 | return new DateTime($init->format('c')); |
16 | 16 | } |
17 | 17 | return new DateTime($init); |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | |
23 | 23 | public static function createImmutable($init = null): DateTimeImmutable { |
24 | 24 | try { |
25 | - if($init instanceof DateTimeInterface) { |
|
25 | + if ($init instanceof DateTimeInterface) { |
|
26 | 26 | return new DateTimeImmutable($init->format('c')); |
27 | 27 | } |
28 | 28 | return new DateTimeImmutable($init); |