@@ -15,13 +15,15 @@ discard block |
||
15 | 15 | |
16 | 16 | public function __construct($interval = 'PT0S') |
17 | 17 | { |
18 | - if ($interval === NULL) |
|
19 | - $interval = 'PT0S'; |
|
18 | + if ($interval === NULL) { |
|
19 | + $interval = 'PT0S'; |
|
20 | + } |
|
20 | 21 | $this->refDT = new DateTimeImmutable('midnight'); |
21 | 22 | $invert = FALSE; |
22 | 23 | if ($interval instanceof \DateInterval) { |
23 | - if ($interval->invert) |
|
24 | - $invert = TRUE; |
|
24 | + if ($interval->invert) { |
|
25 | + $invert = TRUE; |
|
26 | + } |
|
25 | 27 | $interval = self::parse($interval); |
26 | 28 | } elseif (is_string($interval)) { |
27 | 29 | if (strpos($interval, '-') === 0) { |
@@ -29,12 +31,14 @@ discard block |
||
29 | 31 | $interval = substr($interval, 1); |
30 | 32 | } |
31 | 33 | } elseif (is_int($interval)) { |
32 | - if ($interval < 0) |
|
33 | - $invert = TRUE; |
|
34 | + if ($interval < 0) { |
|
35 | + $invert = TRUE; |
|
36 | + } |
|
34 | 37 | $interval = sprintf("PT%uS", abs($interval)); |
35 | 38 | } elseif (is_float($interval)) { |
36 | - if ($interval < 0) |
|
37 | - $invert = TRUE; |
|
39 | + if ($interval < 0) { |
|
40 | + $invert = TRUE; |
|
41 | + } |
|
38 | 42 | $interval = sprintf("PT%uS", abs(round($interval))); |
39 | 43 | } |
40 | 44 | try { |
@@ -66,8 +70,9 @@ discard block |
||
66 | 70 | $d1->add(new self($interval)); |
67 | 71 | $int = ($this->getRefDT())->diff($d1); |
68 | 72 | $this->__construct(self::parse(/** @scrutinizer ignore-type */$int)); |
69 | - if ($d1 < $this->getRefDT()) |
|
70 | - $this->invert = 1; |
|
73 | + if ($d1 < $this->getRefDT()) { |
|
74 | + $this->invert = 1; |
|
75 | + } |
|
71 | 76 | return $this; |
72 | 77 | } |
73 | 78 | |
@@ -78,8 +83,9 @@ discard block |
||
78 | 83 | $d1->sub(new self($interval)); |
79 | 84 | $int = ($this->getRefDT())->diff($d1); |
80 | 85 | $this->__construct(self::parse(/** @scrutinizer ignore-type */$int)); |
81 | - if ($d1 < $this->getRefDT()) |
|
82 | - $this->invert = 1; |
|
86 | + if ($d1 < $this->getRefDT()) { |
|
87 | + $this->invert = 1; |
|
88 | + } |
|
83 | 89 | return $this; |
84 | 90 | } |
85 | 91 | |
@@ -109,12 +115,13 @@ discard block |
||
109 | 115 | |
110 | 116 | if (isset($time['H']) && $time['H'] < 0) { |
111 | 117 | $time['H'] = 24 + $time['H']; |
112 | - if ($date['D'] >= 1) |
|
113 | - $date['D']--; |
|
114 | - elseif ($date['M'] >= 1) |
|
115 | - $date['M']--; |
|
116 | - elseif ($date['Y'] >= 1) |
|
117 | - $date['Y']--; |
|
118 | + if ($date['D'] >= 1) { |
|
119 | + $date['D']--; |
|
120 | + } elseif ($date['M'] >= 1) { |
|
121 | + $date['M']--; |
|
122 | + } elseif ($date['Y'] >= 1) { |
|
123 | + $date['Y']--; |
|
124 | + } |
|
118 | 125 | } |
119 | 126 | |
120 | 127 | if ($time['H'] === 24) { |
@@ -154,9 +161,11 @@ discard block |
||
154 | 161 | private function validateRelativeFormat($interval, \Exception $e = NULL) |
155 | 162 | { |
156 | 163 | $parse = date_parse($interval); |
157 | - if ($parse['error_count']) |
|
158 | - throw new DateInterval\InvalidArgumentException(($e) ? $e->getMessage() : NULL, ($e) ? $e->getCode() : NULL, ($e) ? $e : NULL); |
|
159 | - if (!isset($parse['relative'])) |
|
160 | - throw new DateInterval\InvalidArgumentException(sprintf("First argument '%s' is not in supported relative date format.", $interval), ($e) ? $e->getCode() : NULL, ($e) ? $e : NULL); |
|
164 | + if ($parse['error_count']) { |
|
165 | + throw new DateInterval\InvalidArgumentException(($e) ? $e->getMessage() : NULL, ($e) ? $e->getCode() : NULL, ($e) ? $e : NULL); |
|
166 | + } |
|
167 | + if (!isset($parse['relative'])) { |
|
168 | + throw new DateInterval\InvalidArgumentException(sprintf("First argument '%s' is not in supported relative date format.", $interval), ($e) ? $e->getCode() : NULL, ($e) ? $e : NULL); |
|
169 | + } |
|
161 | 170 | } |
162 | 171 | } |