| Conditions | 4 |
| Paths | 5 |
| Total Lines | 16 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 7 |
| CRAP Score | 4.1755 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 34 | 13 | public function sanitizeDateTime(PreDeserializeEvent $event) |
|
| 35 | { |
||
| 36 | 13 | if ($event->getType()['name'] !== 'DateTime' || empty($event->getData())) { |
|
| 37 | 11 | return; |
|
| 38 | } |
||
| 39 | |||
| 40 | try { |
||
| 41 | 13 | $dateTime = new \DateTime($event->getData()[0]); |
|
| 42 | |||
| 43 | 13 | $element = simplexml_load_string( |
|
| 44 | 13 | sprintf('<x attr="%s"/>', $dateTime->format($event->getType()['params'][0])) |
|
| 45 | ); |
||
| 46 | |||
| 47 | 13 | $event->setData($element->attributes()['attr']); |
|
| 48 | } catch (\Exception $exception) { |
||
| 49 | throw new RuntimeException(sprintf('"%s" is not a datetime', $event->getData()[0])); |
||
| 50 | } |
||
| 52 | } |