| Conditions | 6 |
| Paths | 6 |
| Total Lines | 25 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 0 | ||
| 1 | <?php |
||
| 21 | public static function createDateInterval($value) |
||
| 22 | { |
||
| 23 | if ($value instanceOf \DateInterval) { |
||
| 24 | return $value; |
||
| 25 | } |
||
| 26 | |||
| 27 | if (is_numeric($value)) { |
||
| 28 | $delay = new \DateInterval(sprintf("PT%dS", abs((int) $value))); |
||
| 29 | $delay->invert = ($value < 0) ? 1 : 0; |
||
| 30 | |||
| 31 | return $delay; |
||
| 32 | } |
||
| 33 | |||
| 34 | if (is_string($value)) { |
||
| 35 | try { |
||
| 36 | // first try ISO 8601 duration specification |
||
| 37 | $delay = new \DateInterval($value); |
||
| 38 | } catch (\Exception $e) { |
||
| 39 | // then try normal date parser |
||
| 40 | $delay = \DateInterval::createFromDateString($value); |
||
| 41 | } |
||
| 42 | return $delay; |
||
| 43 | } |
||
| 44 | |||
| 45 | return new \DateInterval('PT0S'); |
||
| 46 | } |
||
| 68 |