@@ -18,8 +18,9 @@ discard block |
||
| 18 | 18 | $this->refDT = new DateTimeImmutable('midnight'); |
| 19 | 19 | $invert = FALSE; |
| 20 | 20 | if ($interval instanceof \DateInterval) { |
| 21 | - if ($interval->invert) |
|
| 22 | - $invert = TRUE; |
|
| 21 | + if ($interval->invert) { |
|
| 22 | + $invert = TRUE; |
|
| 23 | + } |
|
| 23 | 24 | $interval = self::parse($interval); |
| 24 | 25 | } elseif (is_string($interval)) { |
| 25 | 26 | if (strpos($interval, '-') === 0) { |
@@ -27,12 +28,14 @@ discard block |
||
| 27 | 28 | $interval = substr($interval, 1); |
| 28 | 29 | } |
| 29 | 30 | } elseif (is_int($interval)) { |
| 30 | - if ($interval < 0) |
|
| 31 | - $invert = TRUE; |
|
| 31 | + if ($interval < 0) { |
|
| 32 | + $invert = TRUE; |
|
| 33 | + } |
|
| 32 | 34 | $interval = sprintf("PT%uS", abs($interval)); |
| 33 | 35 | } elseif (is_float($interval)) { |
| 34 | - if ($interval < 0) |
|
| 35 | - $invert = TRUE; |
|
| 36 | + if ($interval < 0) { |
|
| 37 | + $invert = TRUE; |
|
| 38 | + } |
|
| 36 | 39 | $interval = sprintf("PT%uS", abs(round($interval))); |
| 37 | 40 | } |
| 38 | 41 | try { |
@@ -42,8 +45,9 @@ discard block |
||
| 42 | 45 | try { |
| 43 | 46 | $d1 = $this->getRefDT(); |
| 44 | 47 | $d2 = (clone $d1)->modify($interval); |
| 45 | - if ($d1 > $d2) |
|
| 46 | - $invert = TRUE; |
|
| 48 | + if ($d1 > $d2) { |
|
| 49 | + $invert = TRUE; |
|
| 50 | + } |
|
| 47 | 51 | parent::__construct(self::parse($d1->diff($d2))); |
| 48 | 52 | } catch (\Exception $e) { |
| 49 | 53 | throw new DateInterval\InvalidArgumentException($e->getMessage(), $e->getCode(), $e); |
@@ -61,8 +65,9 @@ discard block |
||
| 61 | 65 | $d1->add(new self($interval)); |
| 62 | 66 | $int = ($this->getRefDT())->diff($d1); |
| 63 | 67 | self::__construct(self::parse($int)); |
| 64 | - if ($d1 < $this->getRefDT()) |
|
| 65 | - $this->invert = 1; |
|
| 68 | + if ($d1 < $this->getRefDT()) { |
|
| 69 | + $this->invert = 1; |
|
| 70 | + } |
|
| 66 | 71 | return $this; |
| 67 | 72 | } |
| 68 | 73 | |
@@ -73,8 +78,9 @@ discard block |
||
| 73 | 78 | $d1->sub(new self($interval)); |
| 74 | 79 | $int = ($this->getRefDT())->diff($d1); |
| 75 | 80 | self::__construct(self::parse($int)); |
| 76 | - if ($d1 < $this->getRefDT()) |
|
| 77 | - $this->invert = 1; |
|
| 81 | + if ($d1 < $this->getRefDT()) { |
|
| 82 | + $this->invert = 1; |
|
| 83 | + } |
|
| 78 | 84 | return $this; |
| 79 | 85 | } |
| 80 | 86 | |
@@ -134,9 +140,11 @@ discard block |
||
| 134 | 140 | private function validateRelativeFormat($interval, \Exception $e = NULL) |
| 135 | 141 | { |
| 136 | 142 | $parse = date_parse($interval); |
| 137 | - if ($parse['error_count']) |
|
| 138 | - throw new DateInterval\InvalidArgumentException(($e) ? $e->getMessage() : NULL, ($e) ? $e->getCode() : NULL, ($e) ? $e : NULL); |
|
| 139 | - if (!isset($parse['relative'])) |
|
| 140 | - throw new DateInterval\InvalidArgumentException(sprintf("First argument '%s' is not in supported relative date format.", $interval), ($e) ? $e->getCode() : NULL, ($e) ? $e : NULL); |
|
| 143 | + if ($parse['error_count']) { |
|
| 144 | + throw new DateInterval\InvalidArgumentException(($e) ? $e->getMessage() : NULL, ($e) ? $e->getCode() : NULL, ($e) ? $e : NULL); |
|
| 145 | + } |
|
| 146 | + if (!isset($parse['relative'])) { |
|
| 147 | + throw new DateInterval\InvalidArgumentException(sprintf("First argument '%s' is not in supported relative date format.", $interval), ($e) ? $e->getCode() : NULL, ($e) ? $e : NULL); |
|
| 148 | + } |
|
| 141 | 149 | } |
| 142 | 150 | } |