@@ -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 { |
@@ -57,8 +61,9 @@ discard block |
||
| 57 | 61 | $d1->add(new self($interval)); |
| 58 | 62 | $int = ($this->getRefDT())->diff($d1); |
| 59 | 63 | $this->__construct(self::parse($int)); |
| 60 | - if ($d1 < $this->getRefDT()) |
|
| 61 | - $this->invert = 1; |
|
| 64 | + if ($d1 < $this->getRefDT()) { |
|
| 65 | + $this->invert = 1; |
|
| 66 | + } |
|
| 62 | 67 | return $this; |
| 63 | 68 | } |
| 64 | 69 | |
@@ -69,8 +74,9 @@ discard block |
||
| 69 | 74 | $d1->sub(new self($interval)); |
| 70 | 75 | $int = ($this->getRefDT())->diff($d1); |
| 71 | 76 | $this->__construct(self::parse($int)); |
| 72 | - if ($d1 < $this->getRefDT()) |
|
| 73 | - $this->invert = 1; |
|
| 77 | + if ($d1 < $this->getRefDT()) { |
|
| 78 | + $this->invert = 1; |
|
| 79 | + } |
|
| 74 | 80 | return $this; |
| 75 | 81 | } |
| 76 | 82 | |
@@ -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 | } |