| Conditions | 4 |
| Paths | 1 |
| Total Lines | 18 |
| Code Lines | 8 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | 336 | public function __construct(string $name) |
|
| 13 | { |
||
| 14 | 336 | parent::__construct($name, function ($input) use ($name): string { |
|
| 15 | // empty string |
||
| 16 | 182 | if ('' === $input) { |
|
| 17 | 179 | return ''; |
|
| 18 | } |
||
| 19 | |||
| 20 | // input formats |
||
| 21 | 18 | foreach (['Y-m-d', 'd/m/Y'] as $format) { |
|
| 22 | 18 | $date = DateTime::createFromFormat($format, $input); |
|
| 23 | 18 | if ($date instanceof DateTime) { |
|
| 24 | 17 | return $date->format('Y-m-d'); |
|
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | // don't know how to handle |
||
| 29 | 1 | throw new RuntimeException("Para el campo $name la fecha $input no pudo ser interpretada"); |
|
| 30 | 336 | }); |
|
| 33 |