| Conditions | 8 |
| Paths | 6 |
| Total Lines | 23 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 27 | public function normalize(string $input): string |
||
| 28 | { |
||
| 29 | if (preg_match('/^\d{4}[\-][0]{2}[\-][0]{2}$/', $input) || preg_match('/^\d{4}[\-]\d{2}[\-][0]{2}$/', $input)) { |
||
| 30 | return $input; |
||
| 31 | } |
||
| 32 | |||
| 33 | if (preg_match('/^\d{4}[\-|\/]\d{2}[\-|\/]\d{2}$/', $input) || preg_match('/^\d{1,2}\.? [a-zA-Z]{3} \d{4}$/', $input)) { |
||
| 34 | return (new \DateTime($input))->format('Y-m-d'); |
||
| 35 | } |
||
| 36 | |||
| 37 | if (preg_match('/^\d{4}[\-|\/|\.]\d{2}[\-|\/|\.]\d{2}$/', $input)) { |
||
| 38 | return str_replace('.', '-', $input); |
||
| 39 | } |
||
| 40 | |||
| 41 | if (preg_match('/^[a-zA-Z]{3} \d{4}$/', $input)) { |
||
| 42 | return (new \DateTime($input))->format('Y-m') . '-00'; |
||
| 43 | } |
||
| 44 | |||
| 45 | if (preg_match('/^\d{4}$/', $input)) { |
||
| 46 | return $input . '-00-00'; |
||
| 47 | } |
||
| 48 | |||
| 49 | throw new UnrecognizedDateFormat($input); |
||
| 50 | } |
||
| 52 |