| Conditions | 4 |
| Paths | 3 |
| Total Lines | 12 |
| Code Lines | 6 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 5 |
| CRAP Score | 4.074 |
| Changes | 0 | ||
| 1 | <?php |
||
| 44 | 9 | public static function fromString($string) |
|
| 45 | { |
||
| 46 | 9 | if (preg_match('/^((\d+) +)?(\w+)$/', trim($string), $ms)) { |
|
| 47 | 9 | if (isset(static::$periods[$ms[3]])) { |
|
| 48 | 9 | $class = static::$periods[$ms[3]]; |
|
| 49 | |||
| 50 | 9 | return new $class($ms[1] ?: 1); |
|
| 51 | } |
||
| 52 | } |
||
| 53 | |||
| 54 | throw new \Exception("invalid period given: $string"); |
||
| 55 | } |
||
| 56 | |||
| 66 |