Conditions | 5 |
Paths | 7 |
Total Lines | 20 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 12 |
CRAP Score | 5 |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
1 | <?php |
||
33 | 10 | public function parseString(string $string) |
|
34 | { |
||
35 | 10 | $now = time(); |
|
36 | |||
37 | 10 | if (empty($string)) { |
|
38 | 1 | return 0; |
|
39 | 9 | } elseif (is_numeric($string)) { |
|
40 | 3 | $timestamp = $now + (int)$string; |
|
41 | 6 | } elseif (preg_match('/^(\d+)\s*(\w)$/', trim($string), $matches)) { |
|
42 | 5 | $timestamp = $this->withModifier($matches, $now); |
|
43 | } else { |
||
44 | 1 | $timestamp = strtotime($string); |
|
45 | } |
||
46 | |||
47 | 8 | if ($timestamp < $now) { |
|
48 | 1 | throw new UserException(sprintf('Time %s is invalid', $string)); |
|
49 | } |
||
50 | |||
51 | 7 | return $timestamp; |
|
52 | } |
||
53 | |||
70 |